EIDTED!数据结构是

> str(ALLX)
'data.frame':   240 obs. of  21 variables:
 $ Date      : Factor w/ 240 levels "1998-01-01","1998-02-01",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ IM        : num  0.00289 0.00992 -0.00424 0.07958 -0.035 ...
 $ rmrf_local: num  -0.1418 -0.0546 -0.0946 0.0304 -0.1025 ...
 $ SMB_L     : num  -0.0465 -0.0698 0.0274 -0.0741 0.0317 ...
 $ HML_L     : num  -0.1266 -0.191 -0.1408 -0.0122 -0.064 ...
 $ MOM_L     : num  0.0518 0.0127 0.0448 0.0163 0.0151 ...
 $ bond_L    : num  -0.116 -0.128 -0.126 -0.117 -0.123 ...

按照下面的代码,我能够估计滚动gmm函数 .

> gmm_list_IM <-  lapply(1:(length(ALLX$IM)-24), function(i) {
+   tmp <- ALLX[i:(i+23),]
+   IM <- as.matrix(as.numeric(tmp$IM))
+   p <- nrow(IM) 
+   rmrf_local <- as.matrix(as.numeric(tmp$rmrf_local))
+   SMB_L <- as.matrix(as.numeric(tmp$SMB_L))
+   HML_L <- as.matrix(as.numeric(tmp$HML_L))
+   MOM_L <- as.matrix(as.numeric(tmp$MOM_L))
+   bond_L <- as.matrix(as.numeric(tmp$bond_L))
+   h <- cbind(rmrf_local,SMB_L,HML_L,MOM_L,bond_L)
+   gmm(IM ~ rmrf_local+SMB_L+HML_L+MOM_L+bond_L, x=h)
+ })

需要计算VIF以检测具有以下错误的多重共线性 .

> vif(gmm_list_IM)
Error in vcov.default(mod) : 
  there is no vcov() method for models of class list
In addition: Warning message:
In is.na(coef(mod)) :
  is.na() applied to non-(list or vector) of type 'NULL'

在滚动回归下,代码到VIF(方差膨胀因子)不起作用,我无法测试多重共线性 . 可能有人对如何有另一种想法?