validate_n_levels function

Validate that variables has expected number of levels