Dear all
I'm trying to do adjust my standard errors after manual 2SLS. I'm practicing this using the sample data attached, but in my actual dataset I need to do 2SLS manually due to different numbers of observations in first and second stage since my dependent variable is at the individual level but my endogenous regressor and instrument is at the family level.
I'm basing my approach off of this
Here is a sample of my data:
Here are my commands:
As you can see, the results are very different. Any help would be much appreciated.
Many thanks
Owen
I'm trying to do adjust my standard errors after manual 2SLS. I'm practicing this using the sample data attached, but in my actual dataset I need to do 2SLS manually due to different numbers of observations in first and second stage since my dependent variable is at the individual level but my endogenous regressor and instrument is at the family level.
I'm basing my approach off of this
Here is a sample of my data:
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long efamid float(nfamid chmarried6 chtotal6) byte childnum6 float(cheduc5 chage6 chsex6 feduc meduc fses i_faminc gsrelig4 FEsamp iv_d_spfamsize spfamsize) byte(spsibs z_ak067ss)
1200002 4 0 3 1 12 45 1 13 12 26.6 15.6 6 1 0 8 7 7
1200002 4 . 3 2 . 42 1 13 12 26.6 15.6 6 1 . 8 7 7
1200002 4 1 3 3 16 38 0 13 12 26.6 15.6 6 1 . 8 7 7
1200004 7 1 2 1 18 42 1 20 18 79.4 24 7 1 0 3 2 2
1200004 7 1 2 2 18 37 0 20 18 79.4 24 7 1 . 3 2 2
1200005 8 1 2 1 13 49 1 14 12 74.7 27.5 5 1 0 2 1 1
1200005 8 0 2 2 12 48 0 14 12 74.7 27.5 5 1 . 2 1 1
1200007 12 1 3 1 18 38 0 16 16 60.9 25 . 1 . . . .
1200007 12 . 3 2 . 35 1 16 16 60.9 25 . 1 . . . .
1200007 12 1 3 3 . . 0 16 16 60.9 25 . 1 . . . .
1200007 13 1 3 1 19 46 1 17 16 76.8 35 0 1 0 4 3 3
1200007 13 1 3 2 16 43 0 17 16 76.8 35 0 1 . 4 3 3
1200007 13 1 3 3 16 42 1 17 16 76.8 35 0 1 . 4 3 3
1200009 15 1 9 1 16 50 0 13 15 67 11.5 8 1 0 9 8 7
1200009 15 1 9 2 16 48 0 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 3 13 47 0 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 4 16 46 1 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 5 16 45 1 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 6 16 44 0 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 7 16 44 1 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 8 16 41 0 13 15 67 11.5 8 1 . 9 8 7
1200009 15 1 9 9 16 33 0 13 15 67 11.5 8 1 . 9 8 7
1200009 16 1 3 1 16 60 1 14 12 60 0 7 1 . . . .
1200009 16 1 3 2 . 53 1 14 12 60 0 7 1 . . . .
1200009 16 1 3 3 14 46 0 14 12 60 0 7 1 . . . .
1200010 18 0 2 1 16 34 1 17 12 70.2 18 7 1 . . . .
1200010 18 1 2 2 . 30 0 17 12 70.2 18 7 1 . . . .
1200011 19 1 2 1 16 45 1 12 12 19 9.5 1 1 0 3 2 .
1200011 19 1 2 2 12 43 0 12 12 19 9.5 1 1 . 3 2 .
1200012 21 1 4 1 12 47 0 12 12 66 14.2 11 1 0 3 2 2
1200012 21 1 4 2 12 45 0 12 12 66 14.2 11 1 . 3 2 2
1200012 21 0 4 3 12 43 1 12 12 66 14.2 11 1 . 3 2 2
1200012 21 1 4 4 12 38 0 12 12 66 14.2 11 1 . 3 2 2
1200013 23 0 3 1 16 44 1 17 16 70.2 11 7 1 0 2 1 .
1200013 23 1 3 2 16 42 1 17 16 70.2 11 7 1 . 2 1 .
1200013 23 1 3 3 16 40 1 17 16 70.2 11 7 1 . 2 1 .
1200015 28 0 2 1 16 42 0 12 12 26.5 13.447087 2 1 0 4 . 4
1200015 28 0 2 2 . 39 1 12 12 26.5 13.447087 2 1 . 4 . 4
1200016 29 1 3 1 14 52 0 13 12 62.1 18 1 1 0 4 3 3
1200016 29 0 3 2 13 50 1 13 12 62.1 18 1 1 . 4 3 3
1200016 29 0 3 3 16 48 0 13 12 62.1 18 1 1 . 4 3 3
1200017 31 0 2 1 16 30 0 14 12 80.2 . . 1 . 5 . 5
1200017 31 0 2 2 . 30 1 14 12 80.2 . . 1 . 5 . 5
1200017 32 1 3 1 15 48 1 12 12 37 13.1 7 1 0 2 1 1
1200017 32 1 3 2 12 47 0 12 12 37 13.1 7 1 . 2 1 1
1200017 32 1 3 3 15 36 1 12 12 37 13.1 7 1 . 2 1 1
1200018 33 0 3 1 14 49 0 12 12 71 0 7 1 . . . .
1200018 33 0 3 2 . . 1 12 12 71 0 7 1 . . . .
1200018 33 1 3 3 . . 0 12 12 71 0 7 1 . . . .
1200019 35 1 4 1 16 44 1 18 12 79 30 7 1 .5999999 3 2 2
1200019 35 1 4 2 16 42 1 18 12 79 30 7 1 . 3 2 2
1200019 35 0 4 3 18 41 1 18 12 79 30 7 1 . 3 2 2
1200019 35 1 4 4 16 38 1 18 12 79 30 7 1 . 3 2 2
1200019 36 1 2 1 16 31 0 16 16 43.7 17.212366 7 1 -2.4 0 . 0
1200019 36 0 2 2 . 27 1 16 16 43.7 17.212366 7 1 . 0 . 0
1200020 37 . 2 1 19 . 0 22 18 84 18 7 1 . 3 2 2
1200020 37 . 2 2 19 . 0 22 18 84 18 7 1 . 3 2 2
1200021 39 0 2 1 14 48 0 15 16 66 21.9 7 1 . . . .
1200021 39 0 2 2 . 46 1 15 16 66 21.9 7 1 . . . .
1200021 40 1 4 1 16 52 0 15 12 62 17 5 1 0 3 2 2
1200021 40 1 4 2 16 50 1 15 12 62 17 5 1 . 3 2 2
1200021 40 1 4 3 16 46 0 15 12 62 17 5 1 . 3 2 2
1200021 40 1 4 4 12 42 0 15 12 62 17 5 1 . 3 2 2
1200024 45 . 2 1 . 41 1 16 16 43.3 . . 1 . 2 . 2
1200024 45 1 2 2 . 38 0 16 16 43.3 . . 1 . 2 . 2
1200028 52 1 2 1 16 44 1 12 12 34 15.7 4 1 0 3 2 2
1200028 52 1 2 2 12 42 1 12 12 34 15.7 4 1 . 3 2 2
1200028 53 1 2 1 . 36 0 12 12 26.6 11.489403 7 1 . . . .
1200028 53 1 2 2 . 32 1 12 12 26.6 11.489403 7 1 . . . .
1200029 54 0 4 1 16 49 0 16 12 84 30 7 1 0 3 2 .
1200029 54 1 4 2 13 46 0 16 12 84 30 7 1 . 3 2 .
1200029 54 1 4 3 16 43 0 16 12 84 30 7 1 . 3 2 .
1200029 54 1 4 4 14 39 0 16 12 84 30 7 1 . 3 2 .
1200032 60 0 7 1 13 56 1 16 15 79 37 7 1 0 2 1 1
1200032 60 1 7 2 16 54 1 16 15 79 37 7 1 . 2 1 1
1200032 60 1 7 3 14 52 0 16 15 79 37 7 1 . 2 1 1
1200032 60 1 7 4 12 50 0 16 15 79 37 7 1 . 2 1 1
1200032 60 1 7 5 14 48 0 16 15 79 37 7 1 . 2 1 1
1200032 60 . 7 6 . 45 1 16 15 79 37 7 1 . 2 1 1
1200032 60 1 7 7 16 36 0 16 15 79 37 7 1 . 2 1 1
1200033 61 0 3 1 12 49 1 14 13 79 32 4 1 0 4 3 .
1200033 61 1 3 2 11 45 1 14 13 79 32 4 1 . 4 3 .
1200033 61 . 3 3 . 21 0 14 13 79 32 4 1 . 4 3 .
1200034 64 0 6 1 13 49 0 16 12 79.5 0 7 1 0 3 2 4
1200034 64 . 6 2 12 49 1 16 12 79.5 0 7 1 . 3 2 4
1200034 64 . 6 3 . 48 0 16 12 79.5 0 7 1 . 3 2 4
1200034 64 1 6 4 16 47 0 16 12 79.5 0 7 1 . 3 2 4
1200034 64 1 6 5 16 46 1 16 12 79.5 0 7 1 . 3 2 4
1200034 64 1 6 6 16 43 0 16 12 79.5 0 7 1 . 3 2 4
1200036 67 1 2 1 16 50 0 12 12 34 25 7 1 0 2 1 .
1200036 67 1 2 2 16 48 0 12 12 34 25 7 1 . 2 1 .
1200036 68 0 7 1 18 56 1 12 12 44 9 9 1 . . . .
1200036 68 1 7 2 . 53 0 12 12 44 9 9 1 . . . .
1200036 68 . 7 3 . 51 1 12 12 44 9 9 1 . . . .
1200036 68 . 7 4 . 47 1 12 12 44 9 9 1 . . . .
1200036 68 1 7 5 12 43 1 12 12 44 9 9 1 . . . .
1200036 68 0 7 6 12 41 0 12 12 44 9 9 1 . . . .
1200036 68 1 7 7 12 39 1 12 12 44 9 9 1 . . . .
1200037 69 1 2 1 16 39 0 17 12 79.5 12.4 0 1 0 4 3 4
1200037 69 0 2 2 16 37 1 17 12 79.5 12.4 0 1 . 4 3 4
end
label values chsex6 QQDUMSEX
label def QQDUMSEX 0 "Female", modify
label def QQDUMSEX 1 "Male", modify
label values spsibs SPSIBS
label values z_ak067ss QQOLDJUSTMISSING
Code:
*Seeing what results should be ivregress 2sls chmarried6 cheduc5 chage6 fses feduc (chtotal6 = spfamsize), vce(cluster nfamid) estat vce di e(rmse) mat v2sls = e(V) *Performing manually mark data_IV markout data_IV chmarried6 cheduc5 chage6 fses feduc chtotal6 spfamsize nfamid qui reg chtotal6 spfamsize cheduc5 chage6 fses feduc if(data_IV), vce(cluster nfamid) predict chtotal6_hat reg chmarried6 chtotal6_hat cheduc5 chage6 fses feduc, vce(cluster nfamid) scalar rmsebyhand = e(rmse) *The wrong VCE calculated from instruments mat vbyhand = e(V) scalar dfk = e(df_r) *Correct resids: orig regressors * second stage coeffs gen double eps2 = (chmarried6 - _b[chtotal6_hat]*chtotal6 - _b[cheduc5]*cheduc5 - _b[chage6]*chage6 - _b[feduc]*feduc - _b[fses]*fses - _b[_cons])^2 if data_IV qui su eps2 *Corrected RMSE, based on the correct resids scalar rmsecorr = sqrt(r(sum) / dfk) *Corrected VCE, using the right s^2 mat vcorr = (rmsecorr / rmsebyhand)^2 * vbyhand mat li vcorr *Check to see that it equals real 2SLS VCE mat diff = v2sls - vcorr mat li diff
Many thanks
Owen