lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

I got different results from plm and fixest when estimating a 2sls panel model #497

Open dazhwu opened 1 month ago

dazhwu commented 1 month ago

I compared plm, fixest, and FixedEffectModels (julia) with my own data, and found that the latter two produced the same results, different from plm. Is fixest based on a different calculation method compared with plm? Below is an illustration:

library(plm)
library(fixest)
data("EmplUK",package="plm") 
ds = pdata.frame(EmplUK, index = c("firm","year"))

plm_2sls <- plm(emp ~ wage + capital | . - wage + lag(wage, 1), data = ds, effect = "individual", method="within")
summary(plm_2sls)

Coefficients:
        Estimate Std. Error z-value Pr(>|z|)
wage    -0.22881    0.14419 -1.5869  0.11254
capital  1.02658    0.57778  1.7768  0.07561 .

fes_2sls <- feols(emp ~  capital | firm  |  wage ~ lag(wage, 1), data = ds)
summary(fes_2sls)

Standard-errors: Clustered (firm)
          Estimate Std. Error  t value Pr(>|t|)
fit_wage -0.143626   0.071788 -2.00069 0.047374 *
capital   0.801495   0.567784  1.41162 0.160297    
dazhwu commented 1 month ago

I just tried to manually do the 2sls using plm and got the same coefficients as from fixest. It seems that there's some issue with plm.

stage1 <- plm(wage ~ lag(wage,1), data = ds, effect = "individual", method="within")
summary(stage1)
f_wage <- fitted(stage1)

stage2 = plm(emp ~ capital + f_wage , data = ds, effect = "individual", method="within")
summary(stage2)

Coefficients:
         Estimate Std. Error t-value  Pr(>|t|)
capital  0.801495   0.064088 12.5062 < 2.2e-16 ***
f_wage  -0.143626   0.032790 -4.3802 1.327e-05 ***