py-econometrics / pyfixest

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

Help fail `tidy` gracefully if model is intercept only #702

Open leostimpfle opened 1 week ago

leostimpfle commented 1 week ago

Fitting an intercept only model, e.g., "Y ~ 1 | f1 + f2" will make the tidy method fail ungracefully because of an error in get_inference: ValueError: diag requires an array of at least two dimensions

It would be nice to catch the intercept-only case at an earlier stage in tidy (or maybe get_inference?) to avoid throwing hard-to-understand errors in get_inference.

Minimal working example:

import pyfixest as pf
data = pf.get_data(N=1000, seed=0, beta_type="2", error_type="2", model="Feols" )
feols = pf.feols("Y ~ 1 | f1 + f2", data )
feols.coef()
s3alfisc commented 1 week ago

Yep, very good point. This should also apply to a couple of other methods, i.e. summary(), etable(), coefplot() etc.

The error occurs because fitting a model with fixed effects and an intercept only never actually "fits" the model as there are no "coefficients" to fit and in consequence to display - it's mostly supported to allow users to residualize a variable by fixed effects without having to go down to the demean() function.