creating categories programmatically

wp_insert_category and wp_create_category are both in wp-admin/includes/taxonomy.php. They’re not general use functions and can’t be used just anywhere. wp_insert_term is, but you’re using it incorrectly. See the Codex for details on proper usage, but in short, here’s a cheat sheet:

wp_insert_term( $term, $taxonomy, $args = array() );
...
$defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');

I believe what you want to change your code to say is,

$var = wp_insert_term( $cat_name, 'category', array( 'parent' => $parent_term_id ) );