sgaure / lfe

Source code repository for the R package lfe on CRAN.
53 stars 18 forks source link

`getfe` reference level #52

Open tappek opened 3 years ago

tappek commented 3 years ago

It seems like getfe chooses the reference level for the fixed effects based on the pattern of unbalancedness if there is more than one fixed effect. This feels somewhat random to the end-user (seems like it is the first level with max observations).

A second thing I noticed about getfe is that the reference argument does not seems to be respected (if method != "kaczmarz").

See the examples below with comments (they are for IV models, but same applied to ordinary regression models).

data("Crime", package = "plm")
delrows.a <- -c(1,2,10,12)
delrows.b <- -c(9)

crime_formula_2SLS_tw <- lcrmrte ~ lprbconv + lprbpris + lavgsen + 
  ldensity + lwcon + lwtuc + lwtrd + lwfir +
  lwser + lwmfg + lwfed + lwsta + lwloc + lpctymle | 
  county + year |
  (lprbarr|lpolpc ~ ltaxpc + lmix)

FE2SLS_tw_unbal.felm.a <- lfe::felm(crime_formula_2SLS_tw, data = Crime[delrows.a, ])
FE2SLS_tw_unbal.felm.b <- lfe::felm(crime_formula_2SLS_tw, data = Crime[delrows.b, ])

getfe(FE2SLS_tw_unbal.felm.a) # year.84 is set to zero
getfe(FE2SLS_tw_unbal.felm.b) # year.81 is set to zero

# same for ef = "zm"
getfe(FE2SLS_tw_unbal.felm.a, ef = "zm") # year.84 is set to zero
getfe(FE2SLS_tw_unbal.felm.b, ef = "zm") # year.81 is set to zero

# arg references does not work with method != "kaczmarz"
getfe(FE2SLS_tw_unbal.felm.a, references = "year.81", method = "cg")
getfe(FE2SLS_tw_unbal.felm.a, references = "year.81", method = "cholesky")