|
|
|
||||
|
|
|||||
The design is a mixed model with both within-subject and and between-subject factors. The within-subject factor (b) has four levels and the between-subject factor (a) has two levels. To keep the analysis simple we will not consider the a*b interaction.
----------------------------------
s | b1 b2 b3 b4
----------+-----------------------
a1 |
1 | 3 4 7 7
2 | 6 5 8 8
3 | 3 4 7 9
4 | 3 3 6 8
----------+-----------------------
a2 |
5 | 1 2 5 10
6 | 2 3 6 10
7 | 2 4 5 9
8 | 2 3 6 11
----------------------------------
We will begin by looking at the within-subject factor using xtreg-fe. The fe
option stands for fixed-effects which is really the same thing as within-subjects.
Notice that there are coefficients only for the within-subjects (fixed-effects) variables.
Following
the xtreg we will use the test command to obtain the three degree of freedom
test of the levels of b.
use http://www.ats.ucla.edu/stat/stata/faq/spf24
xi: xtreg y i.a i.b, i(s) fe
i.a _Ia_1-2 (naturally coded; _Ia_1 omitted)
i.b _Ib_1-4 (naturally coded; _Ib_1 omitted)
Fixed-effects (within) regression Number of obs = 32
Group variable (i): s Number of groups = 8
R-sq: within = 0.8722 Obs per group: min = 4
between = . avg = 4.0
overall = 0.8259 max = 4
F(3,21) = 47.77
corr(u_i, Xb) = 0.0000 Prob > F = 0.0000
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_2 | (dropped)
_Ib_2 | .75 .5824824 1.29 0.212 -.4613384 1.961338
_Ib_3 | 3.5 .5824824 6.01 0.000 2.288662 4.711338
_Ib_4 | 6.25 .5824824 10.73 0.000 5.038662 7.461338
_cons | 2.75 .4118772 6.68 0.000 1.893454 3.606546
-------------+----------------------------------------------------------------
sigma_u | .6681531
sigma_e | 1.1649647
rho | .24752475 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(7, 21) = 0.99 Prob > F = 0.4669
test _Ib_2 _Ib_3 _Ib_4
( 1) _Ib_2 = 0
( 2) _Ib_3 = 0
( 3) _Ib_4 = 0
F( 3, 21) = 47.77
Prob > F = 0.0000
Next, we will use the be option to look at the between-subject effect. This time notice
that only the coefficient for a is given as it represents the between-subjects
effect.
xi: xtreg y i.a i.b, i(s) be
i.a _Ia_1-2 (naturally coded; _Ia_1 omitted)
i.b _Ib_1-4 (naturally coded; _Ib_1 omitted)
Between regression (regression on group means) Number of obs = 32
Group variable (i): s Number of groups = 8
R-sq: within = . Obs per group: min = 4
between = 0.2500 avg = 4.0
overall = 0.0133 max = 4
F(1,6) = 2.00
sd(u_i + avg(e_i.))= .625 Prob > F = 0.2070
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_2 | -.625 .4419417 -1.41 0.207 -1.706392 .4563925
_Ib_2 | (dropped)
_Ib_3 | (dropped)
_Ib_4 | (dropped)
_cons | 5.6875 .3125 18.20 0.000 4.92284 6.45216
------------------------------------------------------------------------------
test _Ia_2
( 1) _Ia_2 = 0
F( 1, 6) = 2.00
Prob > F = 0.2070
Now it is time to get both the within and between with a single xtreg-re command. Notice
that there are now estimates for both a and b. Since the xtreg-re
test command gives us a chi-square and not an F-ratio, we have to rescale the chi-square by
dividing by the degrees of freedom. The coefficients and test for the re model
are the same as the coefficients and test from the separate fe and be
models.
xi: xtreg y i.a i.b, i(s) re
i.a _Ia_1-2 (naturally coded; _Ia_1 omitted)
i.b _Ib_1-4 (naturally coded; _Ib_1 omitted)
Random-effects GLS regression Number of obs = 32
Group variable (i): s Number of groups = 8
R-sq: within = 0.8722 Obs per group: min = 4
between = 0.2500 avg = 4.0
overall = 0.8392 max = 4
Random effects u_i ~ Gaussian Wald chi2(4) = 145.32
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Ia_2 | -.625 .4419417 -1.41 0.157 -1.49119 .2411899
_Ib_2 | .75 .5824824 1.29 0.198 -.3916445 1.891644
_Ib_3 | 3.5 .5824824 6.01 0.000 2.358356 4.641644
_Ib_4 | 6.25 .5824824 10.73 0.000 5.108356 7.391644
_cons | 3.0625 .474224 6.46 0.000 2.133038 3.991962
-------------+----------------------------------------------------------------
sigma_u | .22658174
sigma_e | 1.1649647
rho | .03645008 (fraction of variance due to u_i)
------------------------------------------------------------------------------
test _Ia_2
( 1) _Ia_2 = 0
chi2( 1) = 2.00
Prob > chi2 = 0.1573
test _Ib_2 _Ib_3 _Ib_4
( 1) _Ib_2 = 0
( 2) _Ib_3 = 0
( 3) _Ib_4 = 0
chi2( 3) = 143.32
Prob > chi2 = 0.0000
/* convert chi-square to F */
display "F = " r(chi2)/r(df)
F = 47.77193
Stata's xtreg random effects model is just a matrix weighted average of the fixed-effects
(within) and the between-effects. In our example, because the within- and between-effects are orthogonal,
thus the re produces the same results as the individual fe and be. With more
general panel datasets the results of the fe and be won't necessarily add up in
the same manner.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services