%load_ext autoreload
import pyfixest as pf
import statsmodels.formula.api as smf
import numpy as np
= pf.get_data() data
Quantile Regression
PyFixest now experimentally supports quantile regression!
Basic Example
Just as in statsmodels
, the function that runs a quantile regression is quantreg()
.
Below, we loop over 10 different quantiles.
%%capture
= [pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = q) for q in np.arange(0.1, 1, 0.1)] fits
We can inspect the quantile regression results using the dedicated qplot()
function.
= 2) pf.qplot(fits, nrow
(<Figure size 960x576 with 4 Axes>,
array([<Axes: title={'center': 'Intercept'}, xlabel='Quantile', ylabel='Coefficient (95 % CI)'>,
<Axes: title={'center': 'X1'}, xlabel='Quantile', ylabel='Coefficient (95 % CI)'>,
<Axes: title={'center': 'X2'}, xlabel='Quantile', ylabel='Coefficient (95 % CI)'>,
<Axes: title={'center': 'f1'}, xlabel='Quantile', ylabel='Coefficient (95 % CI)'>],
dtype=object))
We observe some heterogeneity in the Intercept, but all other variants are homogeneous across users.
Inference
pf.quantreg
supports heteroskedasticity-robust inference (“nid”) and cluster robust inference following Parente & Santos Silva. See this slide set or the Journal of Econometrics paper for details.
= pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = 0.5, vcov = "nid")
fit_nid = pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = 0.5, vcov = {"CRV1": "f1"}) fit_crv
/home/runner/work/pyfixest/pyfixest/pyfixest/estimation/quantreg/quantreg_.py:75: FutureWarning: The Quantile Regression implementation is experimental and may change in future releases.
warnings.warn(
/home/runner/work/pyfixest/pyfixest/pyfixest/estimation/quantreg/quantreg_.py:75: FutureWarning: The Quantile Regression implementation is experimental and may change in future releases.
warnings.warn(