Hi fellow Statalisters,
I'm writing a code which is supposed to store variables from survey data in a local. Those variables have to fulfill two conditions: 1) some observation has to take on value "-8" and 2) the corresponding value label for this observation has to say - for example - "Stata".
I can handle the -8 restriction but I'm not sure how to code the label restriction properly. I assume it would be best to use a command and a corresponding return code. Has anyone had a similar problem or an idea how to extend my code?
One way to do it might be using decode var, gen(var_dc) and then checking the return code of var_dc == "Stata". But that looks like it's not the easiest way of reaching my goal.
Best,
Christian
I'm writing a code which is supposed to store variables from survey data in a local. Those variables have to fulfill two conditions: 1) some observation has to take on value "-8" and 2) the corresponding value label for this observation has to say - for example - "Stata".
I can handle the -8 restriction but I'm not sure how to code the label restriction properly. I assume it would be best to use a command and a corresponding return code. Has anyone had a similar problem or an idea how to extend my code?
Code:
local filtered_nondc foreach var of varlist _all { cap count if `var' == -8 // cap needed to avoid break for string variables if `r(N)' > 0 local filtered_nondc "`filtered_nondc' `var'" }
Best,
Christian
Comment