Create product category programmatically in magento

    $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();

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