I am trying to estimate a model with the GMM library from R. However, when I run my code I am getting the error "requires numeric/complex matrix/vector arguments". I converted my Data Frame to a matrix as suggested in multiple similar questions but I'm still getting the same error, any ideas on how to solve the issue? I know the model is very simple but I was trying to get to understand how the command works. The data that I am loading is all numeric, I've tested it with the mode (X) function.
library(gmm) # For gmm
data_r <- data.frame(replicate(7,sample(0:5,1000,rep=TRUE)))
g <- function(theta, data_r){
y <- as.numeric(data_r[, "X1"])
x <- as.matrix(data_r[,c("X2", "X3", "X4", "X5")])
z <- as.matrix(data_r[,c("X2", "X6", "X4", "X7")])
# Moment conditions
m1 <- z * as.vector(y - x %*% theta)
return(cbind(m1))
}
g_test <- gmm(g, data_r)
summary(g_test)
Which returns an error:
Error in x %*% theta: requires numeric/complex matrix/vector arguments
id <- "1EP3odZcVbNCSMZYAgbEtMV5_2oB8nRHl" ; data_r <- read.csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id))
but what if you deleted that file later on. Then as I explained, the question won't be useful to future readers.gmm(g, data_r, t0 = rep(0, 4))
?