Skip to content

Feols: Incorrect Standard Errors for WLS with weights_type = "fweights" and vcov = "hetero" #367

@s3alfisc

Description

@s3alfisc

Example:

%load_ext autoreload
%autoreload 2
import pyfixest as pf

data = pf.get_data()
data_agg = data[["X1", "f1", "f2"]].groupby(["X1", "f1", "f2"]).size().to_frame("count").reset_index()

vcov = "hetero"

fit1 = pf.feols("X1 ~ f1", data = data, vcov = vcov)
fit2 = pf.feols("X1 ~ f1", data = data_agg, vcov = vcov, weights = "count", weights_type="fweights")

pf.etable([fit1, fit2], digits = 6)
"""
                                est1                    est2
------------  ----------------------  ----------------------
depvar                            X1                      X1
------------------------------------------------------------
Intercept     1.026086*** (0.049331)  1.026086*** (0.058791)
f1               0.001125 (0.002973)     0.001125 (0.003530)
------------------------------------------------------------
------------------------------------------------------------
R2                          0.000147                       -
S.E. type                     hetero                  hetero
Observations                     998                     998
------------------------------------------------------------
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001
Format of coefficient cell:
Coefficient (Std. Error)
"""

Note that this is not a problem for iid and CRV inference:

vcov = {"CRV1":"f2"}

fit1 = pf.feols("X1 ~ f1", data = data, vcov = vcov)
fit2 = pf.feols("X1 ~ f1", data = data_agg, vcov = vcov, weights = "count", weights_type="fweights")

pf.etable([fit1, fit2], digits = 6)
"""
                                est1                    est2
------------  ----------------------  ----------------------
depvar                            X1                      X1
------------------------------------------------------------
Intercept     1.026086*** (0.055146)  1.026086*** (0.055146)
f1               0.001125 (0.002904)     0.001125 (0.002904)
------------------------------------------------------------
------------------------------------------------------------
R2                          0.000147                       -
S.E. type                     by: f2                  by: f2
Observations                     998                     998
------------------------------------------------------------
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001
Format of coefficient cell:
Coefficient (Std. Error)
"""

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions