* * Dougherty, Introduction to Econometrics, 4th ed * Example from Section 7.3 * Monte Carlo simulation of difference between OLS and weighted least squares * set x 1 50 = t+4 * * We cut the number of draws to 100000 as 10 million takes quite a bit of time. * compute ndraws=100000 set betaols 1 ndraws = 0.0 set betawls 1 ndraws = 0.0 set seols 1 ndraws = 0.0 set sewls 1 ndraws = 0.0 set serob 1 ndraws = 0.0 * infobox(action=define,lower=1,upper=ndraws,progress) "Simulation" do draw=1,ndraws set y 1 50 = 10+2*x+x*%ran(1.0) linreg(noprint) y # constant x compute betaols(draw)=%beta(2) compute seols(draw)=%stderrs(2) linreg(noprint,spread=x^2) y # constant x compute betawls(draw)=%beta(2) compute sewls(draw)=%stderrs(2) linreg(noprint,robust) y # constant x compute serob(draw)=%stderrs(2) infobox(current=draw) end do draw infobox(action=remove) * density(grid=automatic,maxgrid=200,smoothing=1.5) betaols / xbeta fols density(grid=input,smoothing=1.5) betawls / xbeta fwls * scatter(footer="7.9 Distribution of the estimators of OLS and WLS",\$ klabels=||"OLS","WLS"||,key=upleft,style=lines) 2 # xbeta fols # xbeta fwls * density(grid=automatic,maxgrid=200,smoothing=1.5) serob / xse fserob density(grid=input,smoothing=1.5) seols / xse fseols density(grid=input,smoothing=1.5) sewls / xse fsewls * scatter(footer="7.10 Distribution of the standard errors of estimators",\$ klabels=||"OLS","WLS","Robust OLS"||,key=upright,style=lines) 3 # xse fseols # xse fsewls # xse fserob