# GMM Estimation and convergence problem

I try to minimize an unweighted moment function $G(\theta)$ given by $G(\theta) = \bar{g}(\theta)'\bar{g}(\theta)$.

$g(\theta,x_i)$ contains the specified moment conditions, where we state $E(g(\theta_0, x_i))=0$ and $\bar{g}(\theta) = N^{-1}\sum_{i=1}^N g(\theta,x_i)$.

R provides a GMM tool with gmm() that works fine to handle the problem.

Example:

Take the example in Chaussé (2010) where he presents the GMM estimation of the parameters of a normal distribution:

    library(gmm)

set.seed(123)
n <- 2000
x1 <- rnorm(n, mean = 4, sd = 2)

g1 <- function(tet,x)  # Moment function
{

m1 <- (tet-x)     # 1st moment E[mu - xi] = 0
m2 <- (tet^2 - (x - tet)^2)  # 2nd moment E[sig^2 - ( x_i - mu)^2] = 0

m <- cbind(m1,m2)
return(m)
}

print(res <- gmm(g1,x1,c(mu = 0, sig = 0), optfct = "optim", wmatrix = "ident" , tol = 0.01 )  )


However, when specifying manually the unweighted moment function $G(\theta)$ and using an optimization tool like optim() estimates are far from the true values ($\mu = 4$ and $\sigma = 2$), as I run into convergence problems.

Example:

gg <- function(tet){

gv <- as.matrix(colMeans(g1(tet, x = x1)))

t(gv)%*%gv

}

start.values = c(0,0)
gg_est <- optim(start.values , gg, method = "BFGS", control = list(maxit = 10000, abstol = 0.01, reltol = 0.01) )
summary(gg_est)
gg_est\$par


Any idea what I miss here?