*cap log cl *log using "C:\Users\royj\Dropbox\eco5720\emlr3.log", replace ************************************************ *** Example: SLR Simulation - 500 reps; n=10 *** ************************************************ clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx=. * Simulating data and storing regression estimates of beta hat * forval i=1/500 { preserve clear set obs 10 g x = rnormal() g u = rnormal() g y = 1 + x + u reg y x local xcoef =_b[x] restore replace data_bx=`xcoef' in `i' } * Summary and histogram of beta hat values * su data_bx hist data_bx ************************************************** *** Example: SLR Simulation - 500 reps; n=1000 *** ************************************************** clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx=. * Simulating data and storing regression estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 g x = rnormal() g u = rnormal() g y = 1 + x + u reg y x local xcoef =_b[x] restore replace data_bx=`xcoef' in `i' } * Summary and histogram of beta hat values * su data_bx hist data_bx ********************************************************************************* *** Example: SLR Simulation - 500 reps; n=10 ; SSR/n biased for sigma-squared *** ********************************************************************************* clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_sig=. * Simulating data and storing regression estimates of SSR/n * forval i=1/500 { preserve clear set obs 10 g x = rnormal() g u = rnormal() g y = 1 + x + u reg y x predict uhat, resid su uhat, d loc mvar = `r(Var)'*(`r(N)'-1)/`r(N)' restore replace data_sig=`mvar' in `i' } * Summary and histogram of SSR/n values * su data_sig hist data_sig *************************************************************************************** *** Example: SLR Simulation - 500 reps; n=1000 ; SSR/n consistent for sigma-squared *** *************************************************************************************** clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_sig=. * Simulating data and storing regression estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 g x = rnormal() g u = rnormal() g y = 1 + x + u reg y x predict uhat, resid su uhat, d loc mvar = `r(Var)'*(`r(N)'-1)/`r(N)' restore replace data_sig=`mvar' in `i' } * Summary and histogram of SSR/n values * su data_sig hist data_sig ************************************************ *** Example: MLR Simulation - 500 reps; n=10 *** ************************************************ clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx=. * Simulating data and storing regression estimates of beta hat * forval i=1/500 { preserve clear set obs 10 g x = rchi2(1) g u = rchi2(1) - 1 g y = 1 + x + u reg y x local xcoef =_b[x] restore replace data_bx=`xcoef' in `i' } * Summary and histogram of beta hat values * su data_bx hist data_bx ************************************************** *** Example: MLR Simulation - 500 reps; n=1000 *** ************************************************** clear * Generating a variable with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx=. * Simulating data and storing regression estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 g x = rchi2(1) g u = rchi2(1) - 1 g y = 1 + x + u reg y x local xcoef =_b[x] restore replace data_bx=`xcoef' in `i' } * Summary and histogram of beta hat values * su data_bx hist data_bx *log cl