------------------------------------------------------------------------------------------------------------ log: /home/uncv.log log type: text opened on: 26 Jul 2005, 12:29:15 . . /* construction of artificial dataset */ . sysuse auto, clear (1978 Automobile Data) . keep mpg weight . gen id = _n . rename mpg x1 . rename weight x2 . replace x2 = x2/100 x2 was int now float (74 real changes made) . label var x1 . label var x2 . . * the equation for group 1 will be y = x1 - x2, se(u) = 15 . tempfile base one . qui save `base' . set seed 1245 . gen y = x1 - x2 - 15*invnormal(uniform()) . gen group = 1 . qui save `one' . . * the equation for group 2 will be y = x1 + x2, se(u) = 7 . use `base', clear (1978 Automobile Data) . gen y = x1 + x2 + 7*invnormal(uniform()) . gen group = 2 . append using `one' . sort group id . drop id . . * next, the groups will made slightly unbalanced . drop in -3/l (3 observations deleted) . . . * BEGINNING OF DEMONSTRATION . regress y x1 x2 if group==1 /* [1] */ Source | SS df MS Number of obs = 74 -------------+------------------------------ F( 2, 71) = 25.11 Model | 12683.3846 2 6341.69231 Prob > F = 0.0000 Residual | 17929.709 71 252.531112 R-squared = 0.4143 -------------+------------------------------ Adj R-squared = 0.3978 Total | 30613.0936 73 419.357446 Root MSE = 15.891 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.21329 .5445941 2.23 0.029 .1273998 2.29918 x2 | -.8809939 .4054011 -2.17 0.033 -1.689341 -.0726472 _cons | -8.650993 22.73703 -0.38 0.705 -53.98734 36.68535 ------------------------------------------------------------------------------ . regress y x1 x2 if group==2 /* [2] */ Source | SS df MS Number of obs = 71 -------------+------------------------------ F( 2, 68) = 9.73 Model | 1115.13849 2 557.569246 Prob > F = 0.0002 Residual | 3895.1677 68 57.281878 R-squared = 0.2226 -------------+------------------------------ Adj R-squared = 0.1997 Total | 5010.3062 70 71.5758028 Root MSE = 7.5685 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | .9307004 .2636696 3.53 0.001 .4045558 1.456845 x2 | .8812369 .1997562 4.41 0.000 .4826296 1.279844 _cons | 4.646794 11.1593 0.42 0.678 -17.62125 26.91483 ------------------------------------------------------------------------------ . . gen g2 = (group==2) . gen g2x1 = g2*x1 . gen g2x2 = g2*x2 . regress y x1 x2 g2 g2x1 g2x2 /* [3] */ Source | SS df MS Number of obs = 145 -------------+------------------------------ F( 5, 139) = 187.59 Model | 147272.497 5 29454.4995 Prob > F = 0.0000 Residual | 21824.8767 139 157.013501 R-squared = 0.8709 -------------+------------------------------ Adj R-squared = 0.8663 Total | 169097.374 144 1174.28732 Root MSE = 12.531 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.21329 .4294217 2.83 0.005 .3642466 2.062333 x2 | -.8809939 .3196656 -2.76 0.007 -1.51303 -.2489582 g2 | 13.29779 25.74446 0.52 0.606 -37.60359 64.19917 g2x1 | -.2825893 .6123452 -0.46 0.645 -1.493305 .928126 g2x2 | 1.762231 .4599583 3.83 0.000 .8528115 2.67165 _cons | -8.650993 17.92853 -0.48 0.630 -44.09889 26.7969 ------------------------------------------------------------------------------ . . predict r, resid . sum r if group==1 Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- r | 74 -3.10e-08 15.67203 -26.91896 39.68083 . gen w = r(Var)*(r(N)-1)/(r(N)-3) if group==1 (71 missing values generated) . sum r if group==2 Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- r | 71 3.67e-10 7.459575 -14.86926 17.28331 . replace w = r(Var)*(r(N)-1)/(r(N)-3) if group==2 (71 real changes made) . . reg y x1 x2 g2 g2x1 g2x2 [aw=1/w] /* [4] */ (sum of wgt is 1.5325e+00) Source | SS df MS Number of obs = 145 -------------+------------------------------ F( 5, 139) = 188.54 Model | 89195.7978 5 17839.1596 Prob > F = 0.0000 Residual | 13151.5613 139 94.6155491 R-squared = 0.8715 -------------+------------------------------ Adj R-squared = 0.8669 Total | 102347.359 144 710.745549 Root MSE = 9.7271 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.21329 .5445941 2.23 0.027 .1365303 2.290049 x2 | -.8809939 .4054011 -2.17 0.031 -1.682544 -.079444 g2 | 13.29779 25.3279 0.53 0.600 -36.77997 63.37554 g2x1 | -.2825893 .6050657 -0.47 0.641 -1.478912 .913733 g2x2 | 1.762231 .4519431 3.90 0.000 .868659 2.655803 _cons | -8.650993 22.73703 -0.38 0.704 -53.60613 36.30415 ------------------------------------------------------------------------------ . . test g2x1 g2x2 g2 ( 1) g2x1 = 0 ( 2) g2x2 = 0 ( 3) g2 = 0 F( 3, 139) = 307.50 Prob > F = 0.0000 . quietly regress y x1 x2 g2 g2x1 g2x2 /* [3] */ . test g2x1 g2x2 g2 ( 1) g2x1 = 0 ( 2) g2x2 = 0 ( 3) g2 = 0 F( 3, 139) = 300.81 Prob > F = 0.0000 . . xtgls y x1 x2 g2 g2x1 g2x2, panel(het) i(group) /* [5] */ Cross-sectional time-series FGLS regression Coefficients: generalized least squares Panels: heteroskedastic Correlation: no autocorrelation Estimated covariances = 2 Number of obs = 145 Estimated autocorrelations = 0 Number of groups = 2 Estimated coefficients = 6 Obs per group: min = 71 avg = 72.5 max = 74 Wald chi2(5) = 982.90 Log likelihood = -551.0524 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.21329 .5334409 2.27 0.023 .1677648 2.258815 x2 | -.8809939 .3970985 -2.22 0.027 -1.659293 -.1026952 g2 | 13.29779 24.80488 0.54 0.592 -35.31889 61.91446 g2x1 | -.2825893 .5925734 -0.48 0.633 -1.444012 .8788333 g2x2 | 1.762231 .4426101 3.98 0.000 .894731 2.629731 _cons | -8.650993 22.27137 -0.39 0.698 -52.30208 35.00009 ------------------------------------------------------------------------------ . log close log: /home/uncv.log log type: text closed on: 26 Jul 2005, 12:29:16 ------------------------------------------------------------------------------------------------------------