<p>I have the following problem with the Arellano and Bond (1991) or Blundell and Bond (1998) estimators in R using the <em>plm</em> package. I receive the following problem when trying to run the needed regression:
<a href="https://i.sstatic.net/iY2sc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iY2sc.png" alt="enter image description here" /></a></p>
<p>The dataset could be found here: <a href="https://drive.google.com/file/d/1WUCrMCi7bJmhYbzZxNuXDpFIwXJTqdh3/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1WUCrMCi7bJmhYbzZxNuXDpFIwXJTqdh3/view?usp=sharing</a></p>
<p>My code is the following, it seems that I do everything correctly, the formula I need to be estimated is the following: <a href="https://i.sstatic.net/cuNlt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cuNlt.png" alt="X is the control variables included in the code, and a and b are fixed effects" /></a></p>
<pre><code>remove(list=ls())

library(plm)
library(dplyr)
library(ggplot2)
library(prodest)
library(estprod)
library(broom)
library(pdynmc)

pckg&lt;-c(&quot;plm&quot;,&quot;readxl&quot;,&quot;dplyr&quot;,&quot;ggplot2&quot;, &quot;broom&quot;,&quot;prodest&quot;, &quot;estprod&quot;)
#install.packages(c(&quot;plm&quot;,&quot;readxl&quot;,&quot;dplyr&quot;,&quot;ggplot2&quot;, &quot;broom&quot;,&quot;prodest&quot;, &quot;estprod&quot;))
lapply(pckg, require, character.only = TRUE)

# Set the working directory
setwd(&quot;C:/Users/vadya/Desktop/baka&quot;)

# Downloading the survey data
Data &lt;- read.csv(&quot;test.csv&quot;, header=TRUE, sep=&quot;,&quot;)
str(Data)

Data<span class="math-container">$ID&lt;-as.numeric(as.factor(Data$</span>ID))

summary(Data)

DataA11 &lt;- Data %&gt;% 
  filter(NACE == 'A' &amp; Year &lt; 2013) %&gt;% 
  filter(VA &gt; 0, L &gt; 0, FA &gt; 0, M &gt; 0, Turn &gt; 0, TA &gt; 0) %&gt;%
  mutate(ID = ID,
         Year = Year,
         l = log(L),
         va = log(VA),
         fa = log(FA),
         m = log(M),
         turn = log(Turn),
         ta = log(TA),
         ff1 = (LTD + STD)/TA,
         ff2 = lag(Cash),
         ff4 = FA/Sales,
         ff5 = TFA/TA)

####################################################################################

mod2LP &lt;- prodest::prodestLP(DataA11<span class="math-container">$turn, fX = DataA11$</span>l, sX = DataA11<span class="math-container">$fa, pX = DataA11$</span>m, idvar = DataA11<span class="math-container">$ID, timevar = DataA11$</span>Year, 
                             R = 100, cX = NULL, opt = &quot;optim&quot;, theta0 = NULL, cluster = NULL, tol = 1e-100, exit = FALSE)  
mod2LP
omegaLP &lt;- prodest::omega(mod2LP)
summary(mod2LP)
summary(omegaLP)

DataA11$omega &lt;- prodest::omega(mod2LP) 

######################################################################################

DataA11 &lt;- DataA11 %&gt;%
  arrange(ID, Year) %&gt;%
  group_by(ID) %&gt;%
  mutate(domega = omega - dplyr::lag(omega),
         debt = LTD + STD,
         ddebt = debt - dplyr::lag(debt),
         dsales = Sales - dplyr::lag(Sales)) %&gt;%
  ungroup

PDataA11 &lt;- pdata.frame(DataA11, index = c(&quot;ID&quot;,&quot;Year&quot;))

pdim(PData)
pvar(PData)

z1 &lt;- pgmm(domega ~ lag(domega, 1:2) + ddebt + ff1 + ff1:ddebt + Age + ta + dsales | lag(domega, 2:99),
           data = PDataA11, effect = &quot;twoways&quot;, model = &quot;twosteps&quot;)
summary(z1, robust = TRUE)
</code></pre>
<p>ALSO! It would be perfect if you provide any information on that package and also what I do incorrectly + would be great if you said how to add fixed effects to this <em>pgmm</em> function.</p>
<p>Thanks a lot to each of you in advance!!!:)</p>
<p>UPDATE:</p>
<pre><code>data(&quot;EmplUK&quot;, package = &quot;plm&quot;)

## Arellano and Bond (1991), table 4 col. b 
emp.gmm &lt;- pgmm(log(emp)~lag(log(emp), 1:2)+lag(log(wage), 0:1)+log(capital)+
                  lag(log(output), 0:1)|lag(log(emp), 2:99),
                data = EmplUK, effect = &quot;twoways&quot;, model = &quot;twosteps&quot;)
summary(emp.gmm)
</code></pre>
<p>I run this code, that is provided here: <a href="https://rdrr.io/cran/plm/man/pgmm.html" rel="nofollow noreferrer">https://rdrr.io/cran/plm/man/pgmm.html</a></p>
<p>and I get the following message:
<a href="https://i.sstatic.net/ieHmS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ieHmS.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2020-10-13T22:05:37.440Z
This looks like dataset issue rather than code issue per se. Try if the code works with simulated data with longer T. My guess is it will and in this dataset you don’t have enough observations. Also you can get all info there is on pgmm by simply typing ?pgmm into console. Furthermore, it already has twoway fixed effects - that is what the option twoway does. If you want ‘vanilla’ fixed effects then just change argument ‘twoway’ to ‘individual’.
1muflon1
CC BY-SA 4.0
2020-10-14T09:19:57.893Z
Tried not to restrict dataset to only 2011 and 2012 year, and got the following problem: Error: `n` must be a nonnegative integer scalar, not an integer vector of length 2. Then I filtered to get only the positive numbers (which is not logical) and got the next issue: Error in Formula(formula) : inherits(object, "formula") is not TRUE. So, I do not really know how to solve it, despite the fact I have read the documentation of the package.
Wadim iLchuk
CC BY-SA 4.0
2020-10-14T09:44:54.420Z
but you are specifying lags for the instrument from 2-99. Last time I was giving you an answer with this dataset I just quickly checked the distribution of temporal dimension among panel IDs and if I remember correctly no ID had more than 9 years associated with it. Also you use lot of control variables and have non-trivial amount of missing observations and the panel is unbalanced I would not be surprised if there simply isn’t in the end enough data points to run the model you want.
1muflon1
CC BY-SA 4.0
2020-10-14T09:47:31.097Z
But, even if I change the number from 99 to whatever 3,4,5,6... the problem is the same Error in Formula(formula) : inherits(object, "formula") is not TRUE. Also, If I try to use the same example as in pgmm function description with EmplUK dataset, the result is the same Error: n must be a nonnegative integer scalar, not an integer vector of length 2.
Run rlang::last_error() to see where the error occurred.
Wadim iLchuk
CC BY-SA 4.0
2020-10-14T09:55:54.720Z
then there might be some additional errors in the specification. However, I tried to run pgmm on a different panel dataset that is balanced and has long T worked fine for me and I tried to also use interaction terms so that is not the problem. As I originally recommended you should simulate a new dataset with long T. Keep the variable names and everything in the command same. See if it runs with simulated data. If it works with simul. data problem is not in command but with dataset. In that case double check all variables are properly declared and try running MVA and possibly  imputation
1muflon1
CC BY-SA 4.0
2020-10-14T14:52:59.310Z
Yes, I tried to run the same command but with the author's dataset provided, and got the same problem
Wadim iLchuk
CC BY-SA 4.0
2020-10-14T14:55:47.513Z
can you update that in your answer I might take a look at it and try if I can replicate the trouble because I think for me the datasets that come with the command worked without any issue. Otherwise this could also easily be due to outdated R some packages are built under new versions the 4.0.0 and later versions changed the way how R works in non-trivial ways
1muflon1
CC BY-SA 4.0
2020-10-14T16:25:50.627Z
Updated, I run the code from "UPDATE" right after the first part of the code
Wadim iLchuk
CC BY-SA 4.0
2020-10-14T19:24:53.197Z
Oh I originally not noticed the error in that first command because rest run without problem and did not scroll high enough. In that example the error can be solved by either turning the option twostep into one step or by adding additional instruments and then the example code runs. I tried to apply that to your code but there are still remaining errors which means its not just because of that in your case.
1muflon1
CC BY-SA 4.0
2020-10-15T10:00:24.917Z
Believe it or not, the result is the same for me regarding even the example dataset of EmplUK, I have the same problem whether I try to run the Arellano and Bond or Bond and Blundell estimator - nothings happens whatever I change. But, nevertheless, thank you for your time :)
Wadim iLchuk
CC BY-SA 4.0
2020-10-15T10:04:24.773Z
if you will still have problem with that EmplUK data in the first model even after adding instruments or switching to one step then there it’s difficult to say what is the problem consider just posting it on stack overflow in that case that looks more like programming issue
1muflon1
CC BY-SA 4.0
2021-01-27T19:11:37.087Z
@1muflon1, may I ask you another question privately (e.g., via email), or I should create another topic?
Wadim iLchuk
CC BY-SA 4.0
2021-01-27T22:22:26.797Z
if you want you can open private chat here on SE but you can also post it as an another question maybe someone else will be able to help you as well that way
1muflon1
CC BY-SA 4.0
2021-08-04T16:02:48.110Z
Did you find a solution for Arellano and Bond (1991) or Blundell and Bond (1998)?Because I have the same error.
amnay mehlaoui
<production-function><productivity><firm><r><financial-constraints>
Arellano and Bond (1991) or Blundell and Bond (1998) in R estimation
Wadim iLchuk
# Arellano and Bond (1991) or Blundell and Bond (1998) in R estimation

(Asked by: username_0 on 2020-10-13)

I have the following problem with the Arellano and Bond (1991) or Blundell and Bond (1998) estimators in R using the plm package. I receive the following problem when trying to run the needed regression:

The dataset could be found here: https://drive.google.com/file/d/1WUCrMCi7bJmhYbzZxNuXDpFIwXJTqdh3/view?usp=sharing
My code is the following, it seems that I do everything correctly, the formula I need to be estimated is the following: 
remove(list=ls())

library(plm)
library(dplyr)
library(ggplot2)
library(prodest)
library(estprod)
library(broom)
library(pdynmc)

pckg<-c("plm","readxl","dplyr","ggplot2", "broom","prodest", "estprod")
#install.packages(c("plm","readxl","dplyr","ggplot2", "broom","prodest", "estprod"))
lapply(pckg, require, character.only = TRUE)

# Set the working directory
setwd("C:/Users/vadya/Desktop/baka")

# Downloading the survey data
Data <- read.csv("test.csv", header=TRUE, sep=",")
str(Data)

Data$ID<-as.numeric(as.factor(Data$ID))

summary(Data)

DataA11 <- Data %>% 
  filter(NACE == 'A' & Year < 2013) %>% 
  filter(VA > 0, L > 0, FA > 0, M > 0, Turn > 0, TA > 0) %>%
  mutate(ID = ID,
         Year = Year,
         l = log(L),
         va = log(VA),
         fa = log(FA),
         m = log(M),
         turn = log(Turn),
         ta = log(TA),
         ff1 = (LTD + STD)/TA,
         ff2 = lag(Cash),
         ff4 = FA/Sales,
         ff5 = TFA/TA)

####################################################################################

mod2LP <- prodest::prodestLP(DataA11$turn, fX = DataA11$l, sX = DataA11$fa, pX = DataA11$m, idvar = DataA11$ID, timevar = DataA11$Year, 
                             R = 100, cX = NULL, opt = "optim", theta0 = NULL, cluster = NULL, tol = 1e-100, exit = FALSE)  
mod2LP
omegaLP <- prodest::omega(mod2LP)
summary(mod2LP)
summary(omegaLP)

DataA11$omega <- prodest::omega(mod2LP) 

######################################################################################

DataA11 <- DataA11 %>%
  arrange(ID, Year) %>%
  group_by(ID) %>%
  mutate(domega = omega - dplyr::lag(omega),
         debt = LTD + STD,
         ddebt = debt - dplyr::lag(debt),
         dsales = Sales - dplyr::lag(Sales)) %>%
  ungroup

PDataA11 <- pdata.frame(DataA11, index = c("ID","Year"))

pdim(PData)
pvar(PData)

z1 <- pgmm(domega ~ lag(domega, 1:2) + ddebt + ff1 + ff1:ddebt + Age + ta + dsales | lag(domega, 2:99),
           data = PDataA11, effect = "twoways", model = "twosteps")
summary(z1, robust = TRUE)

ALSO! It would be perfect if you provide any information on that package and also what I do incorrectly + would be great if you said how to add fixed effects to this pgmm function.
Thanks a lot to each of you in advance!!!:)
UPDATE:
data("EmplUK", package = "plm")

## Arellano and Bond (1991), table 4 col. b 
emp.gmm <- pgmm(log(emp)~lag(log(emp), 1:2)+lag(log(wage), 0:1)+log(capital)+
                  lag(log(output), 0:1)|lag(log(emp), 2:99),
                data = EmplUK, effect = "twoways", model = "twosteps")
summary(emp.gmm)

I run this code, that is provided here: https://rdrr.io/cran/plm/man/pgmm.html
and I get the following message:

**Tags:** production-function, productivity, firm, r, financial-constraints

> **Comments:**
> **username_1**: This looks like dataset issue rather than code issue per se. Try if the code works with simulated data with longer T. My guess is it will and in this dataset you don’t have enough observations. Also you can get all info there is on pgmm by simply typing ?pgmm into console. Furthermore, it already has twoway fixed effects - that is what the option twoway does. If you want ‘vanilla’ fixed effects then just change argument ‘twoway’ to ‘individual’.  
> **username_0**: Tried not to restrict dataset to only 2011 and 2012 year, and got the following problem: Error: `n` must be a nonnegative integer scalar, not an integer vector of length 2. Then I filtered to get only the positive numbers (which is not logical) and got the next issue: Error in Formula(formula) : inherits(object, "formula") is not TRUE. So, I do not really know how to solve it, despite the fact I have read the documentation of the package.  
> **username_1**: but you are specifying lags for the instrument from 2-99. Last time I was giving you an answer with this dataset I just quickly checked the distribution of temporal dimension among panel IDs and if I remember correctly no ID had more than 9 years associated with it. Also you use lot of control variables and have non-trivial amount of missing observations and the panel is unbalanced I would not be surprised if there simply isn’t in the end enough data points to run the model you want.  
> **username_0**: But, even if I change the number from 99 to whatever 3,4,5,6... the problem is the same Error in Formula(formula) : inherits(object, "formula") is not TRUE. Also, If I try to use the same example as in pgmm function description with EmplUK dataset, the result is the same Error: n must be a nonnegative integer scalar, not an integer vector of length 2. Run rlang::last_error() to see where the error occurred.  
> **username_1**: then there might be some additional errors in the specification. However, I tried to run pgmm on a different panel dataset that is balanced and has long T worked fine for me and I tried to also use interaction terms so that is not the problem. As I originally recommended you should simulate a new dataset with long T. Keep the variable names and everything in the command same. See if it runs with simulated data. If it works with simul. data problem is not in command but with dataset. In that case double check all variables are properly declared and try running MVA and possibly  imputation  
> **username_0**: Yes, I tried to run the same command but with the author's dataset provided, and got the same problem  
> **username_1**: can you update that in your answer I might take a look at it and try if I can replicate the trouble because I think for me the datasets that come with the command worked without any issue. Otherwise this could also easily be due to outdated R some packages are built under new versions the 4.0.0 and later versions changed the way how R works in non-trivial ways  
> **username_0**: Updated, I run the code from "UPDATE" right after the first part of the code  
> **username_1**: Oh I originally not noticed the error in that first command because rest run without problem and did not scroll high enough. In that example the error can be solved by either turning the option twostep into one step or by adding additional instruments and then the example code runs. I tried to apply that to your code but there are still remaining errors which means its not just because of that in your case.  
> **username_0**: Believe it or not, the result is the same for me regarding even the example dataset of EmplUK, I have the same problem whether I try to run the Arellano and Bond or Bond and Blundell estimator - nothings happens whatever I change. But, nevertheless, thank you for your time :)  
> **username_1**: if you will still have problem with that EmplUK data in the first model even after adding instruments or switching to one step then there it’s difficult to say what is the problem consider just posting it on stack overflow in that case that looks more like programming issue  
> **username_0**: @username_1, may I ask you another question privately (e.g., via email), or I should create another topic?  
> **username_1**: if you want you can open private chat here on SE but you can also post it as an another question maybe someone else will be able to help you as well that way  
> **username_2**: Did you find a solution for Arellano and Bond (1991) or Blundell and Bond (1998)?Because I have the same error.  

---

## 0 answers

