I am pretty used to using R’s plm
package to fit models with panel data, including first difference models. Today, however, I found myself facing a strange error that is thrown when passing the results of a plm
model fitted with first-differences to plm
‘s vcovHC()
function to estimated robust variance-covariance matrices:
Error in tind[[i]] : subscript out of bounds
The source code of the plm
package available on GitHub shows that the tind
mentioned in the error is an internal time index. That is the only clue we get.
Because I am exactly trying to understand what leads to this issue, I can’t generate simulated data in order to provide a more general minimally reproducible example. But I can share a modified excerpt of my data, and code that, when run, will throw the error.
The data is in file soquestion.csv
, located at: https://filetransfer.io/data-package/sTb50sxx#link
The code:
library(plm)
df <- read.csv("soquestion.csv")
pmodel <- plm(y ~ x1 + x2, data=df, index=c("group", "time"),
model="fd", effect="individual")
vcovHC(pmodel)
This should throw the error. I have checked many things in the data, like whether the class of the time
variable is correct, whether it has NAs, among other things. Nothing noticeable. But it is worth stressing that this only happens with model="fd"
. If one tries any other options in parameter, like within
or random
, then the vcovHC
command works as intended and without errors.
Yuansh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.