R Generalized Method Of Moments Regression Estimation With Instruments

0 votes

I'm trying to train a regression model using the generalized method of moments in R. I have 3 endogenous regressors that are correlated with 6 things I know to be exogenous.

  • My outcome variable is y
  • I have 3 endogenous regressors: z1, z2, z1*z2
  • I have 6 exogenous instruments: x1, x2, x3, x4, x5, x6

In order to do the training I set my data up in an data.matrix dat. The first column is y, the second column is all 1s, the third through eighth columns are the instruments x1-x6. The 9th through 11th columns are the regressors (z1, z2, and z1*z2).

Then I set my moment conditions as follows:

moments <- function(theta, data) {
    y <- as.numeric(data[, 1])
    x <- data.matrix(data[, c(2,3:8)])
    z <- data.matrix(data[, c(2,9,10,11)])
    m <- x * as.vector((y - z %*% theta))
    return(cbind(m))
}

and then I try to train my model:

gmm_model <- gmm(
  g = moments,
  x = dat,
  t0 = (lm(y ~ z1 + z2 + z1:z2,
           data=dat))$coefficients
)

When I run this I get an error: model order: 1 singularities in the computation of the projection matrix results are only valid up to model order 0Error in AA %*% t(X) : requires numeric/complex matrix/vector arguments

The error indicates that the rank of x is not big enough to estimate the coefficients on the variables corresponding to z.

But when I check Matrix::rankMatrix(dat[,3:8]) tells me my x has rank 5 and Matrix::rankMatrix(dat[2,9,10,11]) tells me my z has rank 4. Additionally, rankMatrix(t(x) %*% z ) yields 4. These values seem to be fine for GMM to me. What am I doing wrong?

I also tried to use pgmm from plm, but my data is really just a cross section (not a panel dataset) and I was getting errors for having multiple observations per individual when I tried to use it.

dat looks like:

     y i x1 x2  x3   x4     x5      x6 z1        z2 z1*z2
[1,] 0 1 31  0 123 0.12 123456 1234567  0 0.2954545     0
[2,] 0 1 44  0 123 0.12 123456 1234567  0 0.1555556     0
[3,] 0 1 31  0 123 0.12 123456 1234567  0 0.2325581     0
[4,] 0 1 47  0 123 0.12 123456 1234567  0 0.2537313     0
[5,] 0 1 33  0 123 0.12 123456 1234567  0 0.1500000     0
[6,] 0 1 49  0 123 0.12 123456 1234567  0 0.2553191     0

x1 is an integer in [30-100] x2 is binary 0,1 x3 takes two values x4 takes two values x5 takes two values x6 takes two values

z1 is binary 0,1 z2 is continuous in [0,1]

Apr 11 in Machine Learning by Dev
• 6,000 points
117 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

R - plm regression with time in posix-format

To use in your model, I believe ...READ MORE

answered Apr 4 in Machine Learning by Nandini
• 5,480 points
134 views
0 votes
1 answer

Plotting logistic regression in R with the Smarket dataset

The first, third, and fourth methods of ...READ MORE

answered Apr 12 in Machine Learning by Dev
• 6,000 points
176 views
0 votes
1 answer

How to add regression line equation and R2 on graph?

Below is one solution: # GET EQUATION AND ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,240 points
6,027 views
0 votes
1 answer

Modular programming in R language

R provides support to create subscripts. For ex. ...READ MORE

answered Jan 31, 2019 in Data Analytics by Tyrion anex
• 8,690 points
337 views
0 votes
1 answer

How to export regression equations for grouped data?

First, you'll need a linear model with ...READ MORE

answered Mar 14 in Machine Learning by Dev
• 6,000 points
63 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP