* * Monte Carlo Exercise from pages 81-84 * all 32 * * Regression parameters. The "sigma" here are the standard deviations, not * variances, as it's more convenient to use s.d's when drawing random numbers. * compute b1=1,b2=.5,sigma=1 * * x process parameters * compute c=2,phi=.6,sigeta=1 * * First, with a single draw for x. This is done here using SET. The FIRST option * is used to do the initial data point (which has its own formula), while the * main function handles 2 to the end. * set(first=c/(1-phi)+%ran(sigeta/sqrt(1-phi**2))) x = c+phi*x{1}+%ran(sigeta) * compute ndraws=10000 compute count=0.0 do draw=1,ndraws * * Do a draw for y given x * set y = b1+b2*x+%ran(sigma) * * Do the regression. Make sure you include noprint, or you'll get a * lot of output. * linreg(noprint) y # constant x * * Compute the tstat for the b2 coefficient. This uses the %beta * and %stderrs vectors. %beta(x) is the coefficient on the "x"th * explanatory variable, and %stderrs(x) is its standard error. compute tstat=(%beta(2)-.5)/%stderrs(2) * * To determine significance, you can either compare the absolute * value of the tstat to the critical value, or equivalently, * compare the p-value to .05. We do the latter here. * compute signif=%ttest(tstat,%ndf) * * This adds one to count if signif is <= .05. * compute count=count+(signif<=.05) end do draw * disp "Monte-Carlo estimate of significance, conditional on x" count/ndraws * * Same thing with new x each time through * compute ndraws=10000 compute count=0.0 do draw=1,ndraws * * Do a draw for y given x * set(first=c/(1-phi)+%ran(sigeta/sqrt(1-phi**2))) x = c+phi*x{1}+%ran(sigeta) set y = b1+b2*x+%ran(sigma) * * Do the regression. Make sure you include noprint, or you'll get a * lot of output. * linreg(noprint) y # constant x * * Compute the tstat for the b2 coefficient. This uses the %beta * and %stderrs vectors. %beta(x) is the coefficient on the "x"th * explanatory variable, and %stderrs(x) is its standard error. compute tstat=(%beta(2)-.5)/%stderrs(2) * * To determine significance, you can either compare the absolute * value of the tstat to the critical value, or equivalently, * compare the p-value to .05. We do the latter here. * compute signif=%ttest(tstat,%ndf) * * This adds one to count if signif is <= .05. * compute count=count+(signif<=.05) end do draw * disp "Monte-Carlo estimate of significance, unconditional" count/ndraws