<p>I apologize for my previous comment; it doesn't make much sense.</p>
<p>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 <a href="https://drive.google.com/file/d/1ZqZAQAvEKSvr-JCXMemDtgkSadjA9n0m/view?usp=sharing" rel="nofollow noreferrer">here</a>.</p>
<p>By looking at the source code for the package, we can see what causes that error message to appear:</p>
<pre><code>  if((use.mc.diff | use.mc.lev) &amp;&amp; (length(unique(dat[, varname.t])) &lt;
 3)){    

stop(&quot;Insufficient number of time periods to derive linear
     moment conditions.&quot;)  
}
</code></pre>
<p>which I understand as: if the length of the vector containing the unique dates is less than 3, then the estimation cannot be computed.</p>
<p>Looking at the package help, we can run the example code provided:</p>
<pre><code>## Load data from plm package 
    
    if(!requireNamespace(&quot;plm&quot;, quietly = TRUE)){ 
    
     stop(&quot;Dataset from package \&quot;plm\&quot; needed for this example. 
         Please install the package.&quot;, call. = FALSE) 
    } 
    
    else{  
    
    data(EmplUK,
         package = &quot;plm&quot;)  dat &lt;- EmplUK  dat[,c(4:7)] &lt;- log(dat[,c(4:7)])
         
         ## Arellano and Bond (1991) estimation in Table 4, column (a1) 
    
     m1 &lt;- pdynmc(dat = dat, varname.i = &quot;firm&quot;, varname.t = &quot;year&quot;,
                  use.mc.diff = TRUE, use.mc.lev = FALSE, use.mc.nonlin = FALSE,
                  include.y = TRUE, varname.y = &quot;emp&quot;, lagTerms.y = 2,
                  fur.con = TRUE, fur.con.diff = TRUE, fur.con.lev = FALSE,
                  varname.reg.fur = c(&quot;wage&quot;, &quot;capital&quot;, &quot;output&quot;), lagTerms.reg.fur = c(1,2,2),
                  include.dum = TRUE, dum.diff = TRUE, dum.lev = FALSE, varname.dum = &quot;year&quot;,
                  w.mat = &quot;iid.err&quot;, std.err = &quot;corrected&quot;, estimation = &quot;onestep&quot;,
                  opt.meth = &quot;none&quot;)
  summary(m1)
    }
</code></pre>
<p>which works just fine. Furthermore, if we run the following code:</p>
<pre><code>length(unique(dat[, &quot;year&quot;]))
</code></pre>
<p>we get 9 as the output, which is clearly greater than 3. However, if we do the same using the data you have provided:</p>
<pre><code>length(unique(datacheck[, &quot;Year&quot;]))
</code></pre>
<p>the result is 1, which is smaller than 3, just as the error message pointed out.</p>
<p>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.</p>
<p>While this is not a definitive answer, it's too long to post as a comment. Hope it helps anyway.</p>
<p>EDIT:</p>
<p><a href="https://rdrr.io/cran/pdynmc/src/R/pdynmc_estFct.R" rel="nofollow noreferrer">Source code</a></p>
<p><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwie5LzjmL_uAhWSLLkGHa98ANsQFjAAegQIAxAC&amp;url=https%3A%2F%2Fcran.r-project.org%2Fweb%2Fpackages%2Fpdynmc%2Fvignettes%2Fpdynmc.pdf&amp;usg=AOvVaw09qEQPAbnmLD4yourDyguF" rel="nofollow noreferrer">Vignette</a></p>

CC BY-SA 4.0
2021-01-28T17:47:24.363Z
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?
Wadim iLchuk
CC BY-SA 4.0
2021-01-28T17:54:26.793Z
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.
Pedro Cunha
CC BY-SA 4.0
2021-01-29T22:02:55.990Z
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?
Wadim iLchuk
CC BY-SA 4.0
2021-01-30T11:06:33.793Z
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!
Pedro Cunha
CC BY-SA 4.0
2021-01-28T17:42:04.193Z
2021-01-28T18:01:14.557Z
2021-01-28T18:01:14.557Z
Pedro Cunha
<p>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:</p>
<p>I need to estimate the next model with GMM estimator:
<a href="https://i.sstatic.net/Qsuid.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Qsuid.png" alt="Model to estimate" /></a></p>
<p>So far I was using <em>pgmm</em> function in <em>plm</em> package. You can check other topics of mine with the issues I have faced, and I still did not solve them.</p>
<p>Hence, I tried to move to another package <em>pdynmc</em> authorized by Dr. Markus Fritsch.</p>
<p>Here is a part of my dataset filtered with firms having at least 5 years of observations: <a href="https://drive.google.com/file/d/1dFUgXp8e1K0CdqMTpbtfviDq9vgJNOxW/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1dFUgXp8e1K0CdqMTpbtfviDq9vgJNOxW/view?usp=sharing</a></p>
<p>I am not sure you can get a context of it, but I need to estimate similar to this model as:</p>
<p>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).</p>
<p>In my dataset, needed variables are:</p>
<ul>
<li><em>ID</em> - is an ID of the companies</li>
<li><em>Year</em> - the year of observation</li>
<li><em>ta</em> - log of total assets</li>
<li><em>ff1-5</em> - financial friction variable of the companies</li>
<li><em>LVomegaACF_A</em> - is a TFP measure</li>
<li><em>domegaACF_A</em> - is ΔTFP measure</li>
<li><em>ddebt</em> -  ΔDebt variable</li>
<li><em>dsales</em> -  ΔSales variable</li>
<li><em>Age</em> - age of the companies</li>
</ul>
<p>I tried to use the package as follows:</p>
<pre><code>model &lt;- pdynmc(dat = LVcheck, varname.i = &quot;ID&quot;, varname.t = &quot;Year&quot;,
                varname.y = &quot;domegaACF_A&quot;, lagTerms.y = 2,
                fur.con = FALSE, varname.reg.fur = c(&quot;ddebt&quot;, &quot;ff1&quot;, &quot;Age&quot;, &quot;ta&quot;, &quot;dsales&quot;),
                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 = &quot;Year&quot;,
                w.mat = &quot;iid.err&quot;, std.err = &quot;corrected&quot;, estimation = &quot;onestep&quot;, opt.meth = &quot;none&quot;,
                use.mc.nonlin = FALSE, use.mc.diff = TRUE, use.mc.lev = FALSE, include.y = TRUE)
</code></pre>
<p>And the error I receive:</p>
<pre><code>Error in pdynmc(dat = LVData_A, varname.i = &quot;ID&quot;, varname.t = &quot;Year&quot;,  :
  Insufficient number of time periods to derive linear moment conditions.
</code></pre>
<p>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.</p>
<p>I would really much appreciate your responses and any support from your side. Here is the package description <a href="https://rdrr.io/cran/pdynmc/man/pdynmc.html" rel="nofollow noreferrer">https://rdrr.io/cran/pdynmc/man/pdynmc.html</a></p>
<p>Despite the fact, everything is quite detailed there, I still do not understand what is wrong with what I am doing.</p>
<p>Thank you very much in advance.</p>

CC BY-SA 4.0
2021-01-28T00:37:37.020Z
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.
Pedro Cunha
CC BY-SA 4.0
2021-01-28T11:34:29.770Z
@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.
Wadim iLchuk
<microeconomics><r>
pdynmc package in R | GMM issue
Wadim iLchuk
# pdynmc package in R | GMM issue

(Asked by: username_0 on 2021-01-27)

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](https://i.sstatic.net/Qsuid.png)](https://i.sstatic.net/Qsuid.png)

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.

**Tags:** microeconomics, r

> **Comments:**
> **username_1**: 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.  
> **username_0**: @username_1, 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.  

---

## 1 answers

### Answer by username_1 on 2021-01-28. Score: 1 | Accepted answer

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](https://drive.google.com/file/d/1ZqZAQAvEKSvr-JCXMemDtgkSadjA9n0m/view?usp=sharing).

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])) <
 3)){    

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) 
    } 
    
    else{  
    
    data(EmplUK,
         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")
  summary(m1)
    }

```

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.

EDIT:

[Source code](https://rdrr.io/cran/pdynmc/src/R/pdynmc_estFct.R)

[Vignette](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwie5LzjmL_uAhWSLLkGHa98ANsQFjAAegQIAxAC&url=https%3A%2F%2Fcran.r-project.org%2Fweb%2Fpackages%2Fpdynmc%2Fvignettes%2Fpdynmc.pdf&usg=AOvVaw09qEQPAbnmLD4yourDyguF)

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_0**: 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?  
> **username_1**: 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!  

---

