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