Magento 2 : Create customer group programmatically

Here is the way to add customer groups programmatically in Magento 2, use $group->save() on the model returned by the GroupFactory:

namespace A2bizz\MyCustomModule\Setup;
 
use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\GroupFactory;
 
class InstallData implements InstallDataInterface
{
    protected $groupFactory;
 
    /**
     * Customer group factory
     */
    public function __construct(GroupFactory $groupFactory) {
        $this->groupFactory = $groupFactory;
    }
 
    public function install(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $setup->startSetup();
 
        // Create the new group
        /** @var \Magento\Customer\Model\Group $group */
        $group = $this->groupFactory->create();
        $group
            ->setCode('New Customer Group');
            ->setTaxClassId(3) 
            ->save();
 
        $setup->endSetup();
    }
}