TransWikia.com

R's felm() fixed effects vs. factor() within lm()

Economics Asked by DPek on February 19, 2021

I am wondering why using felm’s fixed effect option versus using the factor() function is different? I was under the impression they were one in the same?

I am running a panel regression where i is the a unique FIPS code and t is every quarter. The variable of interest, a binary of whether the FIPS flooded or not, is constant across time. However, my y, housing prices, varies each with each t. When I use felm()’s fixed effect option for FIPS, flooded is NA. However, using factor(FIPS), gives an estimate for the variable of interest.

I’m under the impression felm()’s fixed effect function is working correctly. Since being flooded is time constant and has no variation within a given FIPS, the fixed effect is absorbing the effect of flooding. However, I’m not sure why factor(FIPS) within the regression would return an estimate since a fixed effect essentially the same thing?

One Answer

You are correct in noting that, adding factor(FIPS) in side the regression formula should be equivalent to specifiying factor(FIPS) + YEARxQT in the felm() fixed effects block. I am less certain that your reg2 model that throws up the NA's is working correctly however, as that would typically throw up an error message before getting that result. Without actually seeing your data, I can only presume your issue is related to a bug, or has something very specific to do with your data.

Fortunately, there are lots of different ways to do this estimation, and it might be worth it to try this using different packages to corroborate the correct estimation and better understand what is going on with your specific use of felm().

For example, just to check, I downloaded some sample panel data and ran a FE estimation using a binary for the main regressor. I run a Least Square Dummy Variable model, a FE using the plm package, and then two versions with felm, both placing the entity fixed effect inside and outside of felm's FE block as you did in your example. In all four cases the coefficient estimate was exactly the same (which it should be).

library(foreign)
library(plm)
library(lfe)

Panel <- read.dta("http://dss.princeton.edu/training/Panel101.dta") 

modlsdv <-lm(y ~ op + factor(country) + factor(year), data=Panel)


modplm <- plm(y ~ op + factor(year), data=Panel, index=c("country", "year"), model="within")


modfelm1 <- felm(y ~ op | country + year | 0 | country, data=Panel)

#in this last model, I move the entity FE outside the FE block
modfelm2 <- felm(y ~ op + factor(country) | year | 0 | country, data=Panel)

I only show the coefficient of interest as all the factored-out variables take up a lot of space, but you can see below that they are all equivalent (apart from the SE's in the felm models being different because of how they were clustered).

────────────────────────────────────────────────────────────────────────────
                     LSDV           plm           felm1          felm2      
               ─────────────────────────────────────────────────────────────
  (Intercept)    419655690.33                                               
                          3                                                 
                 (1320579554.                                               
                        769)                                                
  op             -1434277502.   -1434277502.   -1434277502.   -1434277502.  
                        244            244              244            244  
                                                          *            *    
                 (771947977.3   (771947977.3   (524652684.0   (594276313.4  
                         01)            01)            46)          03) 
               ─────────────────────────────────────────────────────────────
  N                  70             70             70           70          
  R2                  0.386          0.264          0.386        0.386      
  logLik          -1609.649                     -1609.649     -1609.649     
                                                                            
  AIC              3255.298                      3255.298     3255.298      
──────────────────────────────────────────────────────────────────────────

Answered by anguyen1210 on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP