Quantile Regression

PyFixest now experimentally supports quantile regression!

%load_ext autoreload

import pyfixest as pf
import statsmodels.formula.api as smf
import numpy as np

data = pf.get_data()

Basic Example

Just as in statsmodels, the function that runs a quantile regression is quantreg().

Below, we loop over 10 different quantiles.

%%capture
fits = [pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = q) for q in np.arange(0.1, 1, 0.1)]

We can inspect the quantile regression results using the dedicated qplot() function.

pf.qplot(fits, nrow = 2)
(<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.

fit_nid = pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = 0.5, vcov = "nid")
fit_crv = pf.quantreg("Y ~ X1 + X2 + f1", data = data, quantile = 0.5, vcov = {"CRV1": "f1"})
/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(