** FLS 6183 & FLP 0468 ** Lab 3: Omitted Variable Bias * Data: 13/09/2018 clear * Question 1 * Part a. No correlation between X and Z * We will create a data set with 500 observations. We are establishing that X has a mean of 7 and a standard deviation of 8. * We are estiablishing at Y with mean 100 and standard deviation of 20. We are also establishing that Z has a mean of 20 and a standard deviation of 2. * In addition, we will stipulate that the correlation between X and Z is 0, that the correlation between X and Y = 0.7 and the correlation between Y and Z = 0.3. * x, y and z are randomly drawn from a normal distribution. Please note in the matrix C below the order is (y, x, z) in each colunm and row. matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0 \ 0.3, 0, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) summarize corr y x z regress y x estimates store m1 * Let's save the stats we will need to compare if diff is stat diff to implement Clogg, Petkova and Haritou (1995) scalar b = _b[x] scalar vb = _se[x]^2 scalar ve = e(rmse)^2 regress y x z estimates store m2 esttab m1 m2, se * Let's save the stats we will need to compare if diff is stat diff and calculate t test as proposed by Clogg, Petkova and Haritou (1995) scalar d = scalar(b)-_b[x] scalar se = sqrt(_se[x]^2-scalar(vb)*e(rmse)^2/scalar(ve)) di scalar(d) di scalar(se) di scalar(d)/scalar(se) * suest hausman m1 m2, alleqs * Part b. Correlation between X and Z =0.75 * We will create a data set with 500 observations. We are establishing that X has a mean of 7 and a standard deviation of 8. * We are estiablishing at Y with mean 100 and standard deviation of 20. We are also establishing that Z has a mean of 20 and a standard deviation of 2. * In addition, we will stipulate that the correlation between X and Z is 0.75, that the correlation between X and Y = 0.7 and the correlation between Y and Z = 0.3. * x, y and z are randomly drawn from a normal distribution. clear matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0.75 \ 0.3, 0.75, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) summarize corr y x z regress y x estimates store m3 regress y x z estimates store m4 esttab m2 m4, se esttab m3 m4, se esttab m3 m4, ci coefplot m3 m4, drop(_cons z) xline(0) * Question #2 * Case 1 clear matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0 \ 0.3, 0, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) * Solution proposed by Pedro Castro, Jose Octavio, Vinicius and Sergio * Gerar 10 grupos a partir dos decis de z xtile groups = z, nq(10) gen group1 = 0 replace group1 = 1 if groups == 1 gen group2 = 0 replace group2 = 1 if groups == 2 gen group3 = 0 replace group3 = 1 if groups == 3 gen group4 = 0 replace group4 = 1 if groups == 4 gen group5 = 0 replace group5 = 1 if groups == 5 gen group6 = 0 replace group6 = 1 if groups == 6 gen group7 = 0 replace group7 = 1 if groups == 7 gen group8 = 0 replace group8 = 1 if groups == 8 gen group9 = 0 replace group9 = 1 if groups == 9 gen group10 = 0 replace group10 = 1 if groups == 10 * Gerar variável aleatória para sortear subamostra generate subsample = runiform() replace subsample = 0 if subsample <=0.5 replace subsample = 1 if subsample >0.5 regress y x group2 group3 group4 group5 group6 group7 group8 group9 group10 if subsample == 0 estimates store m5 esttab m1 m2 m5, ci * Case 2 clear matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0.75 \ 0.3, 0.75, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) * Gerar 10 grupos a partir dos decis de z xtile groups = z, nq(10) gen group1 = 0 replace group1 = 1 if groups == 1 gen group2 = 0 replace group2 = 1 if groups == 2 gen group3 = 0 replace group3 = 1 if groups == 3 gen group4 = 0 replace group4 = 1 if groups == 4 gen group5 = 0 replace group5 = 1 if groups == 5 gen group6 = 0 replace group6 = 1 if groups == 6 gen group7 = 0 replace group7 = 1 if groups == 7 gen group8 = 0 replace group8 = 1 if groups == 8 gen group9 = 0 replace group9 = 1 if groups == 9 gen group10 = 0 replace group10 = 1 if groups == 10 * Gerar variável aleatória para sortear subamostra generate subsample = runiform() replace subsample = 0 if subsample <=0.5 replace subsample = 1 if subsample >0.5 regress y x group2 group3 group4 group5 group6 group7 group8 group9 group10 if subsample == 0 estimates store m6 esttab m3 m4 m6, ci * Question 3 * Case 1 clear matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0 \ 0.3, 0, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) * Criar os grupos xtile groups = z, nq(3) gen group1 = 0 replace group1 = 1 if groups == 1 gen group2 = 0 replace group2 = 1 if groups == 2 gen group3 = 0 replace group3 = 1 if groups == 3 regress y x group2 group3 estimates store m7 regress y x z group2 group3 estimates store m8 esttab m1 m2 m5 m7 m8, ci * Case 2 clear matrix m = (100,7,20) matrix sd = (20,8,2) matrix C = (1, 0.7, 0.3 \ 0.7, 1, 0.75 \ 0.3, 0.75, 1) drawnorm y x z, n(500) means (m) sds(sd) corr(C) seed(12345) * Criar os grupos xtile groups = z, nq(3) gen group1 = 0 replace group1 = 1 if groups == 1 gen group2 = 0 replace group2 = 1 if groups == 2 gen group3 = 0 replace group3 = 1 if groups == 3 regress y x group2 group3 estimates store m9 regress y x z group2 group3 estimates store m10 esttab m3 m4 m6 m9 m10, ci