Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatability with did2s #136

Closed
michaeltopper1 opened this issue Aug 12, 2023 · 2 comments
Closed

Compatability with did2s #136

michaeltopper1 opened this issue Aug 12, 2023 · 2 comments

Comments

@michaeltopper1
Copy link

Hello!

I am trying to get the fwildclusterboot::boottest function to work with did2s. This used to work in previous versions (I believe in 0.7 it works) of the packages, but has since lost capatability.

Here is a reproducible example using an example from the did2s vignette and the boottest function:

library(fwildclusterboot)
library(did2s)

static <- did2s(df_het,
                yname = "dep_var", first_stage = ~ 0 | state + year,
                second_stage = ~ i(treat, ref = FALSE), treatment = "treat",
                cluster_var = "state")


boottest(static, clustid = c("state"), B = 9999, param = "treat")

Unfortunately, I get the following error: Error in fixest::feols(fml = dep_var ~ 1, data = data, weights = weights_vector, :
Argument 'data' must be either: i) a matrix, or ii) a data.frame. Problem: it is not a
matrix nor a data.frame (instead it is a function).

I believe that this has to do with how boottest is grabbing the data from the fixest object, and in turn, how did2s is storing the data. It looks like did2s is naming the data object as data which boottest can then not find.

Any guidance on a possible workaround? I know I could possibly downgrade the version of fwildclusterboot to something prior, but the speedups from the newer versions make me less inclined to do this.

Thanks!

@s3alfisc
Copy link
Owner

s3alfisc commented Aug 13, 2023

Hi @michaeltopper1 - unfortunately, fwildclusterboot does not work with did2s, and I think that it might not going forward. The issue is that did2s conducts inference based on a GMM procedure, while the wild cluster bootstrap in fwildclusterboot only applies to the OLS case. Maybe I should add a dedicated error message for this use case? But you are definitely right that the error you encounter has something to do with the environments boottest() searches for data =)

If you want to make your inference robust to a small number of (treated) clusters, here are two options: first, you could try out did2s with CRV3 inference, as implemented via my summclust package or sandwich::vcovJK() - this seems to perform almost as good as the wild cluster bootstrap according to MacKinnon, Nielsen & Webb (see their fast and reliable paper). I think you can pass a custom vcov matrix to did2s? Alternatively, fwildclusterboot does support sunab() (as this is nothing but 'fancy OLS') via it's boot_aggregate() function. Yet another option: I have an open PR for etwfe that still needs some final touches + a PR to be merged into fixest. But these are of course only options if you do not have any particular reasons to run did2s vs the other methods.

I hope this helps!

@michaeltopper1
Copy link
Author

Hi @s3alfisc. No worries, and thank you very much for the alternative suggestions! I'll definitely check out your other package summclust.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants