Panel Data Analysis
Panel Data Analysis
Winter 2022
Two-Period Panel Data Analysis
Where;
i denotes the person, firm, city- entity
t denotes the time period
𝑑2𝑡 does not change across i.
𝛼𝑖 captures all unobserved, time constant factors that affect 𝒀𝒊𝒕 - fixed effect;
unobserved heterogeneity ( individual, city or state heterogeneity)
2
Crime Rates and Unemployment
A simple unobserved effects model for city crime rates for 1985 and 1987 is:
𝑪𝒓𝒊𝒎𝒆𝒊𝒕 = 𝜷𝟎 + 𝜹𝟎 𝒅𝟖𝟕𝒕 + 𝜷𝟏 𝒖𝒏𝒆𝒎𝒊𝒕 + 𝜶𝒊 + 𝝁𝒊𝒕 ,
Where:
𝑑87𝑡 = dummy variable for 1987; 2 time periods
i= cities
𝛼𝑖 = unobserved city effect or a city fixed effect- it represents all factors affecting
crime rates that do not change over time or remains constant over the span of
two-years (1985-1987)
These factors include:
i. Geographical features ( city’s location)
ii. Demographic features ( age, race, education)
iii. Different cities may have their own methods for reporting crimes
iv. People living in the cities might have different attitudes toward crime-
typically slow to change
v. For historical reasons, cities can have very different crime rates
3
Crime Rates and Unemployment
A simple unobserved effects model for city crime rates for 1985 and 1987 is:
If the above equation is estimated using a Pooled OLS it will lead to biased
estimators!
4
Unobserved Fixed Effects
• Here we have added a time-constant component to the
error, vit = αi + μit
5
First Differences with Two Time
Periods (T=2)
𝒀𝒊𝒕 = 𝜷𝟎 + 𝜹𝟎 𝒅𝟐𝒕 + 𝜷𝟏 𝒙𝒊𝒕 + 𝜶𝒊 + 𝝁𝒊𝒕 , 𝒕 = 𝟏, 𝟐
For a cross-sectional observation i, write the two years as:
𝒀𝒊𝟐 = (𝜷𝟎 +𝜹𝟎 ) + 𝜷𝟏 𝒙𝒊𝟐 + 𝜶𝒊 + 𝝁𝒊𝟐 , (t=2)
𝒀𝒊𝟏 = 𝜷𝟎 + 𝜷𝟏 𝒙𝒊𝟏 + 𝜶𝒊 + 𝝁𝒊𝟏 , (t=1)
If we subtract the second equation from the first, we obtain
(𝒀𝒊𝟐 −𝒀𝒊𝟏 ) = 𝜹𝟎 + 𝜷𝟏 (𝒙𝒊𝟐 −𝒙𝒊𝟏 ) + (𝝁𝒊𝟐 −𝝁𝒊𝟏 )
∆𝒀𝒊 = 𝜹𝟎 + 𝜷𝟏 ∆𝒙𝒊 + ∆𝝁𝒊
Where
∆ denotes the change from t=1 to t=2.
𝜶𝒊 has been differenced away.
𝜹𝟎 is the change in intercept from t=1 to t=2.
First-differenced equation is just a single cross-sectional equation where
each variable is differenced over time 6
Example-First Differences with Two
Time Periods (T=2)
Cross-Sectional Time (t) crimeit unempit ∆𝒄𝒓𝒊𝒎𝒆𝒊 ∆𝒖𝒏𝒆𝒎𝒑𝒊
Unit (i)
City A 2018 10 10 - -
7
First Differences with Two Time
Periods (T=2)
• We can subtract one period from the other, to obtain
• Dyi = d0 + b1Dxi1 +…+ bkDxik + Dui
• This model has no correlation between the x’s and the error term,
so no bias
• ∆𝑥𝑖 must have some variation across i.
– This can fail if the independent variable does not change over
time for any cross-sectional unit or it changes by the same
amount for every observation.
– As it can get difficult to then separate the effect of 𝛼𝑖 on 𝑌𝑖𝑡
from the effect of any variable that does not change over time.
• Need to be careful about organization of the data to be sure
compute correct change (data needs to be present in the wide format)
8
Differencing with Multiple Periods
(T>2)
• Can extend this method to more periods
• Simply difference adjacent periods
• So if 3 periods, then subtract period 1 from
period 2, period 2 from period 3 and have 2
observations per individual
• Simply estimate by OLS, assuming the Duit are
uncorrelated over time
9
Disadvantages of Differencing
• Differencing can greatly reduce the variation in the
explanatory variables.
• While 𝑥𝑖𝑡 might have substantial variation in the cross
section for each t but ∆𝑥𝑖 may not have much variation.
– Little variation in ∆𝑥𝑖 can lead to large standard
errors for the estimated slope coefficients.
• In order to avoid this, longer differences over time can
be better than year-to-year changes.
10
Fixed Effects Estimation
An alternative method for eliminating an unobserved fixed effect
(𝜶𝒊 ) is the fixed effects transformation.
For each i:
𝒀𝒊𝒕 = 𝜷𝟏 𝒙𝒊𝒕 + 𝜶𝒊 + 𝝁𝒊𝒕 , 𝒕 = 𝟏, 𝟐, … . 𝑻
11
Understanding the Procedure of the FE Estimator
Now, the error term uit is white noise. Hence, the FE estimator is
unbiased.
12
Fixed Effects Estimation
𝑌𝑖𝑡 = 𝛽1 𝑥𝑖𝑡 + 𝛼𝑖 + 𝜇𝑖𝑡 , 𝑡 = 1,2
For each i, average this equation over time
ഥ𝑖 = 𝛽1 𝑥ഥ𝑖 + 𝛼𝑖 + 𝜇ഥ𝑖
𝑌
For each t, we end with time-demeaned data:
15
Fixed Effects Estimation (cont)
• If we were to do this estimation by hand, we’d
need to be careful because we’d think that df =
NT – k, but really is N(T – 1) – k because we
used up dfs calculating means
• Luckily, Stata (and most other packages) will
do fixed effects estimation for you
• This method is also identical to including a
separate intercept for every individual
16
First Differences vs Fixed Effects
• First Differences and Fixed Effects will be
exactly the same when T = 2
• For T > 2, the two methods are different
• Probably see fixed effects estimation more
often than differences – probably more because
it’s easier than that it’s better
• Fixed effects easily implemented for
unbalanced panels, not just balanced panels
17
Using Group Dummies
City A 2018 10 10 0 0
2020 15 11 0 0
City B 2018 18 12 1 0
2020 25 14 1 0
City C 2018 20 12 0 1
2020 25 13 0 1
20
Fixed Effects Estimation
21
Fixed Effects Estimation
22
Fixed Effects Estimation
23
Example of Panel Data
24
Example of Panel Data
25
Balanced vs. unbalanced panel
26
Pooled cross-section
27
Possible assumptions for intercepts and
slope coefficients
28
1.Coefficients constant across time and
individuals
29
2.Slope constant but intercept varies
across individuals
30
2.Fixed effects model
31
2.Fixed effects model
32
What if we know there are differences
between firms?
33
2.Least squares dummy variable
34
2.Results of fixed effects/LSDV model
35
2.Fixed effects model
36
3. Slope constant but intercept varies
across time and individual
37
4. All coefficients vary across
individuals
38
Problems with using fixed effects/LSDV
model
39
Problems with using fixed effects/
/LSDV model
40
Random Effects Model
𝑡 ≠s
41
Random Effects Model
Individual Time Period 𝒗𝒊𝒕
1 1 𝛼1 + 𝜇11
1 2 𝛼1 + 𝜇12
2 1 𝛼2 + 𝜇21
2 2 𝛼2 + 𝜇22
3 1 𝛼3 + 𝜇31
3 2 𝛼3 + 𝜇32
42
Random Effects Model
• Start with the same basic model with a composite error, yit
= b0 + b1xit1 + . . . bkxitk + ai + uit
• Previously we’ve assumed that ai was correlated with the x’s,
but what if it’s not?
• OLS would be consistent in that case, but composite error
will be serially correlated.
𝐶𝑜𝑣 𝑉𝑖𝑡 , 𝑉𝑖𝑠 ≠ 0
𝐶𝑜𝑣 𝑉𝑖𝑡 , 𝑉𝑖𝑠 = 𝐶𝑜𝑣(ai + ui𝑡 ,ai + uis ) = 𝑣𝑎𝑟(ai)=𝜎𝑎2 > 0
43
Random Effects Model
• Need to transform the model and do GLS to
solve the problem and make correct inferences
• Idea is to do quasi-differencing
44
Random Effects Model
= 1 − ( + T )
2
u
2
u
2 12
a
𝒗𝒊𝒕 − 𝝀ഥ
𝒗𝒊 = 𝟏 − 𝝀 𝜶𝒊 + (𝒖𝒊𝒕 −𝝀ഥ 𝒖𝒊𝒕 )
Errors in the transformed equation used in random effects
estimation weight the unobserved effect by 𝟏 − 𝝀
As 𝝀 ⇒ 𝟏, the bias term goes to zero, as it must because the RE
estimator tends to FE estimator
As 𝝀 ⇒ 𝟎, we are leaving a larger fraction of the unobserved effect
in the error term. RE estimator tends to OLS estimator.
47
Random Effects (RE) estimator would be useful if some explanatory
variables remain constant over time.
It assumes that group effects are uncorrelated with regressors, hence
it must be checked whether this assumption is satisfied.
Fixed Effects (FE) estimator measures the relationship based on
time variation within a cross-sectional unit.
Between Effects (BE) estimator measures the relationship based on
cross-sectional variation at each time period.
Random Effects (RE) estimator is a weighted average of the two.
48
Random Effects Model
49
Random Effects Model
50
Random Effects Model
51
Random Effects Model
52
Random Effects Model
53
Random Effects Model
54
Random Effects Model
55
Random Effects Model
56
Fixed Effects or Random?
57
Usually, one needs to apply all of the FE, BE, RE estimators, respectively, to gain
insight on which models is the most appropriate.
Recall: RE is consistent only if Cov (Xi, ui) = 0. Under H0 (below), RE is more
efficient than FE.
Hausman Test:
H0: No difference in coefficients; 𝐶𝑜𝑣 𝛼𝑖 + 𝜇𝑖𝑡 , 𝑥𝑖𝑡 = 0; RE can be used
58
59
Other Uses of Panel Methods
• It’s possible to think of models where there is
an unobserved fixed effect, even if we do not
have true panel data
• A common example is where we think there is
an unobserved family effect
• Can difference siblings
• Can estimate family fixed effect model
60
Additional Issues
• Many of the things we already know about both
cross section and time series data can be
applied with panel data
• Can test and correct for serial correlation in the
errors
• Can test and correct for heteroskedasticity
• Can estimate standard errors robust to both
61