*log using "C:\Users\royj\Dropbox\eco5720\emlr1.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 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 \ 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: 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" * Summary Statistics * d wage lwage educ IQ su wage lwage educ IQ * Simple Regression * reg lwage educ g bed_tilde = _b[educ] * Multiple Regression * reg lwage educ IQ g bed_hat = _b[educ] g biq_hat = _b[IQ] reg IQ educ g ded_tilde = _b[educ] g betadiff1 = bed_tilde - bed_hat g betadiff2 = biq_hat*ded_tilde su betadiff1 betadiff2 ************************** *** Example: MLR Graph *** ************************** *ssc install reganat, replace sysuse auto.dta, clear regress price length regress price length weight headroom mpg reganat price length weight headroom mpg, dis(length) biline reg length weight headroom mpg predict reslhat, res reg price reslhat *log cl