Hi, Stata experts,
I have need to repeat the same foreach loop for different variables but with the same logic (see example below). I'm wondering if I can simplify.
Thank you in advance!
Sam
local varlist var_1 var_2 var_3 var_4 var_5
generate ANY_mcvar1 = 0
foreach var of local varlist{
replace ANY_mcvar1 = 1 if `var' == 1
}
local varlist2 var_6 var_8 var_9 var_10
generate ANY_mcvar2 = 0
foreach var of local varlist2{
replace ANY_mcvar2= 1 if `var' == 1
}
local varlist3 var_11 var_13 var_19 var_20
generate ANY_mcvar3 = 0
foreach var of local varlist3{
replace ANY_mcvar3= 1 if `var' == 1
}
Related Posts with How to do many similar loops
Two way or one way fixed effect ??Hi, test to choose between model two way fixed effec or fixed effect ordinary ? i use STATA 14 …
Dropping observations within a variable if they are not numericHow do I drop observations within a variable if they are not numeric? …
How to reshape the panel data rows to columnsDear Clyde Schechter and other Stata experts, I have the raw data as follows: Code: input str10 A…
Working with multiple if conditionsDear Statalist, I am browsing a dataset with multiple if conditions. Is it possible to identify the…
Creating categories within a nominal variableHello! I am conducting an honors thesis in sociology and need help with creating categories within …
Subscribe to:
Post Comments (Atom)
0 Response to How to do many similar loops
Post a Comment