I am trying to conduct a comparison of coefficient tests across two subsamples. To achieve this, I do the following:
full_model <- lm(y ~ v1*subsample_dummy + fixed_effects, data=df)
reduced_model <- lm(y ~ v1 + subsample_dummy + fixed_effects, data=df)
test <- anova(full_model, reduced_model)
The above gives me the result.
However, I am not sure how to do the same in the situation where I have to cluster the models by, let's say, the year variable.
I can cluster the lm models using the following code:
library(sandwich)
# cluster by year
clustered_se <- vcovCL(full_model, ~ year)
clustered_se1 <- vcovCL(reduced_model, ~ year)
# generate summaries with clustered standard errors
a <- coeftest(full_model, vcov. = clustered_se)
b <- coeftest(reduced_model, vcov. = clustered_se1)
However, the issue remains, as I still cannot do:
anova(a, b)
How to achieve the comparison of coefficient test across subsamples when the model requires standard error clustering?
We can use
sandwich::vcovCLto get essentially the same standard errors likelfe::felm. Let's estimate some models.Comparing the standard errors of est3 with est1,
yields essentially the same.
Thus, and according to a post on Cross validated [1] we could compare models est1 and est2 using an
lmtest::waldtest(there's also alfe::waldtestwhich works differently).Hope this brings you a step further.
BTW: You definitely could file a feature request on this as an issue on the author's GitHub.
Data: