gmm estimation error

╄→гoц情女王★ 提交于 2019-12-11 23:20:59

问题


In estimating GMM with more than one independent variables, The codes are

    do_gmm <- function(X)
 {
      DE <- X[, "DE"]
      rmrf_local <- X[, "rmrf_local"]
      SMB_L <- X[,"SMB_L"]
      h <- cbind(as.numeric(DE,rmrf_local,SMB_L))
      coef(gmm(DE ~ rmrf_local,~SMB_L, x = h))
    }

    r <- rollapplyr(ALLX0, 24, do_gmm, by.column = FALSE, fill = NA)

The code works but in the output, i have only the first variable as follows

> r
       (Intercept)  rmrf_local
  [1,]          0.21        -0.32
  [2,]          0.32        -0.04
  [3,]         -0.43        -0.03
  [4,]         -0.42        -0.23

I NEED SOME THING LIKE

> r
       (Intercept)  rmrf_local     SMB_L
  [1,]          0.21        -0.32   0.34
  [2,]          0.32        -0.04   0.01
  [3,]         -0.43        -0.03   0.21
  [4,]         -0.42        -0.23   0.12

I don't know why, the second variable is missed in the output. Any idea please?


回答1:


Finally, i have solved it as follows

      do_gmm <- function(X) {
      DE <- DE[,1]<- X[, "DE"]
      rmrf_local <- X[, "rmrf_local"]
      SMB_L <- X[,"SMB_L"]
      HML_L <- X [, "HML_L"]
     h <- cbind(rmrf_local,SMB_L, HML_L)
      coef(gmm(DE ~ rmrf_local+SMB_L+HML_L, x = h))
    }

    r <- rollapplyr(ALLX0, 24, do_gmm, by.column = FALSE, fill = NA)
    r <- data.frame(r)
    r
 #   X.Intercept.   rmrf_local        SMB_L         HML_L
#1  -5.555761e-02  0.022837356 -0.937533698 -0.0424317893
#2  -4.264533e-02  0.032031878 -0.793814606 -0.0856941501
#3  -4.468413e-02  0.023003578 -0.789339020 -0.0968315078
#4  -5.088025e-02  0.028099687 -0.866812624 -0.0189772617


来源:https://stackoverflow.com/questions/50683535/gmm-estimation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!