* 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 + 2*x + u ; * the DGP ; reg y x ; * regress y on x ; test x=1 ; 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 ;