Hi Statalist,
I'd like to write a -foreach- loop that runs a number of regressions (let's say I want to run `z' number of regressions), then creates a new *.rtf file (replacing any previous *.rtf output) which has all `z' regression results in the same file. I'm thinking I need to -replace- on the first iteration, and then -append- on all subsequent iterations.
Here's the code format I'm working with, can anybody help where it says XXXreplace/appendXXX?
Would you use the code below? Do I need to use -esttab- twice? The reason I ask is that my -esttab- is a sprawling multi-line command with many options, and I'd rather not have all of those replicated in the code twice. And for the second -esttab- command, is there an easy way to get Stata to -esttab- all models (m1 m2 m3 m4 ... mz) except m1, when I don't always know what the value of `z' is?
Thank you.
I'd like to write a -foreach- loop that runs a number of regressions (let's say I want to run `z' number of regressions), then creates a new *.rtf file (replacing any previous *.rtf output) which has all `z' regression results in the same file. I'm thinking I need to -replace- on the first iteration, and then -append- on all subsequent iterations.
Here's the code format I'm working with, can anybody help where it says XXXreplace/appendXXX?
Code:
counter=1
foreach indep_var in ///
"y1" ///
"y2" ///
"y3" ///
... ///
"yz" ///
{
reg `indep_var' x
estimates store m`counter'
local counter=`counter'+1
}
esttab m* using "output.rtf", XXXreplace/appendXXX
Thank you.
Code:
counter=1
foreach indep_var in ///
"y1" ///
"y2" ///
"y3" ///
... ///
"yz" ///
{
reg `indep_var' x
estimates store m`counter'
local counter=`counter'+1
}
esttab m1 using "output.rtf", replace
esttab m2-mz using "output.rtf", append

Comment