# How to use gmm() from the R gmm package?

#### cbrunos

##### New Member
I'm trying to estimate an econometric model with the gmm package. I'm having a hard time understanding the syntax to build the matrix of moments. You can find the code here: http://pastebin.com/z7Ugx6ge

You can find the data here: https://copy.com/9JVKUV9FWd4p , it's taken from the book "A guide to modern econometrics" by Verbeek. The way I understand I need to build the matrix:

First create an empty matrix and then fill it by columns. For the first column, fill it with the moment condition for the intercept, and for the rest of the columns, fill them one by one with each moment condition for each parameter theta.

Any comment or remark is appreciated.

P.S.: The goal is not the estimate this model per se. I'm working on a paper where I need to use gmm to estimate the parameters of an utility function, but I wanted to first know how to use it on a toy data set.

P.P.S.: I did of course the examples that come in the vignette of the package, but they are very simple and don't explain clearly what you ought to do when you try to estimate more parameters than just one or two.

#### cbrunos

##### New Member
Here is an example that works on simulated data:

Code:
set.seed(120)
x2 <- rnorm(400)
set.seed(121)
x3 <- rnorm(400)
set.seed(21)
x4 <- rnorm(400)
set.seed(124)
y2 <- 2 + 4*x2 + 8*x3 + 12*x4 + rnorm(400)

dat2 <- as.matrix(cbind(1,x2,x3,x4))

mom<-function(theta,dat)
{
m <- array(0,dim=c(400,4))
for (i in 1:4){
m[,i] <- dat[,i]*(y2-dat[,i]*theta[i])
}
return(m)
}

summary(gmm(mom,x=dat2,t0=c(1,2,3,4)),type="cue")
I rewrote the example I put on pastebin like this, but it still doesn't work. I'm starting to think that there's an obscure issue with the data set.