py-econometrics / pyfixest

Fast High-Dimensional Fixed Effects Regression in Python following fixest-syntax
https://py-econometrics.github.io/pyfixest/pyfixest.html
MIT License
117 stars 27 forks source link

Inference: Support `fixef_k = "nested"` for small sample correction in `ssc()` for identical standard errors with `fixest` #501

Open s3alfisc opened 2 weeks ago

s3alfisc commented 2 weeks ago

Context

At the moment, PyFixest's standard errors differ slightly from fixest defaults (explainer here).

This is because fixef_k = "nested" is not implemented in PyFixest - in contrast to fixest, the default argument of the ssc() function is fixef_k = "none" instead of "nested".

Per the fixest docs, "fixef.K="nested" discards all coefficients of fixed effects nested within clusters" when computing the number of coefficients $k$ for small sample corrections, while "fixef.K="none" discards all fixed-effects coefficients".

For examples of what is meant by a fixed effect nested in a cluster, take a look at the fixest vignette.

Image

Image

Task

Add the following variants to the fixef_k function argument of the https://github.com/py-econometrics/pyfixest/blob/a98a9b92dfead109ab96c01f494c2d194c516165/pyfixest/utils/utils.py#L11 function:

Add unit tests against fixest.

Change the default to ssc(fixef_k = "nested"), mirroring fixest.

Note that this introduces a breaking change to the PyFixest results - all default standard errors will deviate slightly.

valak70 commented 2 weeks ago

Hi @s3alfisc, I'm not familiar with fixest but what I understood is replacing fixef_k: str = "none" to fixef_k: str = "nested" will fix this