Skip to content

Quantile Regression #908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6df109c
POC
s3alfisc May 10, 2025
7806986
quantreg initial
s3alfisc May 25, 2025
971feb8
Merge branch 'master' into quantreg
s3alfisc May 25, 2025
f75965a
add nid support
s3alfisc May 26, 2025
a36a6e6
crv1
s3alfisc May 28, 2025
9d34452
crv1
s3alfisc May 28, 2025
8962991
block a range of inference methods
s3alfisc May 29, 2025
9c48d09
trigger errors
s3alfisc May 29, 2025
bdb2fba
add basic notebook
s3alfisc May 29, 2025
9d5b00a
delete doc changes
s3alfisc May 29, 2025
8242c53
revert more unwanted changes to docs
s3alfisc May 29, 2025
15824e2
docs status quo
s3alfisc May 29, 2025
619b720
summary for quantreg
s3alfisc May 29, 2025
15870dd
solve merge conflicts
s3alfisc Jun 3, 2025
0d745e2
solve merge conflicts
s3alfisc Jun 3, 2025
a6dd034
fix some mypy errors
s3alfisc Jun 3, 2025
aa55c61
delete pfn method for the moment
s3alfisc Jun 3, 2025
654de6d
fix mypy errors
s3alfisc Jun 3, 2025
25a2c1e
implement tests against Stata::qreg2 for crv errors
s3alfisc Jun 8, 2025
c5dd41c
fix crv?
s3alfisc Jun 9, 2025
c33c98d
numba import
s3alfisc Jun 9, 2025
85dce19
it was the small sample corrections / crv
s3alfisc Jun 13, 2025
25af58e
fix linter
s3alfisc Jun 13, 2025
0f3e265
adjust tests
s3alfisc Jun 13, 2025
2a7e2a6
adjust some tests
s3alfisc Jun 13, 2025
b67ecbf
Mild code reorg
s3alfisc Jun 14, 2025
ee4e2a4
no ssc in tests -> better match
s3alfisc Jun 14, 2025
432f6cb
cleanups
s3alfisc Jun 15, 2025
7a80304
fix docs
s3alfisc Jun 15, 2025
019ba9a
run tests on ci + install quantreg in dev env
s3alfisc Jun 15, 2025
f386425
update qreg vignette
s3alfisc Jun 15, 2025
c18efb1
more update to docs
s3alfisc Jun 15, 2025
fe16883
delete coverage xml
s3alfisc Jun 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,491 changes: 0 additions & 5,491 deletions coverage.xml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ website:
text: "Regression Decomposition"
- file: ssc.qmd
text: "On Small Sample Corrections"
- file: quantile-regression.qmd
text: "Quantile Regression"
- text: "Compare fixest & PyFixest"
file: compare-fixest-pyfixest.qmd
- text: "Compare Stata & PyFixest"
Expand Down
3 changes: 3 additions & 0 deletions docs/_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ website:
- reference/estimation.estimation.feols.qmd
- reference/estimation.estimation.fepois.qmd
- reference/estimation.estimation.feglm.qmd
- reference/estimation.estimation.quantreg.qmd
- reference/did.estimation.did2s.qmd
- reference/did.estimation.lpdid.qmd
- reference/did.estimation.event_study.qmd
Expand All @@ -21,6 +22,7 @@ website:
- reference/estimation.feprobit_.Feprobit.qmd
- reference/estimation.fegaussian_.Fegaussian.qmd
- reference/estimation.feols_compressed_.FeolsCompressed.qmd
- reference/estimation.quantreg.quantreg_.qmd
section: Estimation Classes
- contents:
- reference/did.visualize.panelview.qmd
Expand All @@ -29,6 +31,7 @@ website:
- reference/report.dtable.qmd
- reference/report.coefplot.qmd
- reference/report.iplot.qmd
- reference/report.qplot.qmd
- reference/did.visualize.panelview.qmd
section: Summarize and Visualize
- contents:
Expand Down
51 changes: 51 additions & 0 deletions docs/quantile-regression.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "Quantile Regression"
format:
html:
html-table-processing: none
toc: true
toc-title: "On this page"
toc-location: left
---

PyFixest now experimentally supports quantile regression!

```{python}
%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.

```{python}
%%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.

```{python}
pf.qplot(fits, nrow = 2)
```

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](https://www.stata.com/meeting/uk15/abstracts/materials/uk15_santossilva.pdf)
or the [Journal of Econometrics paper](https://repository.essex.ac.uk/8976/1/dp728.pdf) for details.

```{python}
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"})
```
9 changes: 1 addition & 8 deletions docs/quarto_example/QuartoExample.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
#| output: false
import pandas as pd
import pyfixest as pf

data = pf.get_data()

fit1 = pf.feols("Y ~ X1 + X2 | f1", data = data)
fit2 = pf.feols("Y ~ X1 + X2 | f1 + f2", data = data)
fit3 = pf.feols("Y ~ X1 *X2 | f1 + f2", data = data)
fit4 = pf.feols("Y2 ~ X1 + X2 | f1", data = data)
fit5 = pf.feols("Y2 ~ X1 + X2 | f1 + f2", data = data)
fit6 = pf.feols("Y2 ~ X1 *X2 | f1 + f2", data = data)

labels={
"Y": "Wage",
"Y2": "Wealth",
Expand All @@ -53,7 +50,6 @@ labels={
"f1": "Industry",
"f2": "Year"
}

```

# A PyFixest Regression Table
Expand All @@ -65,12 +61,9 @@ As @tbl-main shows, LaTex Tables generated by PyFixest can be easily integrated
#| output: asis
#| echo: false
#| tbl-pos: H

mynotes="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."

tab=pf.etable([fit1, fit2, fit4, fit5],
labels=labels, notes=mynotes, type="tex",
model_heads=["US", "China", "US", "China"])

print(tab)
```
```
Loading
Loading