Uploaded by izma azhar

econometrics II

advertisement
Econometrics II
Panel Data Analysis:
First-Differences, Fixed and
Random Effects
Dr Rabia Ikram
Slides prepared by Dr Azam & Aimal Tanvir
Lahore School of Economics
Winter 2023
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 crimetypically 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
Unit (i)
Time (t)
crimeit
unempit
โˆ†๐’„๐’“๐’Š๐’Ž๐’†๐’Š
โˆ†๐’–๐’๐’†๐’Ž๐’‘๐’Š
City A
2018
10
10
-
-
2020
15
11
15-10
=5
11-10
=1
2018
18
12
-
-
2020
25
14
25-18
=7
14-12
=2
2018
20
12
-
-
2020
25
13
25-20
=5
13-12
=1
City B
City C
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
๏€ฆ๏€ฆit is white noise. Hence, the FE estimator is
Now, the error term u
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
Unit (i)
Time (t)
crimeit
unempit
๐’„๐’“๐’Š๐’Ž๐’†๐’Š๐’•
๐’–๐’๐’†๐’Ž๐’‘๐’Š๐’•
City A
2018
10
10
10-12.5
=-2.5
10-10.5
=-0.5
2020
15
11
15-12.5
=2.5
11-10.5
=0.5
2018
18
12
18-21.5
=-3.5
12-13
=-1
2020
25
14
25-21.5
=3.5
14-13
=1
2018
20
12
20-22.5
=-2.5
12-12.5
=-0.5
2020
25
13
25-22.5
=2.5
13-12.5
=0.5
City B
City C
๐‘๐‘Ÿ๐‘–๐‘š๐‘’๐ด = 12.5
๐‘๐‘Ÿ๐‘–๐‘š๐‘’๐ต = 21.5
๐‘๐‘Ÿ๐‘–๐‘š๐‘’๐‘ = 22.5
๐‘ข๐‘›๐‘’๐‘š๐‘๐ด = 10.5
๐‘ข๐‘›๐‘’๐‘š๐‘๐ต = 13
๐‘ข๐‘›๐‘’๐‘š๐‘๐‘ = 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
2018
18
12
1
0
2020
25
14
1
0
2018
20
12
0
1
2020
25
13
0
1
City B
City C
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๏ณ ๏€ฉ๏
yit ๏€ญ ๏ฌyi ๏€ฝ ๏ข 0 ๏€จ1 ๏€ญ ๏ฌ ๏€ฉ ๏€ซ ๏ข1 ๏€จ xit1 ๏€ญ ๏ฌxi1 ๏€ฉ ๏€ซ ...
๏€ซ ๏ข k ๏€จ xitk ๏€ญ xik ๏€ฉ ๏€ซ ๏€จ๏ฎ it ๏€ญ๏ฎ i ๏€ฉ
2
u
2
u
2 12
a
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
Download