Raimundo Soto - Catholic University of Chile
ERF Training on Advanced Panel Data Techniques Applied to Economic Modelling
29 -31 October, 2018
Cairo, Egypt
2. RANDOM EFFECTS MODEL
• Consider the following true model
𝑦𝑖𝑡 = 𝛼𝑖 + 𝛽𝑥𝑖𝑡 + 𝜀𝑖𝑡
• So far, we assumed 𝛼𝑖 to be a fixed characteristic of
individuals.
• We now allow the individual effect to be the
realization of a random variable
2
3. RANDOM EFFECTS MODEL
• Why random?
• Several explanations (indeed, all are the same)
– The “fixed effect” depends on group composition
• There could be sub-groups within the group
– The observed “fixed effect” is a realization of a “latent”
characteristic variable and therefore the observed
behavior depends on this hidden process
• Example: farm produce and the quality of soil
3
5. RANDOM EFFECTS MODEL
• The model is:
𝑦𝑖𝑡 = 𝛼𝑖 + 𝛽𝑥𝑖𝑡 + 𝜀𝑖𝑡
𝛼𝑖 = 𝛼 + 𝜇𝑖
• Where 𝜇𝑖 is a random shock i.i.d.
• Now, there are two sources of uncertainty (𝜀𝑖𝑡 and
𝜇𝑖). A structure is therefore needed
5
6. RANDOM EFFECTS MODEL
• Assume:
• Non systematic shocks: 𝐸 𝜀𝑖𝑡 = 𝐸 𝜇𝑖 = 0
• Finite uncertainty:
𝑉 𝜀𝑖𝑡 = 𝜎𝜀
2
𝑉 𝜇𝑖 = 𝜎𝜇
2
• No cross information:
𝐸 𝜀𝑖𝑡, 𝜇𝑖 = 0
𝐸 𝜇𝑖, 𝜇 𝑗 = 0
𝐸 𝜀𝑖𝑡, 𝜀𝑗𝑡 = 0
• Key assumption in red
6
7. RANDOM EFFECTS MODEL
• The model is:
𝑦𝑖𝑡 = 𝛼 + 𝛽𝑥𝑖𝑡 + 𝜀𝑖𝑡 + 𝜇𝑖
𝑦𝑖𝑡 = 𝛼 + 𝛽𝑥𝑖𝑡 + 𝜔𝑖𝑡
• The error term 𝜔𝑖𝑡 is now heteroskedastic.
Consider the variance of the error term in group 1
7
8. RANDOM EFFECTS MODEL
• Consider the variance for all groups
• We now need an estimator of this variance to use
generalized least squares (GLS)
8
9. RANDOM EFFECTS MODEL
• Recall the GLS estimator trick: we want to
transform (weigh) the data so that the model
becomes homoskedastic
• Let T be the transformation:
𝑇𝑦𝑖𝑡 = 𝑇𝛼 + 𝛽𝑇𝑥𝑖𝑡 + 𝑇𝜔𝑖𝑡
• We thus want E 𝑇𝜔𝑖𝑡 ′ 𝑇𝜔𝑖𝑡 = 𝜎2
𝐼
9
10. RANDOM EFFECTS MODEL
• We want to find T so that E 𝑇𝜔𝑖𝑡 ′ 𝑇𝜔𝑖𝑡 = 𝜎2
𝐼
• Then 𝑇′Ω𝑇 = 𝐼
• Hence, Ω½ = 𝐼 −
𝜃
𝑇
𝑖𝑖′ where 𝜃 = 1 −
𝜎 𝜀
𝑇𝜎 𝜇
2
+𝜎 𝜀
2
• What does 𝐼 −
𝜃
𝑇
𝑖𝑖′ do?
• Magic! 𝐼 −
𝜃
𝑇
𝑖𝑖′ 𝑥 = 𝑥𝑖 − 𝜃 𝑥𝑖
10
11. RANDOM EFFECTS MODEL
• 𝐼 −
𝜃
𝑇
𝑖𝑖′ 𝑥 = 𝑥𝑖 − 𝜃 𝑥𝑖 y 𝜃 = 1 −
𝜎 𝜀
𝑇𝜎 𝜇
2
+𝜎 𝜀
2
• Note that when 𝜎𝜇
2
=0, 𝜃 = 0, there is only one fixed
effect and we are back to the pooled model
• Note that when T → ∞, 𝜃 = 1, there is one fixed effect
per group and we are to the fixed-effects model
• When 0 < 𝜃 < 1 we have a random-effects model
11
12. RANDOM EFFECTS MODEL
• The transformed models is
𝑦𝑖𝑡 − 𝜃 𝑦𝑖 = 𝑥𝑖𝑡 − 𝜃 𝑥𝑖 𝛽 + 𝛼 + 𝜀𝑖𝑡
• But, how do we estimate this model?
• We need 𝜃
• Indeed, we need 𝜃
• That is, we need 𝜎𝜀
2
and 𝜎𝜇
2
12
13. RANDOM EFFECTS MODEL
• But we already know how to do it!!
• We need the intra-group variance, use the fixed-effect
estimator to obtain 𝜎𝜀
2
• We need the inter-group variance which we do not have,
but we have the variance from the between groups
estimator
𝜎 𝜇
2
+𝜎 𝜀
2
𝑇
to obtain 𝜎𝜇
2
• The needed estimator is 𝜃 = 1 −
𝜎 𝜀
𝑇 𝜎 𝜇
2+ 𝜎 𝜀
2
13
14. RANDOM EFFECTS MODEL
• Note that
– This estimator is inconsistent when 𝐸 𝑥𝑖𝑡, 𝜇𝑖 ≠ 0
– This estimator is only asymptotically efficient, since Ω →
Ω only when 𝑁 → ∞ (even if T is fixed)
– Note the notable reduction in estimated parameters:
while in the fixed-effects model there are K constants to
estimate, in the random–effects models there is only 1
(besides 𝜎𝜇
2
)
14
15. RANDOM EFFECTS MODEL
15
rho .71183054 (fraction of variance due to u_i)
sigma_e .32607847
sigma_u .51249125
_cons -4.159675 .221007 -18.82 0.000 -4.592841 -3.72651
l_popt .0564086 .021553 2.62 0.009 .0141654 .0986517
l_infl2 -.0402788 .0050865 -7.92 0.000 -.0502482 -.0303094
l_realgdp .2575086 .0119961 21.47 0.000 .2339967 .2810204
l_money Coef. Std. Err. z P>|z| [95% Conf. Interval]
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
Wald chi2(3) = 1520.84
overall = 0.0028 max = 55
between = 0.0126 avg = 33.3
R-sq: within = 0.3236 Obs per group: min = 4
Group variable: idwbcode Number of groups = 163
Random-effects GLS regression Number of obs = 5436
16. RANDOM EFFECTS MODEL RESULTS
16
rho .71183054 (fraction of variance due to u_i)
sigma_e .32607847
sigma_u .51249125
_cons -4.159675 .221007 -18.82 0.000 -4.592841 -3.72651
l_popt .0564086 .021553 2.62 0.009 .0141654 .0986517
l_infl2 -.0402788 .0050865 -7.92 0.000 -.0502482 -.0303094
l_realgdp .2575086 .0119961 21.47 0.000 .2339967 .2810204
l_money Coef. Std. Err. z P>|z| [95% Conf. Interval]
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
Wald chi2(3) = 1520.84
overall = 0.0028 max = 55
between = 0.0126 avg = 33.3
R-sq: within = 0.3236 Obs per group: min = 4
Group variable: idwbcode Number of groups = 163
Random-effects GLS regression Number of obs = 5436
17. COMPARED RESULTS
17
* p<0.1, ** p<0.05, *** p<0.01
t statistics in parentheses
Observations 5436 5436 5436 5436
(39.10) (-31.67) (5.14) (-18.82)
Constant 3.315*** -7.845*** 2.450*** -4.160***
(0.24) (2.56) (0.30) (2.62)
Population 0.00144 0.0732** 0.00875 0.0564***
(-20.94) (-5.92) (-6.24) (-7.92)
Inflation -0.165*** -0.0281*** -0.406*** -0.0403***
(-2.36) (25.09) (-0.37) (21.47)
Real GDP -0.00867** 0.385*** -0.00630 0.258***
Pooled Within Between Random
(1) (2) (3) (4)
18. WHICH MODEL TO USE?
• Random effects or fixed effects?
• Fixed effects or pooled data?
• Recall
18
Fixed-effects
Estimator
Random-effects
Estimator
When 𝐸 𝑥𝑖𝑡, 𝜇𝑖 = 0 Consistent Consistent
Inefficient Efficient
When 𝐸 𝑥𝑖𝑡, 𝜇𝑖 ≠ 0 Consistent Inconsistent
Inefficient -
19. WHICH MODEL TO USE?
• Let us estimate the parameters using both estimators
𝛽 𝑅𝐸 and 𝛽 𝑉𝐸:
– if they are the same, choose 𝛽 𝑅𝐸 because it is consistent and
efficient
– if they are different, choose 𝛽 𝐹𝐸 because 𝛽 𝑅𝐸 is consistent
• Use a “t” type test
𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
𝑣𝑎𝑟 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
• It is easier to use a Wald test:
𝛽 𝑅𝐸− 𝛽 𝐹𝐸
2
𝑣𝑎𝑟 𝛽 𝑅𝐸− 𝛽 𝐹𝐸
• Let us study 𝑣𝑎𝑟 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
19
20. WHICH MODEL TO USE?
𝑣𝑎𝑟 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸 = 𝑣𝑎𝑟 𝛽 𝑅𝐸 + 𝑣𝑎𝑟 𝛽 𝐹𝐸 − 2𝑐𝑜𝑣 𝛽 𝑅𝐸, 𝛽 𝐹𝐸
• Key insight from Hausman and Wu:
– An efficient estimator is orthogonal to “its difference vis-a-vis
an inefficient estimator”
– Otherwise, you could have an even more efficient estimator
0=Cov[ 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸, 𝛽 𝑅𝐸]=Cov[ 𝛽 𝑅𝐸, 𝛽 𝐹𝐸] − Var[ 𝛽 𝑅𝐸]
• Hence
𝑣𝑎𝑟 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸 = 𝑣𝑎𝑟 𝛽 𝐹𝐸 − 𝑣𝑎𝑟 𝛽 𝑅𝐸
20
21. WHICH MODEL TO USE?
• Hence, the test is
𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
2
𝑣𝑎𝑟 𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
=
𝛽 𝑅𝐸 − 𝛽 𝐹𝐸
2
𝑣𝑎𝑟 𝛽 𝐹𝐸 − 𝑣𝑎𝑟 𝛽 𝑅𝐸
~𝜒2
(𝐾)
21
22. HAUSMAN-WU TEST RESULTS
22
(V_b-V_B is not positive definite)
Prob>chi2 = 0.0000
= 1298.59
chi2(3) = (b-B)'[(V_b-V_B)^(-1)](b-B)
Test: Ho: difference in coefficients not systematic
B = inconsistent under Ha, efficient under Ho; obtained from xtreg
b = consistent under Ho and Ha; obtained from xtreg
l_popt .0731808 .0564086 .0167722 .0186968
l_infl2 -.0281481 -.0402788 .0121307 .
l_realgdp .3846652 .2575086 .1271567 .009549
Within Random Difference S.E.
(b) (B) (b-B) sqrt(diag(V_b-V_B))
Coefficients
Random effects vs. Fixed effects
23. BREUSCH-PAGAN TEST
23
Prob > chibar2 = 0.0000
chibar2(01) = 30448.43
Test: Var(u) = 0
u .2626473 .5124913
e .1063272 .3260785
l_money .4515998 .6720118
Var sd = sqrt(Var)
Estimated results:
l_money[idwbcode,t] = Xb + u[idwbcode] + e[idwbcode,t]
Breusch and Pagan Lagrangian multiplier test for random effects
Random effects vs. No effects
24. WHICH MODEL TO USE?
• Fixed Effects or pooled estimator?
• Equivalent to test: 𝐻0: 𝛼𝑖 = 𝛼
• Careful with the alternative:
𝐻1: 𝛼𝑖 ≠ 𝛼 𝑓𝑜𝑟 𝑎𝑡 𝑙𝑒𝑎𝑡 𝑜𝑛𝑒 𝑔𝑟𝑜𝑢𝑝 "𝑖"
• Stata performs the test when using the Fixed –
effects estimator:
24
25. POOLABILITY TEST RESULTS
25
F test that all u_i=0: F(162, 5270) = 98.59 Prob > F = 0.0000
rho .95557807 (fraction of variance due to u_i)
sigma_e .32607847
sigma_u 1.5123647
_cons -7.844568 .2477214 -31.67 0.000 -8.330205 -7.358932
l_popt .0731808 .0285325 2.56 0.010 .0172453 .1291163
l_infl2 -.0281481 .004758 -5.92 0.000 -.0374757 -.0188204
l_realgdp .3846652 .0153326 25.09 0.000 .354607 .4147234
l_money Coef. Std. Err. t P>|t| [95% Conf. Interval]
corr(u_i, Xb) = -0.9200 Prob > F = 0.0000
F(3,5270) = 859.53
overall = 0.0036 max = 55
between = 0.0140 avg = 33.3
R-sq: within = 0.3285 Obs per group: min = 4
Group variable: idwbcode Number of groups = 163
Fixed-effects (within) regression Number of obs = 5436
Fixed effects vs. No effects