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
OLS model that includes related covariates that add up to 100%Hi group, I'm running an OLS model where the dependent variable is patients' average value of HgA1c,…
Hedge fund data set for statahow can I create a distinct variable and using that variable to entire data set, example Fund 1--200…
Panel Fixed Effect, Clustering Standard Error (Panels are not nested within clusters)Hi there, First off, thank you for taking your time to read through my question. I have a panel dat…
loop over the panel IDs to use quantile regressions xtqregHi, I am running quantile regression for panel of 260 firms for period of 15 years. The general reg…
Ideas on how to convert a hyphenated interval (e.g. '5-8') into its constituent integers delimited by commas (e.g. '5,6,7,8')?Hi, As my post title states, I have data with varied hyphenated intervals such as '3-6', '1-5', '10-…
Subscribe to:
Post Comments (Atom)
0 Response to How to do many similar loops
Post a Comment