I want to estimate a dynamic panel model with firm level time invariant fixed effects and time-varying regional fixed effects. I'm trying to implement this with R package plm, but I run into trouble when I try to include that time-varying regional fixed effects. Here's what I've done:

df <- plm.data(df, index = c("firm", "year")

fit <- pgmm(formula = y ~ lag(y, 1) + lag(X, 0:1) + region:year | 
 lag(y, 2:99) + lag(X, 2:99), 
 data = df, effect = "individual", model = "twosteps", 
 transformation = "ld")

The system becomes singular and does not solve. I can fix that by replacing region:year with region, but that's not what I want to do. So it seems that regional fixed effects can't be time varying for some reason. Is this intended to be so or is there some workaround available? If R cannot handle this, is there some other program that can?

  • 1
    $\begingroup$ Have you tried the latest development version? Something related to pgmm has been fixed two weeks ago: r-forge.r-project.org/R/?group_id=406 $\endgroup$
    – Helix123
    Mar 21, 2016 at 16:40
  • $\begingroup$ Thanks! I could not find what exactly has changed in new dev version. Nevertheless this is a difficult option for me anyways as I have the data in remote access and the admins do not install dev versions of packages. The plm version I use is 1.5-12. $\endgroup$
    – Antti
    Mar 22, 2016 at 8:01

2 Answers 2


Could it be that your lag variables are not properly defined? Check here. They suggest using dynformula function to generate lagged variables.

  • $\begingroup$ I'm not sure about that. I was following the newest plm vignette and that's where I got my template for the formula. The post you found is already seven years old and perhaps the current approach was not available yet? I found that in older vignette versions dynformula is mentioned but not anymore in the latest vignette. Perhaps that is deprecated nowadays? $\endgroup$
    – Antti
    Apr 6, 2016 at 12:10

I've been trying to find a similar procedure, but I don't think an 'out of the box' model is available in R yet.

It looks like your after a panel data model similar to what Ahn, Lee & Schmidt developed in 2013 to model multiple time-varying individual effects (https://asu.pure.elsevier.com/en/publications/panel-data-models-with-multiple-time-varying-individual-effects). The model is flexible and overcomes previous bias for datasets with large N and small T.

If you have small N and large T, you could try the phtt package (https://mran.microsoft.com/snapshot/2016-11-30/web/packages/phtt/vignettes/phtt.pdf).

I am yet to find where the Ahn et al (2013) model has been implemented in R. The tvFE package (https://rdrr.io/cran/tvReg/man/tvFE.html) should get you part-way there.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.