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