0

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?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Enrico Dace
  • 115
  • 10

1 Answers1

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
Enrico Dace
  • 115
  • 10
  • After two days, you can accept your answer. That will help others who read this question in future. – Mawg says reinstate Monica Jun 05 '18 at 07:26
  • 1
    @Mawg System said after one day! Anyhow, i will do tht. – Enrico Dace Jun 05 '18 at 08:02
  • Maybe they changed it; it certainly used to be two days. The main thing is that you are not afraid to accept your own answer :-) – Mawg says reinstate Monica Jun 05 '18 at 08:25
  • 1
    @Mawg I got you! by the way, let me ask. This solution only provides 'coefficients'. To have other estimated values like R2 or std error, and when i remove `coef` from the 7th line of code, i have an error. `Error in zoo(rval, index(x)[i]) : “x” : attempt to define invalid zoo object` what do you suggest? @Parfait – Enrico Dace Jun 05 '18 at 08:34
  • I suggest that someone who understands this stuff helps you, but that ain't me ;-) I also suggest that you open a second question, rather than turn this into a series of questions. Good luck with it – Mawg says reinstate Monica Jun 05 '18 at 08:51