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
Hausman-test interpretation for RE vs FEHello, I have a queston on how to interpret a Hausman-test. Dependent variable (y) is suffering fro…
changing working directoryHi everyone, I recently updated to Stata 15. In the main window, I used to be able to change the wo…
Mixed models repeated measuresHi, I'm trying to find the best model for answering a repeated measures problem. The research quest…
Group identifier for individual panels: repeated time values within panelHi all, I'm hoping to be able to get some guidance on a work-around for the repeated time values wi…
oprobit marginal effects - urgent pleaseI used the following estimation command to understand the interaction effect of ownership and knowle…
Subscribe to:
Post Comments (Atom)
0 Response to How to do many similar loops
Post a Comment