I am a student, currently working on my Bachelor's Thesis. And as the next deadline approaches, I hope someone could give me a hand on my constant issue:

I need to estimate the next model with GMM estimator: Model to estimate

So far I was using pgmm function in plm package. You can check other topics of mine with the issues I have faced, and I still did not solve them.

Hence, I tried to move to another package pdynmc authorized by Dr. Markus Fritsch.

Here is a part of my dataset filtered with firms having at least 5 years of observations: https://drive.google.com/file/d/1dFUgXp8e1K0CdqMTpbtfviDq9vgJNOxW/view?usp=sharing

I am not sure you can get a context of it, but I need to estimate similar to this model as:

A change or growth in the dependent variable from t to t+1 (ΔTFPt+1) = GMM instruments, as far as I understood, of the, lagged dependent variable (so lagged change in the dependent variable) (ΔTFPt, and ΔTFPt-1) + change in one other variable (ΔDebt), the measure of needed variable (financial friction) + interaction between last 2 variables (financial friction * ΔDebt) + control variables (firm age, firm size or log(TA), change in sales or ΔSales).

In my dataset, needed variables are:

  • ID - is an ID of the companies
  • Year - the year of observation
  • ta - log of total assets
  • ff1-5 - financial friction variable of the companies
  • LVomegaACF_A - is a TFP measure
  • domegaACF_A - is ΔTFP measure
  • ddebt - ΔDebt variable
  • dsales - ΔSales variable
  • Age - age of the companies

I tried to use the package as follows:

model <- pdynmc(dat = LVcheck, varname.i = "ID", varname.t = "Year",
                varname.y = "domegaACF_A", lagTerms.y = 2,
                fur.con = FALSE, varname.reg.fur = c("ddebt", "ff1", "Age", "ta", "dsales"),
                lagTerms.reg.fur = c(1,1,1,1,1),
                fur.con.diff = TRUE, fur.con.lev = FALSE,
                include.dum = TRUE, dum.diff = TRUE, dum.lev = FALSE, varname.dum = "Year",
                w.mat = "iid.err", std.err = "corrected", estimation = "onestep", opt.meth = "none",
                use.mc.nonlin = FALSE, use.mc.diff = TRUE, use.mc.lev = FALSE, include.y = TRUE)

And the error I receive:

Error in pdynmc(dat = LVData_A, varname.i = "ID", varname.t = "Year",  :
  Insufficient number of time periods to derive linear moment conditions.

The question is the following, why the number of periods is insufficient if the only firms are displayed that have at least 5 years of observations? And also, is my code written accordingly to my model specification, and all the arguments needed are written correctly.

I would really much appreciate your responses and any support from your side. Here is the package description https://rdrr.io/cran/pdynmc/man/pdynmc.html

Despite the fact, everything is quite detailed there, I still do not understand what is wrong with what I am doing.

Thank you very much in advance.

  • $\begingroup$ What type of variable is Year in your data.frame? It might be coded as numeric, in which case the error message makes complete sense. Perhaps try writing varname.t = "as.factor(Year)" or, if that doesn't work, try setting LVData_A$\$$Year <- as.factor(LVData_A$\$$Year) before running the estimation. $\endgroup$ Jan 28, 2021 at 0:37
  • 1
    $\begingroup$ @PedroCunha, If I do it, the Year variable losses its sense, and does not show the year of observation, but simply consequent numbers. And still, the problem exists. $\endgroup$ Jan 28, 2021 at 11:34

1 Answer 1


I apologize for my previous comment; it doesn't make much sense.

Upon inspecting your data, I've found that there are IDs for which you only have observations for two years. The problematic IDs are: 9231, 24873, 24907, 78341, 78998, 90246, 92673, 92787, and 93846. You can see the full frequency table here.

By looking at the source code for the package, we can see what causes that error message to appear:

  if((use.mc.diff | use.mc.lev) && (length(unique(dat[, varname.t])) <

stop("Insufficient number of time periods to derive linear
     moment conditions.")  

which I understand as: if the length of the vector containing the unique dates is less than 3, then the estimation cannot be computed.

Looking at the package help, we can run the example code provided:

## Load data from plm package 
    if(!requireNamespace("plm", quietly = TRUE)){ 
     stop("Dataset from package \"plm\" needed for this example. 
         Please install the package.", call. = FALSE) 
         package = "plm")  dat <- EmplUK  dat[,c(4:7)] <- log(dat[,c(4:7)])
         ## Arellano and Bond (1991) estimation in Table 4, column (a1) 
     m1 <- pdynmc(dat = dat, varname.i = "firm", varname.t = "year",
                  use.mc.diff = TRUE, use.mc.lev = FALSE, use.mc.nonlin = FALSE,
                  include.y = TRUE, varname.y = "emp", lagTerms.y = 2,
                  fur.con = TRUE, fur.con.diff = TRUE, fur.con.lev = FALSE,
                  varname.reg.fur = c("wage", "capital", "output"), lagTerms.reg.fur = c(1,2,2),
                  include.dum = TRUE, dum.diff = TRUE, dum.lev = FALSE, varname.dum = "year",
                  w.mat = "iid.err", std.err = "corrected", estimation = "onestep",
                  opt.meth = "none")

which works just fine. Furthermore, if we run the following code:

length(unique(dat[, "year"]))

we get 9 as the output, which is clearly greater than 3. However, if we do the same using the data you have provided:

length(unique(datacheck[, "Year"]))

the result is 1, which is smaller than 3, just as the error message pointed out.

I can't figure out why that is happening. My guess is that perhaps you need at least 3 unique sequences of years or something else, because you do have enough observations with more than 3 years available.

While this is not a definitive answer, it's too long to post as a comment. Hope it helps anyway.


Source code


  • 1
    $\begingroup$ it seems to solve the problem, I believe. Thank you. Yet I have another question. Could you share the source code of the package, since I was not able to find it? And is there somewhere stated, that interaction terms could be used? $\endgroup$ Jan 28, 2021 at 17:47
  • $\begingroup$ Sure. As for your second question, I believe you are more likely to find the answer to that in the help file for the package. I'll add both links to my answer. $\endgroup$ Jan 28, 2021 at 17:54
  • 1
    $\begingroup$ Thank you for the help! $\endgroup$ Jan 28, 2021 at 17:58
  • $\begingroup$ sorry to ask again, but how to filter only those ID with enough observation? I am filtering group by ID dataset as filter(n() >= 3) But how to properly do it, so to remove the error? $\endgroup$ Jan 29, 2021 at 22:02
  • $\begingroup$ What I did was create a frequency table and, from that, use the frequencies to create a set of IDs that matched my criterion. However, as I pointed out, removing the IDs with only 2 observations does not fix the error! $\endgroup$ Jan 30, 2021 at 11:06

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.