-------------------------------------------------------------------------------- log: C:\Documents and Settings\Patricia_Anderson\My Documents\ECON 20\In > Class\nov13.log log type: text opened on: 13 Nov 2002, 11:14:52 . **example of correcting standard errors for hetero and serial corr . use jtrain . desc Contains data from jtrain.dta obs: 471 vars: 30 13 Sep 2000 15:32 size: 44,745 (100.0% of memory free) ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- year int %9.0g 1987, 1988, or 1989 fcode float %9.0g firm code number employ int %9.0g # employees at plant sales float %9.0g annual sales, $ avgsal float %9.0g average employee salary scrap float %9.0g scrap rate (per 100 items) rework float %9.0g rework rate (per 100 items) tothrs int %9.0g total hours training union byte %9.0g =1 if unionized grant byte %9.0g =1 if received grant d89 byte %9.0g =1 if year = 1989 d88 byte %9.0g =1 if year = 1988 totrain int %9.0g total employees trained hrsemp float %9.0g tothrs/totrain lscrap float %9.0g log(scrap) lemploy float %9.0g log(employ) lsales float %9.0g log(sales) lrework float %9.0g log(rework) lhrsemp float %9.0g log(1 + hrsemp) lscrap_1 float %9.0g lagged lscrap; missing 1987 grant_1 byte %9.0g lagged grant; assumed 0 in 1987 clscrap float %9.0g lscrap - lscrap_1; year > 1987 cgrant byte %9.0g grant - grant_1 clemploy float %9.0g lemploy - lemploy[t-1] clsales float %9.0g lavgsal - lavgsal[t-1] lavgsal float %9.0g log(avgsal) clavgsal float %9.0g lavgsal - lavgsal[t-1] cgrant_1 byte %9.0g cgrant[t-1] chrsemp float %9.0g hrsemp - hrsemp[t-1] clhrsemp float %9.0g lhrsemp - lhrsemp[t-1] ------------------------------------------------------------------------------- Sorted by: . reg lhrsemp grant lemploy d88 d89, cluster(fcode) Regression with robust standard errors Number of obs = 390 F( 4, 134) = 75.38 Prob > F = 0.0000 R-squared = 0.2630 Number of clusters (fcode) = 135 Root MSE = 1.3291 ------------------------------------------------------------------------------ | Robust lhrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- grant | 1.96604 .136397 14.41 0.000 1.69627 2.235809 lemploy | -.1382575 .100194 -1.38 0.170 -.3364237 .0599087 d88 | .1502718 .0796659 1.89 0.061 -.0072934 .307837 d89 | .5444077 .1142462 4.77 0.000 .3184487 .7703667 _cons | 1.60936 .4005309 4.02 0.000 .8171799 2.401541 ------------------------------------------------------------------------------ . **re-run with first differences . clhrsemp cgrant clemploy d89, cluster(fcode) unrecognized command: clhrsemp r(199); . reg clhrsemp cgrant clemploy d89, cluster(fcode) Regression with robust standard errors Number of obs = 251 F( 3, 126) = 71.48 Prob > F = 0.0000 R-squared = 0.5550 Number of clusters (fcode) = 127 Root MSE = 1.077 ------------------------------------------------------------------------------ | Robust clhrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- cgrant | 2.068721 .1450664 14.26 0.000 1.781639 2.355803 clemploy | .0380198 .5769502 0.07 0.948 -1.103748 1.179787 d89 | .2864464 .1551835 1.85 0.067 -.0206572 .59355 _cons | .1255495 .07487 1.68 0.096 -.022616 .273715 ------------------------------------------------------------------------------ . **re-run with fixed effects . areg lhrsemp grant lemploy d88 d89, absorb(fcode) cluster(fcode) Regression with robust standard errors Number of obs = 390 F( 3, 251) = 63.21 Prob > F = 0.0000 R-squared = 0.8269 Adj R-squared = 0.7317 Root MSE = .79778 (standard errors adjusted for clustering on fcode) ------------------------------------------------------------------------------ | Robust lhrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- grant | 2.093155 .1704372 12.28 0.000 1.757486 2.428825 lemploy | -.2220805 .4424021 -0.50 0.616 -1.093374 .6492128 d88 | .1402767 .0933301 1.50 0.134 -.0435332 .3240867 d89 | .5781834 .1647619 3.51 0.001 .2536914 .9026754 _cons | 1.880561 1.538608 1.22 0.223 -1.149666 4.910787 -------------+---------------------------------------------------------------- fcode | absorbed (135 categories) . **re-run with random effects . xtreg lhrsemp grant lemploy d88 d89, i(fcode) re Random-effects GLS regression Number of obs = 390 Group variable (i) : fcode Number of groups = 135 R-sq: within = 0.5759 Obs per group: min = 1 between = 0.0471 avg = 2.9 overall = 0.2630 max = 3 Random effects u_i ~ Gaussian Wald chi2(4) = 346.48 corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ lhrsemp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- grant | 2.069807 .1320726 15.67 0.000 1.81095 2.328665 lemploy | -.1436618 .0904043 -1.59 0.112 -.320851 .0335274 d88 | .1352416 .1055901 1.28 0.200 -.0717113 .3421944 d89 | .5553465 .1043135 5.32 0.000 .3508958 .7597972 _cons | 1.608945 .3342504 4.81 0.000 .9538267 2.264064 -------------+---------------------------------------------------------------- sigma_u | 1.0666488 sigma_e | .797782 rho | .64127063 (fraction of variance due to u_i) ------------------------------------------------------------------------------ . **do a hausman test . xthaus Hausman specification test ---- Coefficients ---- | Fixed Random lhrsemp | Effects Effects Difference -------------+----------------------------------------- grant | 2.093155 2.069807 .0233482 lemploy | -.2220805 -.1436618 -.0784187 d88 | .1402767 .1352416 .0050351 d89 | .5781834 .5553465 .0228369 Test: Ho: difference in coefficients not systematic chi2( 4) = (b-B)'[S^(-1)](b-B), S = (S_fe - S_re) = 4.41 Prob>chi2 = 0.3538 . **so no correlation and OLS is fine, but fix the std errors . reg clhrsemp cgrant clemploy d89, cluster(fcode) Regression with robust standard errors Number of obs = 251 F( 3, 126) = 71.48 Prob > F = 0.0000 R-squared = 0.5550 Number of clusters (fcode) = 127 Root MSE = 1.077 ------------------------------------------------------------------------------ | Robust clhrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- cgrant | 2.068721 .1450664 14.26 0.000 1.781639 2.355803 clemploy | .0380198 .5769502 0.07 0.948 -1.103748 1.179787 d89 | .2864464 .1551835 1.85 0.067 -.0206572 .59355 _cons | .1255495 .07487 1.68 0.096 -.022616 .273715 ------------------------------------------------------------------------------ . reg lhrsemp grant lemploy d88 d89, cluster(fcode) Regression with robust standard errors Number of obs = 390 F( 4, 134) = 75.38 Prob > F = 0.0000 R-squared = 0.2630 Number of clusters (fcode) = 135 Root MSE = 1.3291 ------------------------------------------------------------------------------ | Robust lhrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- grant | 1.96604 .136397 14.41 0.000 1.69627 2.235809 lemploy | -.1382575 .100194 -1.38 0.170 -.3364237 .0599087 d88 | .1502718 .0796659 1.89 0.061 -.0072934 .307837 d89 | .5444077 .1142462 4.77 0.000 .3184487 .7703667 _cons | 1.60936 .4005309 4.02 0.000 .8171799 2.401541 ------------------------------------------------------------------------------ . use wagepan, clear . desc Contains data from wagepan.dta obs: 4,360 vars: 27 13 Sep 2000 15:42 size: 165,680 (99.9% of memory free) ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- nr int %9.0g person identifier year int %9.0g 1980 to 1987 black byte %9.0g =1 if black exper byte %9.0g labor market experience hisp byte %9.0g =1 if Hispanic hours int %9.0g annual hours worked married byte %9.0g =1 if married occ1 byte %9.0g =1 if occupation == 1 occ2 byte %9.0g =1 if occupation == 2 occ3 byte %9.0g occ4 byte %9.0g occ5 byte %9.0g occ6 byte %9.0g occ7 byte %9.0g occ8 byte %9.0g occ9 byte %9.0g educ byte %9.0g years of schooling union byte %9.0g =1 if in union lwage float %9.0g log(wage) d81 byte %9.0g =1 if year == 1981 d82 byte %9.0g d83 byte %9.0g d84 byte %9.0g d85 byte %9.0g d86 byte %9.0g d87 byte %9.0g expersq int %9.0g exper^2 ------------------------------------------------------------------------------- Sorted by: . **very simple look at effect of union status and hours worked . reg lwage union hours d81-87, cluster(nr) 87 invalid name r(198); . reg lwage union hours d81-d87, cluster(nr) Regression with robust standard errors Number of obs = 4360 F( 9, 544) = 56.69 Prob > F = 0.0000 R-squared = 0.0993 Number of clusters (nr) = 545 Root MSE = .506 ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- union | .1809054 .0296387 6.10 0.000 .122685 .2391258 hours | -.000045 .0000264 -1.71 0.089 -.0000969 6.84e-06 d81 | .1246873 .0246643 5.06 0.000 .0762383 .1731363 d82 | .1842392 .0242131 7.61 0.000 .1366766 .2318018 d83 | .2384 .0251083 9.49 0.000 .1890788 .2877212 d84 | .310814 .0284821 10.91 0.000 .2548657 .3667623 d85 | .3657845 .0269231 13.59 0.000 .3128984 .4186705 d86 | .4297731 .0284666 15.10 0.000 .3738551 .485691 d87 | .4892394 .0272362 17.96 0.000 .4357384 .5427403 _cons | 1.435786 .0597381 24.03 0.000 1.31844 1.553131 ------------------------------------------------------------------------------ . **make our own changes . sort nr year . by nr: gen lwage_1=lwage[_n-1] (545 missing values generated) . by nr: gen union_1=union[_n-1] (545 missing values generated) . by nr: gen hours_1=hours[_n-1] (545 missing values generated) . gen clwage=lwage-lwage_1 (545 missing values generated) . gen cunion=union-union_1 (545 missing values generated) . gen chours=hours-hours_1 (545 missing values generated) . reg clwage cunion chours d82-d87 Source | SS df MS Number of obs = 3815 -------------+------------------------------ F( 8, 3806) = 32.30 Model | 47.7610146 8 5.97012682 Prob > F = 0.0000 Residual | 703.432909 3806 .184822099 R-squared = 0.0636 -------------+------------------------------ Adj R-squared = 0.0616 Total | 751.193923 3814 .19695698 Root MSE = .42991 ------------------------------------------------------------------------------ clwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- cunion | .0406641 .019113 2.13 0.033 .0031913 .0781369 chours | -.0002253 .0000145 -15.59 0.000 -.0002537 -.000197 d82 | -.0754047 .0260602 -2.89 0.004 -.126498 -.0243114 d83 | -.0733842 .0260441 -2.82 0.005 -.1244459 -.0223226 d84 | -.0616046 .0260568 -2.36 0.018 -.1126911 -.0105181 d85 | -.0896953 .026081 -3.44 0.001 -.1408293 -.0385613 d86 | -.0766948 .0260698 -2.94 0.003 -.1278069 -.0255826 d87 | -.0696342 .0260802 -2.67 0.008 -.1207667 -.0185016 _cons | .1443152 .0184842 7.81 0.000 .1080753 .180555 ------------------------------------------------------------------------------ . **easier to do fixed effects . areg lwage union hours d81-d87, absorb(nr) cluster(nr) Regression with robust standard errors Number of obs = 4360 F( 8, 3806) = 55.98 Prob > F = 0.0000 R-squared = 0.6222 Adj R-squared = 0.5673 Root MSE = .35036 (standard errors adjusted for clustering on nr) ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- union | .0794695 .0245429 3.24 0.001 .0313511 .127588 hours | -.0001174 .000023 -5.10 0.000 -.0001625 -.0000723 d81 | .1324807 .0258666 5.12 0.000 .0817669 .1831944 d82 | .1961194 .0253324 7.74 0.000 .1464529 .2457859 d83 | .2565126 .0259165 9.90 0.000 .2057011 .307324 d84 | .3333069 .0287604 11.59 0.000 .2769197 .3896942 d85 | .3868938 .0280527 13.79 0.000 .331894 .4418936 d86 | .4517597 .0296718 15.23 0.000 .3935856 .5099338 d87 | .5196515 .027954 18.59 0.000 .4648452 .5744578 _cons | 1.602363 .0527261 30.39 0.000 1.498988 1.705737 -------------+---------------------------------------------------------------- nr | absorbed (545 categories) . **try a long difference (5yrs) . by nr: gen lwage_5=lwage[_n-5] (2725 missing values generated) . by nr: gen union_5=union[_n-5] (2725 missing values generated) . by nr: gen hours_5=hours[_n-5] (2725 missing values generated) . gen clwage5=lwage-lwage_5 (2725 missing values generated) . gen cunion5=union-union_5 (2725 missing values generated) . gen chours5=hours-hours_5 (2725 missing values generated) . reg clwage cunion chours d82-d87 Source | SS df MS Number of obs = 3815 -------------+------------------------------ F( 8, 3806) = 32.30 Model | 47.7610146 8 5.97012682 Prob > F = 0.0000 Residual | 703.432909 3806 .184822099 R-squared = 0.0636 -------------+------------------------------ Adj R-squared = 0.0616 Total | 751.193923 3814 .19695698 Root MSE = .42991 ------------------------------------------------------------------------------ clwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- cunion | .0406641 .019113 2.13 0.033 .0031913 .0781369 chours | -.0002253 .0000145 -15.59 0.000 -.0002537 -.000197 d82 | -.0754047 .0260602 -2.89 0.004 -.126498 -.0243114 d83 | -.0733842 .0260441 -2.82 0.005 -.1244459 -.0223226 d84 | -.0616046 .0260568 -2.36 0.018 -.1126911 -.0105181 d85 | -.0896953 .026081 -3.44 0.001 -.1408293 -.0385613 d86 | -.0766948 .0260698 -2.94 0.003 -.1278069 -.0255826 d87 | -.0696342 .0260802 -2.67 0.008 -.1207667 -.0185016 _cons | .1443152 .0184842 7.81 0.000 .1080753 .180555 ------------------------------------------------------------------------------ . reg clwage5 cunion5 chours5 d82-d87 Source | SS df MS Number of obs = 1635 -------------+------------------------------ F( 4, 1630) = 5.89 Model | 7.266858 4 1.8167145 Prob > F = 0.0001 Residual | 502.767898 1630 .308446563 R-squared = 0.0142 -------------+------------------------------ Adj R-squared = 0.0118 Total | 510.034756 1634 .312138773 Root MSE = .55538 ------------------------------------------------------------------------------ clwage5 | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- cunion5 | .0936479 .0301019 3.11 0.002 .0346054 .1526903 chours5 | -.0000608 .0000203 -3.00 0.003 -.0001006 -.000021 d82 | (dropped) d83 | (dropped) d84 | (dropped) d85 | (dropped) d86 | -.0629245 .0336858 -1.87 0.062 -.1289965 .0031475 d87 | -.0591955 .0336965 -1.76 0.079 -.1252885 .0068975 _cons | .368597 .0247145 14.91 0.000 .3201214 .4170726 ------------------------------------------------------------------------------ . **try a lagged dep var model . reg lwage lwage_1 union hours educ black hisp, cluster(nr) Regression with robust standard errors Number of obs = 3815 F( 6, 544) = 194.71 Prob > F = 0.0000 R-squared = 0.4405 Number of clusters (nr) = 545 Root MSE = .38839 ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- lwage_1 | .590737 .0262682 22.49 0.000 .5391374 .6423366 union | .0656593 .0158901 4.13 0.000 .0344458 .0968727 hours | -.0000755 .0000161 -4.68 0.000 -.0001071 -.0000438 educ | .0360128 .0045272 7.95 0.000 .0271198 .0449058 black | -.0788788 .0256794 -3.07 0.002 -.1293216 -.0284359 hisp | .0113738 .0193173 0.59 0.556 -.0265719 .0493195 _cons | .4653702 .0660825 7.04 0.000 .3355621 .5951782 ------------------------------------------------------------------------------ . reg lwage union hours educ black hisp, cluster(nr) Regression with robust standard errors Number of obs = 4360 F( 5, 544) = 27.03 Prob > F = 0.0000 R-squared = 0.0937 Number of clusters (nr) = 545 Root MSE = .50734 ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- union | .1937147 .0284167 6.82 0.000 .1378948 .2495346 hours | .0000112 .000026 0.43 0.666 -.0000398 .0000622 educ | .0766324 .0091196 8.40 0.000 .0587184 .0945463 black | -.152231 .0511444 -2.98 0.003 -.2526957 -.0517663 hisp | .0127827 .0397009 0.32 0.748 -.0652031 .0907685 _cons | .6911483 .1299256 5.32 0.000 .435931 .9463656 ------------------------------------------------------------------------------ . **compare across same samples . reg lwage union hours educ black hisp if lwage_1~=., cluster(nr) Regression with robust standard errors Number of obs = 3815 F( 5, 544) = 28.17 Prob > F = 0.0000 R-squared = 0.1044 Number of clusters (nr) = 545 Root MSE = .49135 ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- union | .1810353 .0292378 6.19 0.000 .1236025 .2384681 hours | -.0000438 .0000279 -1.57 0.117 -.0000986 .000011 educ | .0797809 .009329 8.55 0.000 .0614557 .0981061 black | -.1626381 .0542668 -3.00 0.003 -.2692362 -.05604 hisp | .0171563 .0407932 0.42 0.674 -.0629751 .0972878 _cons | .8165593 .134623 6.07 0.000 .5521147 1.081004 ------------------------------------------------------------------------------ . reg lwage lwage_1 union hours educ black hisp, cluster(nr) Regression with robust standard errors Number of obs = 3815 F( 6, 544) = 194.71 Prob > F = 0.0000 R-squared = 0.4405 Number of clusters (nr) = 545 Root MSE = .38839 ------------------------------------------------------------------------------ | Robust lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- lwage_1 | .590737 .0262682 22.49 0.000 .5391374 .6423366 union | .0656593 .0158901 4.13 0.000 .0344458 .0968727 hours | -.0000755 .0000161 -4.68 0.000 -.0001071 -.0000438 educ | .0360128 .0045272 7.95 0.000 .0271198 .0449058 black | -.0788788 .0256794 -3.07 0.002 -.1293216 -.0284359 hisp | .0113738 .0193173 0.59 0.556 -.0265719 .0493195 _cons | .4653702 .0660825 7.04 0.000 .3355621 .5951782 ------------------------------------------------------------------------------ . log close log: C:\Documents and Settings\Patricia_Anderson\My Documents\ECON 20\I > nClass\nov13.log log type: text closed on: 13 Nov 2002, 12:29:11 -------------------------------------------------------------------------------