Dear Statalist,
I am struggling to make the code below shorter: I would like to use a loop to include local macros below within the if condition.
Furthermore, I would like to include these macros in both the file name when saving regression results and the title of the table showing the regression outcomes.
Specifically, I aim to run regressions on subsets defined by combining the local macro `abovems' with the local macros `onlys', `onlym', and `onlyeng', respectively. Similarly, I will run the same regressions on subsets defined by combining the local macro `belowms' with the three specified local macros.
How can I automate all these tasks?
Thank you for your help!
Chwen Chwen
Code
local abovems "above_medsize==1" // above median size
local belowms "above_medsize==0" // below median size
local onlys "onlys==1"
local onlym "onlym==1"
local onlye "onlyeng==1"
est clear
local m=1
foreach var in dep1 dep2 dep3 dep4 dep5 dep6 dep7 {
foreach x in ind1 ind2 ind3 {
eststo model_`m': regr `var' `x' `ctrlist' if (`onlys' & `belowms'), robust
local m `++m'
}
esttab model_* using "$path\Mdata-`belowms'-`var'-`onlys'.txt", ///
replace noconstant se ar2 star(* .10 ** .05 *** .01) b(%10.3f) ///
title("Regr analysis `var' and `onlys' education `belowms'")
est clear
}
I am struggling to make the code below shorter: I would like to use a loop to include local macros below within the if condition.
Furthermore, I would like to include these macros in both the file name when saving regression results and the title of the table showing the regression outcomes.
Specifically, I aim to run regressions on subsets defined by combining the local macro `abovems' with the local macros `onlys', `onlym', and `onlyeng', respectively. Similarly, I will run the same regressions on subsets defined by combining the local macro `belowms' with the three specified local macros.
How can I automate all these tasks?
Thank you for your help!
Chwen Chwen
Code
local abovems "above_medsize==1" // above median size
local belowms "above_medsize==0" // below median size
local onlys "onlys==1"
local onlym "onlym==1"
local onlye "onlyeng==1"
est clear
local m=1
foreach var in dep1 dep2 dep3 dep4 dep5 dep6 dep7 {
foreach x in ind1 ind2 ind3 {
eststo model_`m': regr `var' `x' `ctrlist' if (`onlys' & `belowms'), robust
local m `++m'
}
esttab model_* using "$path\Mdata-`belowms'-`var'-`onlys'.txt", ///
replace noconstant se ar2 star(* .10 ** .05 *** .01) b(%10.3f) ///
title("Regr analysis `var' and `onlys' education `belowms'")
est clear
}
Comment