I am generating a series of new variables that represent recoded versions of existing variables. At the same time, I am labeling the new variable and labeling the values of the new variables. To make my code more succinct, I am using macros to hold a list of old and new variable names and extended macros to call each name in the list.
When I run the following code, I get the error message "invalid syntax" after the last line of the loop below ("label `var2' ...). Note the name I intended to give the variable displayed in the trace is correct.
Sample code with three variables:
local oldvar food diet meals
local newvar F1 F2 F3
label define F3way 0 "Never true" 1 "Sometimes true" 2 "Often true"
forval i = 1/3 {
local var1 `: word `i' of `oldvar''
local var2 `: word `i' of `newvar''
gen `var2' =0 if `var1' ==3
replace `var2' =1 if `var1' ==2
replace `var2' =2 if `var1' ==1
label values `var2' F3way
label `var2' "Recode `var1'"
}
Could you please help me understand where I've gone wrong? Thank you
in advance for your assistance!
Lois Fisher
Related Posts with Using a loop with local and extended macros to generate new recoded variables, variable labels, and value labels
Reminder: UK Stata Conference submission deadline 26 MayUK Stata Conference, 7-8 September 2023: reminder I'm bumping the thread at https://www.statalist.o…
Stata Command: including interaction terms of the endogenous variable in 2SLS using xtivregHi, I am wondering if anyone had any experience in including an interaction term in 2SLS using xtiv…
inter-religious marriageDear sir I am working with Census data. To make it simple, consider a database as follows: id fa…
number increased or decreased?Dear All, I found this question here (in Chinese). The variable x denotes the product. Code: * Exam…
Query on ordering coefficients from multiple models when using coefplotHi All We need help with using the coefplot command. Briefly, we have run a series logistic regress…
Subscribe to:
Post Comments (Atom)
0 Response to Using a loop with local and extended macros to generate new recoded variables, variable labels, and value labels
Post a Comment