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
Reverse Command Lookup for .gph File?Hi Everyone, I'm new to Stata, so apologies for the newbie question here. I'm wondering if there's …
fillin or expand?Dear All, The question is related to a previous post here. Now, the expanded data is Code: * Exampl…
How can I modify the variable label of a table output?Hi masters, I use table command to create a table, but I'm not satisfied with the table's output. T…
Tracking executive changes in datasetHi, I'm doing a tracking analysis of executive changes. In the dataset, I divide the positions into …
Collapse command error message that has me stumpedI'm using the Collapse command in Stata to aggregate a series of numbers by different categories. Th…
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