Question

I am trying to use the pgmm function from the plm package for R. The regression runs and I can call up the results, however, asking for the summary gives the following error:

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

I've imported the data from the World Bank using the WDI package:

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

Calling the results as follows works.

EQ

But the summary (below) gives the error message mentioned above.

summary(EQ)
Was it helpful?

Solution

I think the error occurs because summary.pgmm tries to do a second order Arelland-Bond test of serial correlation on your data, but your data only have two points (2008 and 2009) so it fails.

To fix this problem, you could patch the function so that it checks whether you only have two points in the data set and runs the test only if you have more than two points. I provide a patched function below:

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
}

You might want to write to the author of the plm package and show him this post. The author will be able to write a less 'hacky' patch.

Using your own (slightly modified) example data, here is how you would use the function:

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top