*log using "C:\Users\royj\Dropbox\eco5720\f24\emlr1f24.log", replace *************************************************************************************************************** *** Example: MLR Simulation - 500 reps; n=1000; corr(x1,u) = 0; corr(x2,u) = 0; corr (x1,x2) = 0.4; no bias *** *************************************************************************************************************** clear * Generating 2 variables with missing values to store estimated values of beta hat from the simulation * set obs 500 /* This is the number of repetitions in the simulation */ g data_bx1=. /* This is where the result for beta1 from each repetition will be stored */ g data_bx2=. /* This is where the result for beta2 from each repetition will be stored */ * Simulating data based on correlation values and storing estimates of beta hat * forval i=1/500 { /* This is again the number of repetitions */ preserve /* The preserve and restore loop helps us load new data in each repetition */ clear set obs 1000 /* This is the sample size */ matrix C = (1, .4, 0 \ .4, 1, 0 \ 0, 0, 1) /* This where the correlation of x1, x2, and u with x1, x2, and u is specified */ drawnorm x1 x2 u, corr(C) g y = 1 + 2*x1 + x2 + u reg y x1 x2 local x1coef =_b[x1] /* Saving the value of beta1 from each repetition */ local x2coef =_b[x2] /* Saving the value of beta2 from each repetition */ restore replace data_bx1=`x1coef' in `i' /* Storing the value of beta1 from each repetition */ replace data_bx2=`x2coef' in `i' /* Storing the value of beta2 from each repetition */ } * Summary and histogram of beta hat values * su data_bx1 data_bx2 hist data_bx1 /* Histogram of beta1 values */ hist data_bx2 /* Histogram of beta2 values */ ***************************************************************************************************************** *** Example: MLR Simulation - 500 reps; n=1000; corr(x1,u) = -0.6; corr(x2,u) = 0.2; corr (x1,x2) = 0.4; bias *** ***************************************************************************************************************** clear * Generating 2 variables with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx1=. g data_bx2=. * Simulating data based on correlation values and storing estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 matrix C = (1, .4, -.6 \ .4, 1, 0.2 \ -.6, 0.2, 1) drawnorm x1 x2 u, corr(C) g y = 1 + 2*x1 + x2 + u reg y x1 x2 local x1coef =_b[x1] local x2coef =_b[x2] restore replace data_bx1=`x1coef' in `i' replace data_bx2=`x2coef' in `i' } * Summary and histogram of beta hat values * su data_bx1 data_bx2 hist data_bx1 hist data_bx2 ***************************************************************************************************************** *** Example: MLR Simulation - 500 reps; n=1000; corr(x1,u) = 0; corr(x2,u) = 0.6; corr (x1,x2) = 0.4; bias *** ***************************************************************************************************************** clear * Generating 2 variables with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx1=. g data_bx2=. * Simulating data based on correlation values and storing estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 matrix C = (1, .4, 0 \ .4, 1, 0.6 \ 0, 0.6, 1) drawnorm x1 x2 u, corr(C) g y = 1 + 2*x1 + x2 + u reg y x1 x2 local x1coef =_b[x1] local x2coef =_b[x2] restore replace data_bx1=`x1coef' in `i' replace data_bx2=`x2coef' in `i' } * Summary and histogram of beta hat values * su data_bx1 data_bx2 hist data_bx1 hist data_bx2 *********************************************************************************************************************************** *** Example: MLR Simulation - 500 reps; n=1000; corr(x1,u) = 0; corr(x2,u) = 0; corr (x1,x2) = 0.99; no bias; multicollinearity *** *********************************************************************************************************************************** clear * Generating 2 variables with missing values to store estimated values of beta hat from the simulation * set obs 500 g data_bx1=. g data_bx2=. * Simulating data based on correlation values and storing estimates of beta hat * forval i=1/500 { preserve clear set obs 1000 matrix C = (1, .99, 0 \ .99, 1, 0 \ 0, 0, 1) drawnorm x1 x2 u, corr(C) g y = 1 + 2*x1 + x2 + u reg y x1 x2 local x1coef =_b[x1] local x2coef =_b[x2] restore replace data_bx1=`x1coef' in `i' replace data_bx2=`x2coef' in `i' } * Summary and histogram of beta hat values * su data_bx1 data_bx2 hist data_bx1 hist data_bx2 ********************** *** Example: WAGE2 *** ********************** clear *use "C:\Users\royj\Dropbox\eco5720\Data Sets- STATA\WAGE2.DTA" * Multiple Regression * reg lwage educ IQ * Simple Regression * reg lwage educ * Correlation between IQ and educ * corr IQ educ *log cl