Closed StatPhil closed 4 years ago
This seems to be an issue with plm rather than clubSandwich:
example.of.problem <- function(){
require(plm)
# require(clubSandwich)
our.data <- iris
model.output <- plm(formula = "Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width", data = our.data, model = "within", index = "Species")
# vcovCR(model.output, cluster = our.data$Species, type="CR1S")
model.output
}
example.of.problem()
#> Loading required package: plm
#> Loading required package: Formula
#> Error in pFormula(formula): inherits(object, "formula") is not TRUE
Well, it is a input error: the argument formula
should not be a character. Just take:
model.output <- plm(formula = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data = our.data, model = "within", index = "Species")
...and jepusto's example derived from the original post works on my side.
Calling vcovCR() on a plm object does not work properly when it's called within a function.
Here's a reproducible example:
This results in an error message, whereas running the code that's inside the function works just fine if it's not inside a function.