* * Dougherty, Introduction to Econometrics, 4th ed * Example from Section 8.5 * Instrumental variables * Monte Carlo experiment * * This is set to do 100,000 draws since 10,000,000 takes quite a while. * compute ndraws=100000 * compute lambda1=2.0,lambda2=0.5,beta1=10.0,beta2=5.0 * set b2iv_25 1 ndraws = 0.0 set b2ols_25 1 ndraws = 0.0 set b2iv_100 1 ndraws = 0.0 set b2ols_100 1 ndraws = 0.0 set b2iv_3200 1 ndraws = 0.0 set b2ols_3200 1 ndraws = 0.0 * clear z v u x y instruments constant z * infobox(action=define,lower=1,upper=ndraws,progress) "Simulations" do i=1,ndraws infobox(current=i) set z 1 3200 = %ran(1.0) set v 1 3200 = %ran(1.0) set u 1 3200 = %ran(1.0) set x 1 3200 = lambda1*z+lambda2*v+u set y 1 3200 = beta1+beta2*x+u * linreg(noprint) y 1 25 # constant x compute b2ols_25(i)=%beta(2) * linreg(inst,noprint) y 1 25 # constant x compute b2iv_25(i)=%beta(2) * linreg(noprint) y 1 100 # constant x compute b2ols_100(i)=%beta(2) * linreg(inst,noprint) y 1 100 # constant x compute b2iv_100(i)=%beta(2) * linreg(noprint) y 1 3200 # constant x compute b2ols_3200(i)=%beta(2) * linreg(inst,noprint) y 1 3200 # constant x compute b2iv_3200(i)=%beta(2) end do i infobox(action=remove) * * Get a fairly fine grid across 4 to 6 to accomodate the sharp features of the * 3200 data point estimates. * @gridseries(from=4.0,to=6.0,n=500) xb density(grid=input,smoothing=1.5) b2ols_25 / xb f2ols_25 density(grid=input,smoothing=1.5) b2iv_25 / xb f2iv_25 density(grid=input,smoothing=1.5) b2ols_100 / xb f2ols_100 density(grid=input,smoothing=1.5) b2iv_100 / xb f2iv_100 density(grid=input,smoothing=1.5) b2ols_3200 / xb f2ols_3200 density(grid=input,smoothing=1.5) b2iv_3200 / xb f2iv_3200 * scatter(style=line,footer="Figure 8.2 Distributions of the OLS and IV estimators for b2 for n=25 and 100",\$ vmin=0.0,key=upleft,klabels=||"OLS, n=25","IV, n=25","OLS, n=100","IV, n=100"||) 4 # xb f2ols_25 # xb f2iv_25 # xb f2ols_100 # xb f2iv_100 * scatter(style=line,footer="Figure 8.3 Distributions of the OLS and IV estimators for b2 for n=3200",\$ vmin=0.0,key=upleft,klabels=||"OLS, n=3200","IV, n=3200"||) 2 # xb f2ols_3200 # xb f2iv_3200