Hi
I'm trying to use a loop to generate a set of new variables representing the format of an existing variable list - if the value in the existing variable starts with a number, the corresponding new variable should have a value of 0, and if it starts with a letter, the new variable should have a value of 1.
To do so I've created a local macro with my variables of interest:
local tidycodvar "tidycod tidycod0 tidycod1 tidycod2"
When I ask it to display tidycodvar, it brings up this list correctly.
Then when I run the following loop, I get an error message saying "varlist required". (Note that I've already defined the labels for codf earlier in the do file).
foreach varname of varlist `tidycodvar' {
gen f`varname' = .
replace f`varname' = 0 if regexm(`varname', "^[0-9]")
replace f`varname' = 1 if regexm(`varname', "^[A-Z]")
label values f`varname' codf
label variable f`varname' "Format of COD code"
}
I would be very grateful for any suggestions as to where I'm going wrong.
Many thanks
Related Posts with "Varlist required" error message in loop using local macro
Unequal interval systematic samplingI can easily do systematic sampling from the equal interval sample like 1,2,3,4,5,6,7,8,9,........ B…
Penalized spline models with -mixed-Greetings, all. I recently ran across a StataCorp presentation by Roberto Gutierrez that discussed …
How to calculate percentage of certain categories using bysort command?I have a dataset at the individual level which includes a variable on education. The variable takes …
delete observations according to some rulesDear statalist, I have two sets of data and I append them together. The first set consists of a ser…
Loop over variablesinput double(month202001 month202002 month202003 month202004 month202005 month202101 month202102 mon…
Subscribe to:
Post Comments (Atom)
0 Response to "Varlist required" error message in loop using local macro
Post a Comment