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
I want to run a VAR with bootstrap standard errorsI want to run a VAR(1) with both OLS standard errors and bootstrap standard errors which are compute…
Duplicates list full pieces of observationsHi Statalisters, Just have a simple question. If my dataset contains variable v1, v2, and v3, I use…
[HELP] Destring Variables DilemaHello Statalist -- Hope everyone is doing well. I am currently cleaning a dataset and am stumbling …
How to produce a table that shows the estimates of beta_cf and beta_dr for the 25 size BEME-sorted portfoliosHi Mr. Clyde Schechter and all STATALIST expert, I have an issue which i really appreciate the h…
Obtaining marginal effects for all possible predictsHi everyone, I was wondering to know how can I combine the below four margins commands in a single o…
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