Hi all,
I am trying to write a program for my own analysis to save time because I have to repeat similar analyses numerous times. Since I am pretty new to Stata programming, I have tried a simple one as the followings:
That program works, but I now want to make it a bit more complicated. Suppose that I run two first stage, obtain first stage predicted values and then plug these predicted values into the second stage. Let y the outcome, z1 and z2 are instrumental variables, y1 and y2 are endogenous variables and x1 and x2 are exogenous variables. I want to write a program for the following regressions and store their associated estimates.
Any help is much appreciated. Thank you.
I am trying to write a program for my own analysis to save time because I have to repeat similar analyses numerous times. Since I am pretty new to Stata programming, I have tried a simple one as the followings:
Code:
cap program drop example program example args y x1 x2 x3 di "`y' `x1' `x2' `x3'" qui reg `y' `x1' `x2' `x3', vce(robust) sum `y' if e(sample) sca m_y = r(mean) sca b = _b[`x1'] sca se = _se[`x1'] sca di m_y b se end sysuse auto, clear example price headroom mpg rep78
Code:
reg y1 z1 x1, robust predict yhat1 reg y2 z2 x2, robust predict yhat2 reg y yhat1 yhat2 x1 x2, robust sum y if e(sample) sca m_y = r(mean) sca b = _b[yhat1] sca se = _se[yhat2]
Comment