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

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?

• This is maybe a better question for StackOverflow, but out of curiousity, what are the two different commands you are entering for these different results? Nov 24, 2020 at 9:13
• Yeah I was torn between where to post but I figured this forum would be more familiar with econometric theory. The one that returns an estimate: reg1 <- felm(HPI~FLOODED+ lag(dat.reg[,'HPI'],1) + factor(FIPS) | YEARxQT | 0 | FIPS, data= dat.reg). The one that returned NA: reg2 <- felm(HPI~FLOODED+ lag(dat.reg[,'HPI'],1) | FIPS+YEARxQT | 0 | FIPS, data= dat.reg).
– DPek
Nov 24, 2020 at 13:52
• Did your reg2 call give you a Warning message? Nov 25, 2020 at 6:06

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)

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