I am running spatial panel models (using splm) of census tracts in the U.S. between 1990 and 2010 with neighbor matrices based upon distance or contiguity. But I also want to cluster the standard errors on the city the census tract is within.
Within panel models (plm) there is a way to do this (with the postestimation function "vcovHC" and then "coeftest" (see here)) but I do not see and have not been able to find a way to do this with a splm object. When I run the same code, I receive the error "Error in terms.default(object) : no terms component nor attribute."
There are a lot of questions about clustering with other models, but none with the splm package, so any help is greatly appreciated.
This can be done in Stata with the XSLME package and including: vce(cluster "group_var") at the end of the call, but with 37k+ cases over 3 panels, Stata crashes.
A hypothetical example with the same problem is below:
library(splm)
library(spdep)
data("Insurance")
data(itaww)
sw <- mat2listw(itaww)
myformula <- rgdp ~ agen + school + fam
myresults <- spml(myformula,
data = Insurance,
listw = sw,
model = "within",
lag = FALSE,
effect = "individual",
spatial.error = "b")
summary(myresults)
results_vcov <- vcovHC(myresults, type = "HC0", cluster = "group")
## same thing but with plm
library(plm)
myplmresults <- plm(myformula,
data = Insurance,
model = "within")
summary(myplmresults)
results_vcov <- vcovHC(myplmresults, type = "HC0", cluster = "group")
library(lmtest)
coeftest(myplmresults, vcov = results_vcov)