Create Category through code in Magento1

To create the category firstly create the category Model object through below code.
[php]
$category = Mage::getModel(‘catalog/category’);
[/php]
after that define the category name, Url key, etc.

[php]
$parentId = ‘2’;
$category = Mage::getModel(‘catalog/category’);
$category->setName(‘category_name’);
$category->setUrlKey(‘category_key’);
$category->setIsActive(1);
$category->setDisplayMode(‘PRODUCTS’);
$category->setIsAnchor(1); //for active anchor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel(‘catalog/category’)->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
[/php]

Note:- parentId is a category id, where we create a child category of this category.