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 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 .
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.
I am pretty used to using R's
plmpackage 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 aplmmodel fitted with first-differences toplm'svcovHC()function to estimated robust variance-covariance matrices:The source code of the
plmpackage shows that thetindmentioned 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 .
The code:
This should throw the error. I have checked many things in the data, like whether the class of the
timevariable is correct, whether it has NAs, among other things. Nothing noticeable. But it is worth stressing that this only happens withmodel="fd". If one tries any other options in parameter, likewithinorrandom, then thevcovHCcommand works as intended and without errors.