0

我正在尝试将包中的pgmm功能用于. 回归运行,我可以调用结果,但是,要求摘要给出以下错误:plmR

Error in t(y) %*% x : non-conformable arguments

我使用 WDI 包从世界银行导入了数据:

library(plm) # load package
library(WDI) # Load package
COUNTRIES <- c("AGO","BEN","BWA","BFA","BDI") # Specify countries
INDICATORS <- c("NY.GDP.PCAP.KN", "SP.DYN.TFRT.IN", "SP.DYN.CBRT.IN", "SP.POP.TOTL") # Specify indicators
LONG <- WDI(country=COUNTRIES, indicator=INDICATORS, start=2005, end=2009, extra=FALSE) # Load data
PANEL <- pdata.frame(LONG, c("iso2c","year")) # Transform to PANEL dataframe
PANEL$year <- as.numeric(as.character(PANEL$year)) # Encode year
EQ <- pgmm( log(fertility) ~ log(gdp) + lag(log(fertility), 2) | lag(log(fertility), 2), data=PANEL, effect="twoways", model="twosteps", gmm.inst=~log(fertility) ) # Run regression

调用结果如下。

EQ

但是摘要(如下)给出了上面提到的错误消息。

summary(EQ)
4

1 回答 1

4

我认为发生错误是因为summary.pgmm尝试对您的数据进行序列相关性的二阶 Arelland-Bond 测试,但您的数据只有两个点(2008 年和 2009 年),所以它失败了。

要解决此问题,您可以修补该函数,使其检查数据集中是否只有两个点,并仅在您有两个以上点时运行测试。我在下面提供了一个修补功能:

summary.pgmm.patched <- function (object, robust = FALSE, time.dummies = FALSE, ...) 
{
    model <- plm:::describe(object, "model")
    effect <- plm:::describe(object, "effect")
    transformation <- plm:::describe(object, "transformation")
    if (robust) {
        vv <- vcovHC(object)
    }
    else {
        vv <- vcov(object)
    }
    if (model == "onestep") 
        K <- length(object$coefficients)
    else K <- length(object$coefficients[[2]])
    Kt <- length(object$args$namest)
    if (!time.dummies && effect == "twoways") 
        rowsel <- -c((K - Kt + 1):K)
    else rowsel <- 1:K
    std.err <- sqrt(diag(vv))
    b <- coef(object)
    z <- b/std.err
    p <- 2 * pnorm(abs(z), lower.tail = FALSE) 
    CoefTable <- cbind(b, std.err, z, p)
    colnames(CoefTable) <- c("Estimate", "Std. Error", "z-value", 
        "Pr(>|z|)")
    object$CoefTable <- CoefTable[rowsel, , drop = FALSE]
    object$sargan <- sargan(object)
    object$m1 <- plm:::mtest(object, 1, vv)

    # The problem line:
    # object$m2 <- mtest(object, 2, vv) 

    if (length(object$residuals[[1]] ) > 2) object$m2 <- plm:::mtest(object, 2, vv) 
    object$wald.coef <- plm:::wald(object, "param", vv)
    if (plm:::describe(object, "effect") == "twoways") 
        object$wald.td <- plm:::wald(object, "time", vv)
    class(object) <- "summary.pgmm"
    object
}

您可能想写信给plm包的作者并向他展示这篇文章。作者将能够编写一个不那么“hacky”的补丁。

使用您自己的(稍作修改的)示例数据,您将如何使用该函数:

library(WDI) # Load package
library(plm)

COUNTRIES <- c("AGO","BEN","BWA","BFA","BDI") # Specify countries
INDICATORS <- c("NY.GDP.PCAP.KN", "SP.DYN.TFRT.IN", "SP.DYN.CBRT.IN", "SP.POP.TOTL") #     Specify indicators
LONG <- WDI(country=COUNTRIES, indicator=INDICATORS, start=2005, end=2009, extra=FALSE) #     Load data
PANEL <- pdata.frame(LONG, c("iso2c","year")) # Transform to PANEL dataframe
PANEL$year <- as.numeric(as.character(PANEL$year)) # Encode year
names(PANEL) [c(4,5)] = c('gdp','fertility')
EQ <- pgmm( log(fertility) ~ log(gdp) + lag(log(fertility), 2) | lag(log(fertility), 2),     data=PANEL, effect="twoways", model="twosteps", gmm.inst=~log(fertility) ) # Run regression

summary.pgmm.patched(EQ)
于 2012-04-13T15:14:19.603 回答