# Generalized method of moments estimation in R with plm and gmm

I am interested in using some of the additional features in the gmm package in R to estimate GMM in panel data. Specifically, I am interested in first estimating difference GMM and then later on estimating a collapsed version of system GMM with panel data. As a short cut, and as a way to minimize error, instead of hassling with prepping the data and ensuring it is correct etc..., I was going to rely on the pgmm function in the plm package to prep the data. Below is a demonstration of what I mean...

library(plm)
library(gmm)
data("EmplUK", package = "plm")
## prep the data by running pgmm
mod1 <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0)
+ log(capital) + lag(log(output), 0) | lag(log(emp), 3:99)  ,
data = pdata.frame(EmplUK, c("firm", "year")),
transformation = "d",collapse=TRUE,
effect = "twoways", model = "twostep")
## combine the data
x <-data.frame(do.call("rbind", mod1$model)) z <- data.frame(do.call("rbind", mod1$W))
mod2 <- gmm(log.emp. ~ 0+., z, data = x, type="twoStep")


My hope is that the results would be closer to one another. Here are the results from pgmm

Residuals:
Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
-0.7155767 -0.0386309  0.0000000 -0.0003097  0.0409038  0.8517571

Coefficients:
Estimate Std. Error z-value  Pr(>|z|)
lag(log(emp), 1:2)1  0.520252   0.430801  1.2076 0.2271864
lag(log(emp), 1:2)2  0.659294   0.345804  1.9066 0.0565780 .
lag(log(wage), 0)   -0.685434   0.219737 -3.1193 0.0018126 **
log(capital)         0.260244   0.071666  3.6313 0.0002820 ***
lag(log(output), 0)  0.485892   0.146357  3.3199 0.0009005 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Sargan test: chisq(4) = 2.066723 (p-value = 0.72349)
Autocorrelation test (1): normal = 0.00104534 (p-value = 0.99917)
Autocorrelation test (2): normal = -1.871779 (p-value = 0.061237)
Wald test for coefficients: chisq(5) = 49.32682 (p-value = 1.9028e-09)
Wald test for time dummies: chisq(6) = 8.3523 (p-value = 0.21341)


and here are the results from gmm

Coefficients:
Estimate     Std. Error   t value      Pr(>|t|)
lag.log.emp...1.2.1   0.53098523   0.33758288   1.57290331   0.11574121
lag.log.emp...1.2.2   0.53381789   0.32472310   1.64391722   0.10019330
lag.log.wage...0.    -0.70190873   0.25038291  -2.80334126   0.00505761
log.capital.          0.26874508   0.07083527   3.79394423   0.00014827
lag.log.output...0.   0.53425632   0.15994995   3.34014682   0.00083734


The point estimates are close, but the standard errors are a little off. The weighting matrices are both off as well. Maybe my understanding of the packages and of GMM is incorrect, but would anyone else have any idea what is causing the differences between these two results. I would expect there to be some variation due to optimization differences, but other work (https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2896087) involving the comparison of GMM in two different languages and across packages is able to generate fairly consistent results. I am wondering if I am missing something here and if anyone could provide some clarity.

## migrated from stackoverflow.comApr 4 '18 at 23:49

This question came from our site for professional and enthusiast programmers.