In this example, I have four variables. I want to run some regressions on them and display the regression on the first two variables together, as well as those on the third and fourth variable.
In the above, I use w as a placeholder. That part is commented out using /**/ because it would not work.
What I want is to use a loop to simplify something of the following structure:
So what I want to do running through the above foreach loop only twice, and cover two of the four variables each time.
In other software, I would define an array consisting of mpg rep78 headroom weight, and taking two elements with each iteration of a loop that has only two iterations. But how can I do that, or something else with the same result, in Stata?
Code:
clear sysuse auto.dta scalar i = 1 di i foreach v in mpg rep78 headroom weight { eststo: quietly: reg `v' price trunk length eststo: quietly: reg `v' price trunk length, vce(robust) /* eststo: quietly: reg `w' price trunk length eststo: quietly: reg `w' price trunk length, vce(robust) */ esttab * using esttab-`=scalar(i)'.tex, scalar i = i+1 }
What I want is to use a loop to simplify something of the following structure:
Code:
eststo: quietly: reg mpg price trunk length eststo: quietly: reg mpg price trunk length, vce(robust) eststo: quietly: reg rep78 price trunk length eststo: quietly: reg rep78 price trunk length, vce(robust) esttab * using esttab-1.tex eststo: quietly: reg headroom price trunk length eststo: quietly: reg headroom price trunk length, vce(robust) eststo: quietly: reg weight price trunk length eststo: quietly: reg weight price trunk length, vce(robust) esttab * using esttab-2.tex
So what I want to do running through the above foreach loop only twice, and cover two of the four variables each time.
In other software, I would define an array consisting of mpg rep78 headroom weight, and taking two elements with each iteration of a loop that has only two iterations. But how can I do that, or something else with the same result, in Stata?
Comment