======================================= ===============Results=================== ======================================= . // chp8_panel data . . * -to reader-*: 具体使用时,你可能需要更改数据存储的路径 . use "D:\stata8\ado\Examples\XTFiles\grunfeld.dta", clear . . *--A1--* . tsset company year /*declare Panel-variable and Time-variable*/ > panel variable: company, 1 to 10 time variable: year, 1935 to 1954 . . gen Lag_invest = L.invest (10 missing values generated) . order company year invest Lag_invest /*从新排列命令窗口中变量的显示顺序*/ . . *--A2--* . xtdes /* To describe the pattern of Panel Data */ company: 1, 2, ..., 10 n = 10 year: 1935, 1936, ..., 1954 T = 20 Delta(year) = 1; (1954-1935)+1 = 20 (company*year uniquely identifies each observation) Distribution of T_i: min 5% 25% 50% 75% 95% max 20 20 20 20 20 20 20 Freq. Percent Cum. | Pattern ---------------------------+---------------------- 10 100.00 100.00 | 11111111111111111111 ---------------------------+---------------------- 10 100.00 | XXXXXXXXXXXXXXXXXXXX . xtsum /* To calculate the describative statistics*/ Variable | Mean Std. Dev. Min Max | Observations -----------------+--------------------------------------------+---------------- company overall | 5.5 2.879489 1 10 | N = 200 between | 3.02765 1 10 | n = 10 within | 0 5.5 5.5 | T = 20 | | year overall | 1944.5 5.780751 1935 1954 | N = 200 between | 0 1944.5 1944.5 | n = 10 within | 5.780751 1935 1954 | T = 20 | | invest overall | 145.9583 216.8753 .93 1486.7 | N = 200 between | 198.8242 3.0845 608.02 | n = 10 within | 106.1986 -204.3617 1024.638 | T = 20 | | Lag_in~t overall | 139.2307 198.0107 .93 1304.4 | N = 190 between | 187.4249 2.977368 561.7737 | n = 10 within | 86.17229 -164.8429 881.8571 | T = 19 | | mvalue overall | 1081.681 1314.47 58.12 6241.7 | N = 200 between | 1334.917 70.921 4333.845 | n = 10 within | 340.5421 -459.964 2989.536 | T = 20 | | kstock overall | 276.0172 301.1039 .8 2226.3 | N = 200 between | 200.9701 5.9415 648.435 | n = 10 within | 232.6603 -369.6179 1853.882 | T = 20 | | time overall | 10.5 5.780751 1 20 | N = 200 between | 0 10.5 10.5 | n = 10 within | 5.780751 1 20 | T = 20 . //xttab invest . . *--A3--* . xtreg mvalue invest kstock,fe /*to estimate fixed-effect model*/ Fixed-effects (within) regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4117 Obs per group: min = 20 between = 0.8078 avg = 20.0 overall = 0.7388 max = 20 F(2,188) = 65.78 corr(u_i, Xb) = 0.6955 Prob > F = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 2.856166 .3075147 9.29 0.000 2.249543 3.462789 kstock | -.5078673 .1403662 -3.62 0.000 -.7847625 -.2309721 _cons | 804.9802 32.43177 24.82 0.000 741.0033 868.9571 -------------+---------------------------------------------------------------- sigma_u | 905.81517 sigma_e | 268.73329 rho | .91910377 (fraction of variance due to u_i) ------------------------------------------------------------------------------ F test that all u_i=0: F(9, 188) = 113.76 Prob > F = 0.0000 . xtreg mvalue invest kstock,re /*to estimate random-effect model*/ Random-effects GLS regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4115 Obs per group: min = 20 between = 0.8043 avg = 20.0 overall = 0.7371 max = 20 Random effects u_i ~ Gaussian Wald chi2(2) = 149.94 corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 3.113429 .3076132 10.12 0.000 2.510519 3.71634 kstock | -.578422 .1424721 -4.06 0.000 -.8576622 -.2991819 _cons | 786.9048 182.1715 4.32 0.000 429.8553 1143.954 -------------+---------------------------------------------------------------- sigma_u | 546.52144 sigma_e | 268.73329 rho | .80529268 (fraction of variance due to u_i) ------------------------------------------------------------------------------ . xtgls mvalue invest kstock,panels(he) /*to estimate the model with Heteroskedastic variance > with GLS*/ Cross-sectional time-series FGLS regression Coefficients: generalized least squares Panels: heteroskedastic Correlation: no autocorrelation Estimated covariances = 10 Number of obs = 200 Estimated autocorrelations = 0 Number of groups = 10 Estimated coefficients = 3 Time periods = 20 Wald chi2(2) = 326.06 Log likelihood = -1445.752 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 5.666927 .3139891 18.05 0.000 5.05152 6.282335 kstock | -.6849888 .1123445 -6.10 0.000 -.90518 -.4647977 _cons | 299.1641 29.96708 9.98 0.000 240.4297 357.8985 ------------------------------------------------------------------------------ . . *--A4--* . *-Test fixed effect-* . * method1: calculate the F statistic by yourself . // step1 : estimate Pooled model and store R2 . reg mvalue invest kstock Source | SS df MS Number of obs = 200 -------------+------------------------------ F( 2, 197) = 288.50 Model | 256323828 2 128161914 Prob > F = 0.0000 Residual | 87514460.3 197 444235.839 R-squared = 0.7455 -------------+------------------------------ Adj R-squared = 0.7429 Total | 343838288 199 1727830.6 Root MSE = 666.51 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 5.759807 .2908613 19.80 0.000 5.186206 6.333409 kstock | -.6152727 .2094979 -2.94 0.004 -1.028419 -.2021263 _cons | 410.8156 64.14189 6.40 0.000 284.3227 537.3084 ------------------------------------------------------------------------------ . ereturn list /*to reader: please see the results after this command*/ scalars: e(N) = 200 e(df_m) = 2 e(df_r) = 197 e(F) = 288.4997172285366 e(r2) = .7454778502025821 e(rmse) = 666.5101944725171 e(mss) = 256323828.0623155 e(rss) = 87514460.34915113 e(r2_a) = .7428938689863647 e(ll) = -1582.687429866819 e(ll_0) = -1719.524171284405 macros: e(depvar) : "mvalue" e(cmd) : "regress" e(predict) : "regres_p" e(model) : "ols" matrices: e(b) : 1 x 3 e(V) : 3 x 3 functions: e(sample) . local R2_r = e(r2) . local K = e(df_m) . . // step2 : estimate Fixed-effect model and store R2 . xtreg mvalue invest kstock , fe Fixed-effects (within) regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4117 Obs per group: min = 20 between = 0.8078 avg = 20.0 overall = 0.7388 max = 20 F(2,188) = 65.78 corr(u_i, Xb) = 0.6955 Prob > F = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 2.856166 .3075147 9.29 0.000 2.249543 3.462789 kstock | -.5078673 .1403662 -3.62 0.000 -.7847625 -.2309721 _cons | 804.9802 32.43177 24.82 0.000 741.0033 868.9571 -------------+---------------------------------------------------------------- sigma_u | 905.81517 sigma_e | 268.73329 rho | .91910377 (fraction of variance due to u_i) ------------------------------------------------------------------------------ F test that all u_i=0: F(9, 188) = 113.76 Prob > F = 0.0000 . local R2_u = 1- e(rss)/e(tss) . local nT = e(N) . local n = e(N_g) . . // step3 : calculate the F statistics and P-value . local F1 = (`R2_u' - `R2_r')/(`n' - 1) . local F2 = (1 - `R2_u')/(`nT' - `n' - `K') . local F = `F1'/`F2' . local p = 1- F(`n' - 1,`nT' - `n' - `K',`F') . #delimit ; delimiter now ; . dis in ye "The F test for all u_i=0 is : " %8.2f `F' _n > in ye "The P-value is: " %6.4f `p' ; The F test for all u_i=0 is : 113.76 The P-value is: 0.0000 . #delimit cr delimiter now cr . . * method2 : using the statistic given by stata's xtreg,fe command, . * which will give the same result as method1 . xtreg mvalue invest kstock , fe Fixed-effects (within) regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4117 Obs per group: min = 20 between = 0.8078 avg = 20.0 overall = 0.7388 max = 20 F(2,188) = 65.78 corr(u_i, Xb) = 0.6955 Prob > F = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 2.856166 .3075147 9.29 0.000 2.249543 3.462789 kstock | -.5078673 .1403662 -3.62 0.000 -.7847625 -.2309721 _cons | 804.9802 32.43177 24.82 0.000 741.0033 868.9571 -------------+---------------------------------------------------------------- sigma_u | 905.81517 sigma_e | 268.73329 rho | .91910377 (fraction of variance due to u_i) ------------------------------------------------------------------------------ F test that all u_i=0: F(9, 188) = 113.76 Prob > F = 0.0000 . . *--A5--* . // Hausman 检验 . //step1 estimate fixed-effect model and store the results . xtreg mvalue invest kstock , fe Fixed-effects (within) regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4117 Obs per group: min = 20 between = 0.8078 avg = 20.0 overall = 0.7388 max = 20 F(2,188) = 65.78 corr(u_i, Xb) = 0.6955 Prob > F = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 2.856166 .3075147 9.29 0.000 2.249543 3.462789 kstock | -.5078673 .1403662 -3.62 0.000 -.7847625 -.2309721 _cons | 804.9802 32.43177 24.82 0.000 741.0033 868.9571 -------------+---------------------------------------------------------------- sigma_u | 905.81517 sigma_e | 268.73329 rho | .91910377 (fraction of variance due to u_i) ------------------------------------------------------------------------------ F test that all u_i=0: F(9, 188) = 113.76 Prob > F = 0.0000 . est store fe . //step2 estimate random-effect model and store the results . xtreg mvalue invest kstock , re Random-effects GLS regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4115 Obs per group: min = 20 between = 0.8043 avg = 20.0 overall = 0.7371 max = 20 Random effects u_i ~ Gaussian Wald chi2(2) = 149.94 corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 3.113429 .3076132 10.12 0.000 2.510519 3.71634 kstock | -.578422 .1424721 -4.06 0.000 -.8576622 -.2991819 _cons | 786.9048 182.1715 4.32 0.000 429.8553 1143.954 -------------+---------------------------------------------------------------- sigma_u | 546.52144 sigma_e | 268.73329 rho | .80529268 (fraction of variance due to u_i) ------------------------------------------------------------------------------ . est store re . hausman fe ---- Coefficients ---- | (b) (B) (b-B) sqrt(diag(V_b-V_B)) | fe re Difference S.E. -------------+---------------------------------------------------------------- invest | 2.856166 3.113429 -.2572636 . kstock | -.5078673 -.578422 .0705548 . ------------------------------------------------------------------------------ b = consistent under Ho and Ha; obtained from xtreg B = inconsistent under Ha, efficient under Ho; obtained from xtreg Test: H difference in coefficients not systematic chi2(2) = (b-B)'[(V_b-V_B)^(-1)](b-B) = 2366.62 Prob>chi2 = 0.0000 . . *--A6--* . // Testing for random-effect using B-P test . xtreg mvalue invest kstock , re Random-effects GLS regression Number of obs = 200 Group variable (i): company Number of groups = 10 R-sq: within = 0.4115 Obs per group: min = 20 between = 0.8043 avg = 20.0 overall = 0.7371 max = 20 Random effects u_i ~ Gaussian Wald chi2(2) = 149.94 corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mvalue | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- invest | 3.113429 .3076132 10.12 0.000 2.510519 3.71634 kstock | -.578422 .1424721 -4.06 0.000 -.8576622 -.2991819 _cons | 786.9048 182.1715 4.32 0.000 429.8553 1143.954 -------------+---------------------------------------------------------------- sigma_u | 546.52144 sigma_e | 268.73329 rho | .80529268 (fraction of variance due to u_i) ------------------------------------------------------------------------------ . xttest0 Breusch and Pagan Lagrangian multiplier test for random effects: mvalue[company,t] = Xb + u[company] + e[company,t] Estimated results: | Var sd = sqrt(Var) ---------+----------------------------- mvalue | 1727831 1314.47 e | 72217.58 268.7333 u | 298685.7 546.5214 Test: Var(u) = 0 chi2(1) = 772.32 Prob > chi2 = 0.0000 . end of do-file . |