Skip to content

Instantly share code, notes, and snippets.

@pachevalier
Created July 30, 2013 10:48
Show Gist options
  • Select an option

  • Save pachevalier/6111962 to your computer and use it in GitHub Desktop.

Select an option

Save pachevalier/6111962 to your computer and use it in GitHub Desktop.
This gist compare the results of the gmm() and the lm() function in R using simulated data.
library("gmm")
set.seed(1234567)
N <- 1000
dd <- data.frame(id = 1:N)
dd$u <- rnorm(N)
dd$x <- 1 + rnorm(N)
dd$y <- 1 + dd$x + dd$u
m1 <- lm(y ~ x, data = dd)
m2 <- gmm(y ~ x, x = ~ x, wmatrix = "ident", data = dd)
coefficients(m1)
coefficients(m2)
sqrt(diag(vcov(m1)))
sqrt(diag(vcov(m2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment