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
No chi2 statistics calculated for mlogtest, combine commandHi there I am trying to run 'mologtest, combine' after running the mlogit regression: svy: mlogit …
Why my boxplot in Stata isn't showing whiskers?Good day! Please let me know how I can make the whiskers appear for my boxplot. I am just following …
How to drop random years from panel data?I have a panel data set, consisting of 125 countries, 36 years. I want to run an IV regression multi…
Does it make sense to use decadal dummies for quinquennial data?Dear Statalists, I have a question of if it is reasonable to use decadal dummies as time fixed effe…
obtain coefficient from interaction dummiesDear all , I ran this regression: reg lnmwage totalpers addshift edulength urate vrate i.hlofeduc#…
Subscribe to:
Post Comments (Atom)
0 Response to "Varlist required" error message in loop using local macro
Post a Comment