Panel Data Analysis Using Stata: Sebastian T. Braun University of ST Andrews
Panel Data Analysis Using Stata: Sebastian T. Braun University of ST Andrews
Sebastian T. Braun
University of St Andrews
Course Outline 1-1
Course Objectives
Panel Data
Course Outline 1-2
Recommended Readings
Panel Data
Course Outline 1-3
Course Material
Panel Data
Overview 2-1
Overview
1. Course Outline X
2. Introduction
3. Panel Data Management
4. Regression Analysis
5. Hypothesis Testing
6. Extensions
7. Outlook: Advanced Panel Data Analysis
Panel Data
Introduction 3-1
Panel Data
Introduction 3-2
Panel Data
Introduction 3-3
Panel Data
Panel Data Management 4-1
Getting Started...
Panel Data
Panel Data Management 4-2
The Dataset
Panel Data
Panel Data Management 4-3
. describe
Panel Data
Panel Data Management 4-4
Panel Data
Panel Data Management 4-5
Panel Data
Panel Data Management 4-7
Panel Data
Regression analysis 5-1
Panel Data
Regression analysis 5-2
Panel Data
Regression analysis 5-3
Panel Data
Regression analysis 5-4
Panel Data
Regression analysis 5-5
Pooled OLS
Panel Data
Regression analysis 5-6
------------------------------------------------------------------------------
lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .0384824 .002442 15.76 0.000 .0336945 .0432703
exp2 | -.0006084 .0000539 -11.29 0.000 -.000714 -.0005027
wks | .0047247 .0012331 3.83 0.000 .0023071 .0071422
ed | .0635993 .0028509 22.31 0.000 .0580098 .0691887
union | .1204051 .0138341 8.70 0.000 .0932818 .1475284
ind | .0431938 .0126986 3.40 0.001 .0182968 .0680908
occ | -.150339 .016286 -9.23 0.000 -.1822695 -.1184086
_cons | 5.24959 .0780379 67.27 0.000 5.096589 5.402592
------------------------------------------------------------------------------
Panel Data
Regression analysis 5-7
Panel Data
Regression analysis 5-8
Panel Data
Regression analysis 5-9
.
. * Autocorrelations of residual
. quietly regress lwage exp exp2 wks ed union ind occ
| L.
| uhat uhat
-------------+------------------
uhat |
--. | 1.0000
L1. | 0.8599 1.0000
Panel Data
Regression analysis 5-10
Panel Data
Regression analysis 5-11
Panel Data
Regression analysis 5-12
Panel Data
Regression analysis 5-13
Panel Data
Regression analysis 5-14
Panel Data
Regression analysis 5-15
Panel Data
Regression analysis 5-16
yi = α + x i β + ai + i , (10)
Panel Data
Regression analysis 5-17
Now subtract equation (10) from (9) to get rid of the fixed effect:
Panel Data
Regression analysis 5-18
Panel Data
Regression analysis 5-19
F(6,3162) = 1004.25
corr(u_i, Xb) = -0.9223 Prob > F = 0.0000
------------------------------------------------------------------------------
lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .1149389 .0026801 42.89 0.000 .1096841 .1201938
exp2 | -.0004347 .0000584 -7.44 0.000 -.0005491 -.0003202
wks | .0004693 .0006576 0.71 0.476 -.0008201 .0017587
ed | (omitted)
union | .0316998 .0159769 1.98 0.047 .0003736 .063026
ind | .0182395 .0160431 1.14 0.256 -.0132165 .0496954
occ | -.0113013 .0146455 -0.77 0.440 -.0400169 .0174144
_cons | 4.600501 .044283 103.89 0.000 4.513675 4.687328
-------------+----------------------------------------------------------------
sigma_u | 1.047369
sigma_e | .1534777
rho | .97897847 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(527, 3162) = 33.82 Prob > F = 0.0000
Panel Data
Regression analysis 5-20
Panel Data
Regression analysis 5-21
60
A
50
40
30
20
B
10
B A
0
-5 0 5 10 15 20
Panel Data
Regression analysis 5-22
2 1 XX
Within: sW = (xit − x i )2 , (13)
NT − 1 i t
1 X
Between: sB2 = (xi − x )2 , (14)
N −1 i
1 XX
Overall: sO2 = (xit − x )2 . (15)
NT − 1 i t
Panel Data
Regression analysis 5-24
xttrans union
if wage |
set be a | if wage set be a
union | union contract
contract | 0 1 | Total
-----------+----------------------+----------
0 | 1,890 66 | 1,956
| 96.63 3.37 | 100.00
-----------+----------------------+----------
1 | 63 1,149 | 1,212
| 5.20 94.80 | 100.00
-----------+----------------------+----------
Total | 1,953 1,215 | 3,168
| 61.65 38.35 | 100.00
Panel Data
Regression analysis 5-25
xttrans ed
. * Transition probabilities for a variable
. xttrans ed if ed>=12, freq
Panel Data
Regression analysis 5-26
Panel Data
Regression analysis 5-27
There are two other estimators that also allow the unobserved
fixed-effect to be correlated with the regressors:
Both estimators are also widely used in practice but share the
caveats of the fixed effects estimator.
Panel Data
Regression analysis 5-28
Panel Data
Regression analysis 5-29
Panel Data
Regression analysis 5-30
------------------------------------------------------------------------------
lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .1149389 .0026801 42.89 0.000 .1096841 .1201938
exp2 | -.0004347 .0000584 -7.44 0.000 -.0005491 -.0003202
wks | .0004693 .0006576 0.71 0.476 -.0008201 .0017587
ed | (omitted)
union | .0316998 .0159769 1.98 0.047 .0003736 .063026
ind | .0182395 .0160431 1.14 0.256 -.0132165 .0496954
occ | -.0113013 .0146455 -0.77 0.440 -.0400169 .0174144
_cons | 4.600501 .044283 103.89 0.000 4.513675 4.687328
-------------+----------------------------------------------------------------
id | F(527, 3162) = 39.191 0.000 (528 categories)
Panel Data
Regression analysis 5-31
First-difference Estimator
Panel Data
Regression analysis 5-32
Panel Data
Regression analysis 5-33
Now use Stata to re-estimate the union wage premium using the
model in first differences:
Panel Data
Regression analysis 5-34
. * First-differences estimator
. regress D.(lwage exp exp2 wks ed union ind occ), noconstant
note: _delete omitted because of collinearity
------------------------------------------------------------------------------
D.lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp |
D1. | .1192783 .006853 17.41 0.000 .1058416 .1327151
|
exp2 |
D1. | -.0005583 .0001491 -3.75 0.000 -.0008506 -.000266
|
wks |
D1. | -.0003622 .0006187 -0.59 0.558 -.0015752 .0008508
|
ed |
D1. | (omitted)
|
union |
D1. | .0162718 .0162282 1.00 0.316 -.0155471 .0480907
|
ind |
D1. | .0144281 .0168265 0.86 0.391 -.0185639 .0474201
|
occ |
D1. | -.0158051 .0147561 -1.07 0.284 -.0447376 .0131274
------------------------------------------------------------------------------
Panel Data
Regression analysis 5-35
Panel Data
Regression analysis 5-36
Panel Data
Regression analysis 5-37
Panel Data
Regression analysis 5-38
Panel Data
Regression analysis 5-39
Panel Data
Regression analysis 5-40
Panel Data
Regression analysis 5-41
Panel Data
Regression analysis 5-42
Panel Data
Regression analysis 5-43
------------------------------------------------------------------------------
lwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .0825226 .0030822 26.77 0.000 .0764816 .0885636
exp2 | -.0007411 .0000676 -10.96 0.000 -.0008737 -.0006086
wks | .0006109 .0008368 0.73 0.465 -.0010292 .002251
ed | .1057496 .0062768 16.85 0.000 .0934474 .1180518
union | .0646388 .0181938 3.55 0.000 .0289796 .100298
ind | .0013936 .0179769 0.08 0.938 -.0338405 .0366276
occ | -.0348985 .0176442 -1.98 0.048 -.0694806 -.0003165
_cons | 4.059829 .1030828 39.38 0.000 3.857791 4.261868
-------------+----------------------------------------------------------------
sigma_u | .28526616
sigma_e | .1534777
rho | .77551783 (fraction of variance due to u_i)
------------------------------------------------------------------------------
Panel Data
Regression analysis 5-44
For the RE model, the estimated θ̂i can be obtained using the
theta option.
Panel Data
Regression analysis 5-45
Comparison of Estimates
Panel Data
. quietly xtreg lwage $xlist, fe
. estimates store FE
Regression analysis 5-46
. quietly xtreg lwage $xlist, re
. estimates store RE
Comparison of Estimates (ctd.)
. estimates table OLS_rob FE RE, ///
> b se stats(N r2 r2_o r2_b r2_w) b(%7.4f)
--------------------------------------------------
Variable | OLS_rob FE RE
-------------+------------------------------------
exp | 0.0415 0.1135 0.0869
| 0.0050 0.0025 0.0028
exp2 | -0.0007 -0.0004 -0.0008
| 0.0001 0.0001 0.0001
wks | 0.0076 0.0008 0.0010
| 0.0018 0.0006 0.0008
ed | 0.0704 (omitted) 0.1086
| 0.0060 0.0062
union | 0.1517 0.0321 0.0615
| 0.0275 0.0149 0.0170
ind | 0.0966 0.0182 0.0124
| 0.0259 0.0155 0.0172
occ | -0.1447 -0.0214 -0.0411
| 0.0318 0.0137 0.0164
_cons | 4.9149 4.5930 3.9015
| 0.1413 0.0400 0.0983
-------------+------------------------------------
N | 4165 4165 4165
r2 | 0.3205 0.6574
r2_o | 0.0491 0.1933
r2_b | 0.0289 0.1833
r2_w | 0.6574 0.6287
--------------------------------------------------
legend: b/se
Panel Data
Hypothesis Testing 6-1
Hypothesis Testing
Panel Data
Hypothesis Testing 6-2
Panel Data
Hypothesis Testing 6-3
F(6,3162) = 1004.25
corr(u_i, Xb) = -0.9223 Prob > F = 0.0000
------------------------------------------------------------------------------
lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .1149389 .0026801 42.89 0.000 .1096841 .1201938
exp2 | -.0004347 .0000584 -7.44 0.000 -.0005491 -.0003202
wks | .0004693 .0006576 0.71 0.476 -.0008201 .0017587
ed | (omitted)
union | .0316998 .0159769 1.98 0.047 .0003736 .063026
ind | .0182395 .0160431 1.14 0.256 -.0132165 .0496954
occ | -.0113013 .0146455 -0.77 0.440 -.0400169 .0174144
_cons | 4.600501 .044283 103.89 0.000 4.513675 4.687328
-------------+----------------------------------------------------------------
sigma_u | 1.047369
sigma_e | .1534777
rho | .97897847 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(527, 3162) = 33.82 Prob > F = 0.0000
Panel Data
Hypothesis Testing 6-4
Panel Data
Hypothesis Testing 6-5
The Hausman test uses the fact that both estimators are
consistent under the null hypothesis of no correlation.
Under the null hypothesis, the two estimates of β should thus
not differ systematically.
We can implement the test in Stata using hausman.
For the technical details of the test, you may consult Greene
(2008).
Panel Data
Hypothesis Testing 6-6
chi2(6) = (b-B)'[(V_b-V_B)^(-1)](b-B)
= 1578.13
Prob>chi2 = 0.0000
Panel Data
Hypothesis Testing 6-7
Panel Data
Extensions 7-1
The time effects λt shift the intercept over time and affect all
micro-units uniformly.
Examples: business cycle movements, common trend in
wages...
In short panels, we usually include a full set of time dummies
among the xit ’s.
Panel Data
Extensions 7-2
Panel Data
Extensions 7-3
F(11,3559) = 629.58
corr(u_i, Xb) = -0.9089 Prob > F = 0.0000
------------------------------------------------------------------------------
lwage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .1117254 .0026174 42.69 0.000 .1065936 .1168571
exp2 | -.000401 .0000546 -7.35 0.000 -.000508 -.000294
wks | .0006692 .0005994 1.12 0.264 -.000506 .0018444
ed | (omitted)
union | .0288605 .0148838 1.94 0.053 -.0003212 .0580422
ind | .0198261 .0154044 1.29 0.198 -.0103763 .0500285
occ | -.0193217 .0137094 -1.41 0.159 -.0462008 .0075574
|
t |
2 | -.0081074 .0081694 -0.99 0.321 -.0241246 .0079098
3 | .0258101 .0077694 3.32 0.001 .0105772 .041043
4 | .0286159 .0076429 3.74 0.000 .013631 .0436009
5 | .0235754 .0077717 3.03 0.002 .0083381 .0388128
6 | .007083 .0081633 0.87 0.386 -.0089221 .0230881
7 | (omitted)
|
_cons | 4.613659 .0431638 106.89 0.000 4.52903 4.698287
-------------+----------------------------------------------------------------
sigma_u | 1.0261585
sigma_e | .15150311
rho | .97866713 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(594, 3559) = 29.82 Prob > F = 0.0000
Panel Data
Extensions 7-4
------------------------------------------------------------------------------
lwage | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
exp | .0289861 .0025233 11.49 0.000 .0240404 .0339317
exp2 | -.0004355 .00005 -8.72 0.000 -.0005334 -.0003375
wks | .0009599 .0005954 1.61 0.107 -.0002072 .0021269
ed | .0735711 .0049521 14.86 0.000 .0638651 .0832771
union | .0500422 .0134164 3.73 0.000 .0237465 .0763379
ind | .0409469 .0136322 3.00 0.003 .0142283 .0676656
occ | -.0339167 .0129552 -2.62 0.009 -.0593084 -.0085249
|
t |
2 | .0756715 .0089433 8.46 0.000 .058143 .0931999
3 | .1931833 .0092131 20.97 0.000 .175126 .2112406
4 | .279892 .0096431 29.03 0.000 .260992 .2987921
5 | .3588786 .0101782 35.26 0.000 .3389297 .3788275
6 | .4269871 .0108193 39.47 0.000 .4057817 .4481926
7 | .5040351 .0115335 43.70 0.000 .4814297 .5266404
|
_cons | 5.055152 .0812668 62.20 0.000 4.895871 5.214432
-------------+----------------------------------------------------------------
sigma_u | .30410708
sigma_e | .15150311
rho | .80115798 (fraction of variance due to u_i)
------------------------------------------------------------------------------
Panel Data
Outlook: Advanced Panel Data Analysis 8-1
Two major topics in applied panel data analysis were not covered:
1. Panel IV estimation
2. Dynamic panel estimation
Panel Data
Outlook: Advanced Panel Data Analysis 8-2
Panel IV estimation
Panel Data
Outlook: Advanced Panel Data Analysis 8-3
Panel Data
Outlook: Advanced Panel Data Analysis 8-4
Panel Data
Outlook: Advanced Panel Data Analysis 8-5
. xtdescribe
Panel Data
Outlook: Advanced Panel Data Analysis 8-6
FE Estimates
. use "G:\Lhre\Panel Data\Wooldridge\scrap.dta", clear
F(1,44) = 5.96
corr(u_i, Xb) = 0.0294 Prob > F = 0.0187
------------------------------------------------------------------------------
lscrap | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
hrsemp | -.0097174 .0039812 -2.44 0.019 -.017741 -.0016937
_cons | .6737459 .064658 10.42 0.000 .5434363 .8040555
-------------+----------------------------------------------------------------
sigma_u | 1.4400308
sigma_e | .43425379
rho | .91664268 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(46, 44) = 20.80 Prob > F = 0.0000
Panel Data
Outlook: Advanced Panel Data Analysis 8-7
Panel Data
Outlook: Advanced Panel Data Analysis 8-8
The IV Idea
z x y
Panel Data
Outlook: Advanced Panel Data Analysis 8-9
Panel Data
Outlook: Advanced Panel Data Analysis 8-10
F(1,44) = 41.21
corr(u_i, Xb) = -0.0875 Prob > F = 0.0000
------------------------------------------------------------------------------
hrsemp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
grant | 26.01751 4.053008 6.42 0.000 17.84921 34.18581
_cons | 6.787258 1.441732 4.71 0.000 3.881638 9.692877
-------------+----------------------------------------------------------------
sigma_u | 14.822833
sigma_e | 11.816449
rho | .61143602 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(46, 44) = 3.11 Prob > F = 0.0001
Panel Data
Outlook: Advanced Panel Data Analysis 8-11
------------------------------------------------------------------------------
lscrap | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
hrsemp | -.0154088 .0058563 -2.63 0.009 -.026887 -.0039306
_cons | .7397372 .0821938 9.00 0.000 .5786403 .9008341
-------------+----------------------------------------------------------------
sigma_u | 1.4405516
sigma_e | .44422418
rho | .91316478 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(46,44) = 19.87 Prob > F = 0.0000
------------------------------------------------------------------------------
Instrumented: hrsemp
Instruments: grant
------------------------------------------------------------------------------
Panel Data
Outlook: Advanced Panel Data Analysis 8-12
Panel Data
Outlook: Advanced Panel Data Analysis 8-13
Panel Data
Outlook: Advanced Panel Data Analysis 8-14
Panel Data
Appendix 9-1
Panel Data
Appendix 9-2
Panel Data
Appendix 9-3
Panel Data
Appendix 9-4
Panel Data