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

Add support for two-way clustering #25

Closed
s3alfisc opened this issue Mar 15, 2023 · 4 comments
Closed

Add support for two-way clustering #25

s3alfisc opened this issue Mar 15, 2023 · 4 comments
Labels
good first issue Good for newcomers
Milestone

Comments

@s3alfisc
Copy link
Member

  • Simply apply vcov() cluster three times: vcov_a + vcov_b - vcov_ab.
  • For ssc, see here.
@s3alfisc s3alfisc added this to the v0.4 milestone Mar 15, 2023
@s3alfisc s3alfisc added the good first issue Good for newcomers label Mar 15, 2023
@aeturrell
Copy link

+1 for this, in my case for product-country two way clustering in fepois.

s3alfisc added a commit that referenced this issue Oct 10, 2023
@s3alfisc
Copy link
Member Author

s3alfisc commented Oct 10, 2023

Update: this is basically done and should only require some unit tests =)

Hi @aeturrell, I have added a skeleton for twoway clustering in case you are under time pressure / need to get results sooner than I will be able to fully implement this. Though I think I can get this done by the end of the week =)

The syntax for twoway clustering would be

fit = fepois("Y ~ X1 + X2", vcov= {'CRV1': "f1+f2"}, data=df)

Alternatively, one could also allow to specify the two clustering variables by a list.

@s3alfisc s3alfisc linked a pull request Oct 12, 2023 that will close this issue
s3alfisc added a commit that referenced this issue Oct 13, 2023
s3alfisc added a commit that referenced this issue Oct 13, 2023
* add support for twoway clustering #25
* CRV3 inference for poisson #157 (#185)
@s3alfisc
Copy link
Member Author

s3alfisc commented Oct 13, 2023

This is now possible with version 0.10.3.

from pyfixest.estimation import fepois
from pyfixest.summarize import summary
from pyfixest.utils import get_data

data = get_data(N = 1000, model = "Fepois")
fit_crv1 = fepois("Y ~ X1 + X2 | f1 + f2", data = data, vcov = {"CRV1":"f1+f2"})
fit_crv3 = fepois("Y ~ X1 + X2 | f1 + f2", data = data, vcov = {"CRV3":"f1+f2"})

summary([fit_crv1, fit_crv3])

###

Estimation:  Poisson
Dep. var.: Y, Fixed effects: f1+f2
Inference:  CRV1
Observations:  997

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| X1            |     -0.052 |        0.035 |    -1.502 |      0.133 |  -0.120 |    0.016 |
| X2            |      0.007 |        0.014 |     0.520 |      0.603 |  -0.020 |    0.034 |
---
Deviance: 1066.019
###

Estimation:  Poisson
Dep. var.: Y, Fixed effects: f1+f2
Inference:  CRV3
Observations:  997

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5 % |   97.5 % |
|:--------------|-----------:|-------------:|----------:|-----------:|--------:|---------:|
| X1            |     -0.052 |        0.038 |    -1.375 |      0.169 |  -0.126 |    0.022 |
| X2            |      0.007 |        0.015 |     0.480 |      0.631 |  -0.022 |    0.036 |
---
Deviance: 1066.019

So I am closing this for now. Let me know if you experience any issues / would prefer another syntax @aeturrell =)

@aeturrell
Copy link

Oh wow, amazing, thank you so much. Great timing too! Need this this week.

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

Successfully merging a pull request may close this issue.

2 participants