5

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?

kennyB
  • 1,963
  • 3
  • 17
  • 22

1 Answers1

6

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.

Simen Gaure
  • 291
  • 1
  • 4
  • 1
    The next release of lfe (in a month or so) will support this directly with pseries, provided plm is loaded. It turned out to be a very simple fix. At a single point when I create the model frame, I have replaced an "as.formula" with an "as.Formula". The class of 'wage' is then preserved, and the right lag() will be used. – Simen Gaure Apr 21 '15 at 10:51
  • 3
    The current version of lfe (2.3) handles this, i.e. `felm(emp~output+capital + lag(wage, 1)|firm,data=Em)` will use the pseries lag. – Simen Gaure May 29 '15 at 09:42