I have a variable with 50 categories and would like to create indicators for each category. Then I would like to add the names of each category into a local and keep only those indicators plus some other variables. So I tried this:
create local list of all categotries:
local list of group 1 variables to keep
local list of group 2 variables to keep
local list of all variables to keep
create indicators for each category:
keep variables from local list:
I get the error message ` invalid name. I think the source of the error is levelsof.
create local list of all categotries:
Code:
levelsof cat_var, local(cat_list)
Code:
local indvars = "ind1 ind2"
Code:
local facvars = "fac1 fac2"
Code:
local vars = "`indvars' `facvars' `cat_list'"
Code:
foreach var in `cat_list' { gen `var' = (cat_var == "`var'") }
Code:
keep `vars'
I get the error message ` invalid name. I think the source of the error is levelsof.
Comment