繁体   English   中英

仪器的R矩估计的广义方法

[英]R Generalized Method Of Moments Regression Estimation With Instruments

我正在尝试使用R中的广义矩方法训练回归模型。我有3个内生回归变量,它们与6个我所知的外生变量相关。

  • 我的结果变量是y
  • 我有3个内生回归变量:z1,z2,z1 * z2
  • 我有6种外部工具:x1,x2,x3,x4,x5,x6

为了进行培训,我将数据设置在data.matrix dat 第一列为y,第二列均为1,第三至第八列为工具x1-x6。 第9到第11列是回归变量(z1,z2和z1 * z2)。

然后我将矩条件设置如下:

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))
}

然后尝试训练模型:

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

运行此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出现错误: 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

该错误表明x的秩不够大,无法估计与z对应的变量的系数。

但是当我检查Matrix::rankMatrix(dat[,3:8])告诉我x的排名为5时,而Matrix::rankMatrix(dat[2,9,10,11])告诉我z的排名为4。 , rankMatrix(t(x) %*% z )得出4。对于我来说,这些值对于GMM似乎很好。 我究竟做错了什么?

我也尝试使用plm pgmm ,但是我的数据实际上只是一个横截面(而不是面板数据集),当我尝试使用它时,由于每个人有多个观察值而出现错误。

dat看起来像:

     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是[30-100]中的整数x2是二进制0,1 x3取两个值x4取两个值x5取两个值x6取两个值

z1是二进制0,1 z2在[0,1]中是连续的

尝试了许多不同的事情后,什么工作一度下探变量x,直到变量x的数量为基质,包括所有的人都为列排名:看来gmm不喜欢有在使用外源性仪器的矩阵中的任何奇异当下条件。 明确地,当我更改为这组矩条件时,相同的gmm调用起作用了:

moments <- function(theta, data) {
    y <- as.numeric(data[, 1])
    x <- data.matrix(data[, c(2,3,4,5,6)]) # this is rank 5 still
    z <- data.matrix(data[, c(2,9,10,11)]) # rank 4
    m <- x * as.vector((y - z %*% theta))
    return(cbind(m))
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM