xtreg y x1 x2....,fe
estimates store fe
xtreg y x1 x2...., re
hausman fe
下面是我的一个例子 不过数据没法传上来 只能证明我的命令能用。
HAUSMAN TEST
. xtreg ltrade lrgdp lrgdppc ldist comlang border regional landl island lareap comcol curcol colony comctry
> custrict,fe
Fixed-effects (within) regression Number of obs = 219558
Group variable (i): pairid Number of groups = 11178
R-sq: within = 0.1174 Obs per group: min = 1
between = 0.2289 avg = 19.6
overall = 0.2236 max = 50
F(5,208375) = 5544.92
corr(u_i, Xb) = 0.1438 Prob > F = 0.0000
------------------------------------------------------------------------------
ltrade | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lrgdp | .0479512 .0087746 5.46 0.000 .0307531 .0651493
lrgdppc | .7909501 .0140174 56.43 0.000 .7634762 .8184239
ldist | (dropped)
comlang | (dropped)
border | (dropped)
regional | .692351 .0450073 15.38 0.000 .6041379 .7805642
landl | (dropped)
island | (dropped)
lareap | (dropped)
comcol | (dropped)
curcol | .358431 .0881309 4.07 0.000 .1856965 .5311654
colony | (dropped)
comctry | (dropped)
custrict | .6512318 .050578 12.88 0.000 .5521001 .7503634
_cons | -4.956948 .2282823 -21.71 0.000 -5.404376 -4.50952
-------------+----------------------------------------------------------------
sigma_u | 3.3401212
sigma_e | 1.3220505
rho | .86455466 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(11177, 208375) = 34.50 Prob > F = 0.0000
. estimates store fe
. xtreg ltrade lrgdp lrgdppc ldist comlang border regional landl island lareap comcol curcol colony comctry
> custrict, re
Random-effects GLS regression Number of obs = 219558
Group variable (i): pairid Number of groups = 11178
R-sq: within = 0.1152 Obs per group: min = 1
between = 0.5207 avg = 19.6
overall = 0.4656 max = 50
Random effects u_i ~ Gaussian Wald chi2(14) = 40688.72
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
------------------------------------------------------------------------------
ltrade | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lrgdp | .2694305 .0072176 37.33 0.000 .2552843 .2835767
lrgdppc | .5252985 .011516 45.61 0.000 .5027275 .5478695
ldist | -1.345633 .0314899 -42.73 0.000 -1.407352 -1.283914
comlang | .1760738 .0619909 2.84 0.005 .0545739 .2975736
border | .5309711 .1644242 3.23 0.001 .2087057 .8532366
regional | .6610592 .0448452 14.74 0.000 .5731643 .7489541
landl | -.8566298 .0425414 -20.14 0.000 -.9400094 -.7732501
island | -.0574684 .0517478 -1.11 0.267 -.1588923 .0439555
lareap | .2560334 .0091301 28.04 0.000 .2381387 .2739281
comcol | -.2770005 .0791023 -3.50 0.000 -.4320381 -.1219628
curcol | .4283967 .0887594 4.83 0.000 .2544316 .6023619
colony | 3.208207 .2055153 15.61 0.000 2.805404 3.61101
comctry | 1.272358 1.593654 0.80 0.425 -1.851146 4.395863
custrict | .700997 .0500125 14.02 0.000 .6029744 .7990196
_cons | -7.236036 .3224152 -22.44 0.000 -7.867958 -6.604114
-------------+----------------------------------------------------------------
sigma_u | 2.1970043
sigma_e | 1.3220536
rho | .73415697 (fraction of variance due to u_i)
------------------------------------------------------------------------------
. hausman fe
---- Coefficients ----
| (b) (B) (b-B) sqrt(diag(V_b-V_B))
| fe . Difference S.E.
-------------+----------------------------------------------------------------
lrgdp | .0479512 .2694305 -.2214793 .0049901
lrgdppc | .7909501 .5252985 .2656516 .0079919
regional | .692351 .6610592 .0312918 .0038165
curcol | .358431 .4283967 -.0699658 .
custrict | .6512318 .700997 -.0497653 .0075425
------------------------------------------------------------------------------
b = consistent under Ho and Ha; obtained from xtreg
B = inconsistent under Ha, efficient under Ho; obtained from xtreg
Test: Ho: difference in coefficients not systematic
chi2(5) = (b-B)'[(V_b-V_B)^(-1)](b-B)
= 6418.73
Prob>chi2 = 0.0000
(V_b-V_B is not positive definite)