Hi
In my simulation I am trying to compare output from OLS and 2SLS. I have the following code which saves beta for each in a matrix but I also want to save the standard errors for both OLS and 2SLS. Could you please advise how se's can be added.
set seed 10101
capture program drop mcsimb
program mcsimb, eclass
clear
** change this for Nobs
set obs 500
* z1 & z2 are normally distributed
gen z1=rnormal()
gen z2=rnormal()
* create u and v based on the given correlation, and assume that otherwise the variance is 1
matrix corruv=[1,.8\.8,1]
drawnorm u v , corr(corruv)
* generate X
gen x=1+5*z1+10*z2+v
* generate y
gen y=1+x+u
* estimate models
reg y x
matrix b= _b[x]
ivregress 2sls y (x=z1 z2)
matrix b=b,_b[x]
matrix colname b= ols iv
ereturn post b
end
simulate, reps(1000): mcsimb
summarize
Thank you
Kate
Related Posts with Monte Carlo simulation comparing output for OLS and 2SLS by saving beta and se's in matrix
calculating Growth rates with a gap of 3 years in a panel dataDear statlist, I am working on a panel data set and need to calculate growth rates of each panel ID…
Out-of-sample forecastingHello, I'm trying to forecast an arima(1,0,1) model with 4 variables out of sample. The dataset run…
Using indented foreach and forvaluesDear all, I am trying for the first time to use foreach and forvalues, but with little success. The …
Comparing rates in stataHello, I am new to STATA and am using Version 15. Due to the confidential nature of my data I canno…
Graphical analysis of ratesHello, I am new to STATA and am using Version 15. Due to the confidential nature of my data I canno…
Subscribe to:
Post Comments (Atom)
0 Response to Monte Carlo simulation comparing output for OLS and 2SLS by saving beta and se's in matrix
Post a Comment