Programmatically Create Category and sub Category

If your question if like this:

Category A
– sub-category 1
– sub-category 2
– sub-category 3

Then you would create the following in your theme’s functions.php:

//create the main category
wp_insert_term(

// the name of the category
'Category A', 

// the taxonomy, which in this case if category (don't change)
'category', 

array(

// what to use in the url for term archive
'slug' => 'category-a',  
));

Then for each sub-category:

wp_insert_term(

// the name of the sub-category
'Sub-category 1', 

// the taxonomy 'category' (don't change)
'category',

array(
// what to use in the url for term archive
'slug' => 'sub-cat-1', 

// link with main category. In the case, become a child of the "Category A" parent  
'parent'=> term_exists( 'Category A', 'category' )['term_id']

));

Hope this helps.