You are on page 1of 61

Econometrics II

Panel Data Analysis:


First-Differences, Fixed and
Random Effects
Dr. Azam Chaudhry
Professor & Dean, Faculty of Economics
&
Aimal Tanvir
Teaching and Research Fellow, Faculty of Economics

Lahore School of Economics

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:

𝑪𝒓𝒊𝒎𝒆𝒊𝒕 = 𝜷𝟎 + 𝜹𝟎 𝒅𝟖𝟕𝒕 + 𝜷𝟏 𝒖𝒏𝒆𝒎𝒊𝒕 + 𝜶𝒊 + 𝝁𝒊𝒕 ,

𝐶𝑜𝑣 𝛼𝑖 + 𝜇𝑖𝑡 , 𝑢𝑛𝑒𝑚𝑖𝑡 ≠ 0


If,
𝑪𝒐𝒗 𝜶𝒊 , 𝒖𝒏𝒆𝒎𝒊𝒕 ≠ 𝟎
𝐶𝑜𝑣 𝜇𝑖𝑡 , 𝑢𝑛𝑒𝑚𝑖𝑡 = 0

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

• If αi is correlated with the x’s, OLS will be biased,


since we αi is part of the error term

• With panel data, we can difference-out the


unobserved fixed effect

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 - -

2020 15 11 15-10 11-10


=5 =1
City B 2018 18 12 - -

2020 25 14 25-18 14-12


=7 =2
City C 2018 20 12 - -

2020 25 13 25-20 13-12


=5 =1

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

1) For each group calculate group average over time.

2) Obtain the time-demeaned data: yit = yit − yi xit = xit − xi

3) Run the regression on time-demeaned data:

yit = xit + uit

Now, the error term uit 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:

ഥ𝑖 = 𝛽1 𝑥𝑖𝑡 − 𝑥ഥ𝑖 + (𝜇𝑖𝑡 − 𝜇ഥ𝑖 )


𝑌𝑖𝑡 − 𝑌

𝑌𝑖𝑡ሷ = 𝛽1 𝑥𝑖𝑡ሷ + 𝜇𝑖𝑡ሷ , 𝑡 = 1,2

These time-demeaned variables are called fixed effects estimators


or the within estimator ( the time variation in Y and X within each
cross sectional unit has been used to remove heterogeneity).
13
Example-Fixed Effects Estimation with
Two Time Periods (T=2)
Cross-Sectional Time (t) crimeit unempit ሷ 𝒊𝒕
𝒄𝒓𝒊𝒎𝒆 ሷ
𝒖𝒏𝒆𝒎𝒑 𝒊𝒕
Unit (i)
City A 2018 10 10 10-12.5 10-10.5
=-2.5 =-0.5
2020 15 11 15-12.5 11-10.5
=2.5 =0.5
City B 2018 18 12 18-21.5 12-13
=-3.5 =-1
2020 25 14 25-21.5 14-13
=3.5 =1
City C 2018 20 12 20-22.5 12-12.5
=-2.5 =-0.5
2020 25 13 25-22.5 13-12.5
=2.5 =0.5

𝑐𝑟𝑖𝑚𝑒𝐴 = 12.5 𝑢𝑛𝑒𝑚𝑝𝐴 = 10.5


𝑐𝑟𝑖𝑚𝑒𝐵 = 21.5 𝑢𝑛𝑒𝑚𝑝𝐵 = 13
𝑐𝑟𝑖𝑚𝑒𝑐 = 22.5 𝑢𝑛𝑒𝑚𝑝𝑐 = 12.5 14
Fixed Effects Estimation
• When there is an unobserved fixed effect, an
alternative to first differences is fixed effects
estimation
• Consider the average over time of yit = b1xit1
+…+ bkxitk + ai + uit
• The average of ai will be ai, so if you subtract
the mean, ai will be differenced out just as when
doing first differences

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

Suppose our model is: 𝑌𝑖 = 𝛽0 + 𝛽1 𝑋𝑖 + 𝜇𝑖

There are two categories: Di = { 1 if i belongs to group 1


0 otherwise

We run the regression: 𝑌𝑖 = 𝛽0 + 𝛽1 𝑋𝑖 + 𝛽2 𝐷𝑖 + 𝛽3 𝐷𝑖 𝑋𝑖 + 𝜇𝑖

In interpreting the results, we should read two regressions:


Yi = (𝛽0 + 𝛽2 ) + (𝛽1 + 𝛽3 )Xi + i for group 1
Yi = 𝛽0 + 1Xi + i for group 0

If 𝛽2 ≠ 0 , then Yi for group 1 has a different mean


If 𝛽3 ≠ 0 , then Yi for group 1 has a different sensitivity to X
18
Least Squares Dummy Variable
(LSDV) Model
𝑌𝑖𝑡 = 𝛽0 + 𝛽1 𝑥𝑖𝑡 + 𝛼𝑖 + 𝜇𝑖𝑡
If i=3, then: Directly controlling for each cross-sectional
unit’s heterogeneity

𝑌𝑖𝑡 = 𝛽0 + 𝛽1 𝑥𝑖𝑡 + 𝛿1 𝑑2𝑖 + 𝛿2 𝑑3𝑖 + 𝜇𝑖𝑡


If i=1,2,3….N then we incorporate N-1 dummies
for each entity to avoid falling into the dummy
variable trap (perfect collinearity).
𝛽෣
𝐿𝑆𝐷𝑉 = 𝛽෢
𝐹𝐸
𝑆𝐸(𝛽෣ 𝐿𝑆𝐷𝑉 ) = 𝑆𝐸( ෣
𝛽 𝐹𝐸 )
19
Example-LSDV

Cross-Sectional Unit (i) Time (t) crimeit unempit 𝑑2 𝑑3

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

𝑤ℎ𝑒𝑟𝑒 𝜎𝜖2 = 𝑣𝑎𝑟 𝛼𝑖 𝑎𝑛𝑑 𝜎𝑢2 = 𝑣𝑎𝑟 𝜇𝑖𝑡

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

• Need to transform the model and do GLS to solve


the problem and make correct inferences
• End up with a sort of weighted average of OLS
and Fixed Effects – use quasi-demeaned data

 = 1 −  ( + T )
2
u
2
u
2 12
a

yit − yi =  0 (1 −  ) + 1 (xit1 − xi1 ) + ...


+  k ( xitk − xik ) + ( it − i )
45
Random Effects Model
• If 𝜆= 1, then this is just the fixed effects
estimator
• If 𝜆= 0, then this is just the OLS estimator
• So, the bigger the variance of the unobserved
effect (𝜎𝛼2 ), the closer it is to FE
• The smaller the variance of the unobserved
effect (𝜎𝛼2 ), the closer it is to OLS
• If 0< 𝜆 <1, then RE≠ 𝑂𝐿𝑆, 𝐹𝐸
• Stata will do Random Effects for us
46
Random Effects Model
𝒚𝒊𝒕 − 𝝀ഥ 𝒙𝒊𝟏 ) + ….+𝜷𝒌 (𝒙𝒊𝒕𝒌 − 𝝀ഥ
𝒚𝒊 = 𝜷𝟎 𝟏 − 𝝀 + 𝜷𝟏 (𝒙𝒊𝒕𝟏 − 𝝀ഥ 𝒙𝒊𝒌 ) + (𝒗𝒊𝒕 − 𝝀ഥ
𝒗𝒊 )

𝒗𝒊𝒕 − 𝝀ഥ
𝒗𝒊 = 𝟏 − 𝝀 𝜶𝒊 + (𝒖𝒊𝒕 −𝝀ഥ 𝒖𝒊𝒕 )
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

HA: Significant differences in coefficients; 𝐶𝑜𝑣 𝛼𝑖 + 𝜇𝑖𝑡 , 𝑥𝑖𝑡 ≠ 0 ;RE cannot be


used; FE or FD must be used

STATA commands: xtreg y x, fe


estimates store fixed
xtreg y x, re
estimates store random
hausman fixed random
(Hausman test is not available in menu)

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

You might also like