Search code examples
rxtsplmlfe

How to calculate dynamic panel models with lfe package


I am trying to estimate a large dynamic fixed effects panel data model with lags, and multiple group effects.

I know about the pseries object from the plm package which can handle panel regression with lags.

library(plm)
data("EmplUK", package = "plm")
Em <- pdata.frame(EmplUK)
plm(emp~output+capital + lag(wage, 1),data=Em,model="within")

Is there a similar solution in the lfe package for panel objects so that I can take advantage of the speediness that lfe provides?


Solution

  • There is no direct way to do lags in felm as of now, but it is possible to do it as follows:

    library(lfe)
    felm(emp~output+capital + lag(Em[,'wage'],1)|firm,data=Em)
    

    The reason the lag does not work straight away with felm is that it will use the default lag function, not the pseries lag. When specifying it as above, the pseries lag is used.

    Another way to make it work is:

    felm(emp~output+capital + lag(wage,1)|firm,data=as.data.frame(Em))
    

    I.e. include an explicit as.data.frame, this will convert Em to a "data.frame" with appropriate attributes. This will incur a copy of the entire dataset, but is no different from what plm does behind the scene.