* Simulates univariate OLS regression ; #delimit ; * set end of line marker to a semicolor; capture program drop ols1 ; * if ols1 exists, drop it ; program define ols1, rclass ; * create a new command called ols1 ; drop _all ; * clear memory ; set obs 100 ; * set observations to n=100 ; gen x = uniform() ; * draw the regressor from U[0,1] ; gen u = invnorm(uniform()) ; * draw the error from N(0,1) ; gen y = 1 + `1'*x + u ; * the DGP ; reg y x ; * regress y on x ; test x ; return scalar b1 = _b[x]; * store est. slope in variable "b1" ; return scalar b0 = _b[_cons];* store constant in "b0" ; return scalar seb1= _se[x] ; * store std. err. of slope in "seb1" ; return scalar p = r(p) ; * return model R2 in "r2" ; end ; matrix B = J(41,3,0) ; local i=1; forvalues b=-2(0.1)2 { ; simulate b1=r(b1) p=r(p), reps(1000) : ols1 `b' ; matrix B[`i',1] = `b' ; count if p<0.05 ; matrix B[`i',2] = r(N) ; count if p<0.01 ; matrix B[`i',3] = r(N) ; local i=`i'+1; } ; drop _all ; svmat B ; rename B1 truebeta ; label var truebeta "Value of beta in DGP" ; rename B2 power05 ; la var power05 "Power curve, size=0.05"; rename B3 power01 ; la var power01 "Power curve, size=0.01" ; twoway line power05 power01 truebeta , ti("Power curves") ;