Chapter 8: Quantile Regression
Seeing the whole distribution, not just the average
8. Quantile Regression
8.1 Why a development researcher should care about quantiles
Here is the situation. A microfinance line of credit is rolled out to rural households in northern Portugal. Two years later the data arrive and the impact-evaluation memo is on the desk. Run OLS on log per-capita consumption. The treatment coefficient is positive, statistically significant, and small. Write the memo. The funder reads “the program raised consumption by 3.4 percent on average” and feels fine.
That memo is misleading, possibly in both directions.
Suppose the 3.4 percent average effect breaks down like this: the program raised the 10th percentile of consumption by 9 percent, the median by 4 percent, and the 90th percentile by essentially zero. The average is real, but it buries the entire point of the intervention. A rural-credit program targeted at poverty reduction that disproportionately helps the bottom of the distribution is doing exactly what it was funded to do. Reporting only the mean understates the case to the people writing the next check.
Now suppose the same 3.4 percent average breaks down the other way: the 90th percentile rose by 11 percent, the median by 3 percent, and the 10th percentile by minus 1 percent. Same mean. Catastrophically different program. The credit found its way to households who would have done fine without it, and the poorest got pushed slightly backwards (maybe by debt overhang, maybe by general-equilibrium effects on local prices). That program should be redesigned, not scaled.
OLS cannot distinguish these two worlds. Quantile regression is the tool that does. For anyone working in blended finance, rural development, or any intervention whose raison d’etre is distributional, the conditional mean is at best one summary statistic among many, and at worst actively hostile to the policy question. The honest answer to “did this work” is a function of \tau \in (0,1), not a scalar.
This chapter teaches the reader to estimate that function, plot it, interpret it, defend it under cross-examination, and avoid the four or five places where smart people routinely embarrass themselves with quantile methods.
8.2 The intuition: minimizing a tilted absolute-loss function
OLS is the answer to a specific minimization problem. Given data (y_i, x_i), OLS picks \hat\beta to minimize the sum of squared residuals:
\hat\beta_{\text{OLS}} = \arg\min_\beta \sum_i (y_i - x_i'\beta)^2.
The squared-loss function u^2 is symmetric and convex, and minimizing it recovers the conditional mean E[y \mid x]. That is a theorem, not a convention. Change the loss function and you change what you estimate.
Replace squared loss with absolute loss, |u|, and you get the conditional median. That is already a useful fact (median regression is robust to outliers in y, which OLS notoriously is not). But you can do better by tilting the absolute-value function.
Define the check function at quantile \tau \in (0,1):
\rho_\tau(u) = u \cdot \bigl(\tau - \mathbf{1}\{u < 0\}\bigr) = \begin{cases} \tau \cdot u & \text{if } u \geq 0, \\ (\tau - 1) \cdot u & \text{if } u < 0. \end{cases}
Picture the graph. For u > 0 the function rises with slope \tau. For u < 0 it rises (in the leftward direction) with slope 1-\tau. At \tau = 0.5 the two slopes are equal and the function reduces to absolute value, scaled by one half. At \tau = 0.9, positive residuals (under-predictions) are penalized lightly (slope 0.9) but negative residuals (over-predictions) are penalized heavily (slope 0.1, taken absolutely). So minimizing E[\rho_{0.9}(y - q)] over q pushes q up until only 10 percent of the mass lies above it. That is the 90th percentile.
More formally, for any random variable Y the unconditional \tau-th quantile Q_\tau(Y) solves
Q_\tau(Y) = \arg\min_q E[\rho_\tau(Y - q)].
Replace q with x'\beta, pass to the sample analog, and you have quantile regression. The estimator finds the linear function of x that minimizes asymmetrically-weighted absolute deviations, where the asymmetry \tau is the chosen quantile.
There is nothing magic here. Quantile regression is to OLS what a tilted ruler is to a straight one. You are still doing least-something. You just changed the something.
8.3 The estimator
Formally, given a sample \{(y_i, x_i)\}_{i=1}^n and a target quantile \tau \in (0,1), the Koenker-Bassett quantile regression estimator is
\hat\beta(\tau) = \arg\min_{\beta \in \mathbb{R}^k} \sum_{i=1}^n \rho_\tau\bigl(y_i - x_i'\beta\bigr).
The objective is convex but not differentiable everywhere (the check function has a kink at zero), so closed-form gradient methods will not work. Koenker and Bassett (1978) showed that the problem is a linear program: introduce non-negative variables u_i^+, u_i^- for the positive and negative parts of each residual and the objective becomes linear in (\beta, u^+, u^-) subject to linear equality constraints. Modern solvers (interior-point or simplex) handle this efficiently up to very large n.
The limiting distribution under standard regularity conditions is
\sqrt{n} \bigl(\hat\beta(\tau) - \beta(\tau)\bigr) \xrightarrow{d} \mathcal{N}\bigl(0, \tau(1-\tau) \cdot D^{-1} \Omega D^{-1}\bigr),
where D = E[f_{u \mid x}(0 \mid x) x x'] involves the conditional density of the residual at zero (a quantity called the sparsity) and \Omega = E[x x']. The presence of D is the practical headache: estimating a conditional density at a point requires bandwidth choices and is fragile.
Three honest options for standard errors:
- Bootstrap. Resample observations (or clusters), re-fit at each replication, take the empirical variance. Robust, transparent, computationally expensive but cheap on modern hardware.
- Sparsity estimation. Koenker’s
summary.rq(..., se="iid")plugs in a kernel estimate of D. Fine when residuals are roughly iid; unreliable when they are not. - Powell sandwich. A heteroskedasticity-robust variant that estimates D without assuming iid residuals (
se="nid"inquantreg). Good default for cross-sectional data.
In practice: bootstrap when there is clustering or when n is small enough to make bootstrap feasible (so, almost always in applied work). Powell sandwich when running many specifications and speed matters.
8.4 Reading a quantile-regression plot
The deliverable from a quantile-regression exercise is almost never a table. It is a plot of \hat\beta_k(\tau) against \tau for \tau \in (0,1), with pointwise confidence bands. One plot per coefficient of interest. Usually overlaid with the OLS estimate as a horizontal reference line.
Here is how to read one. Suppose the outcome is log income and the treatment is exposure to a credit program.
- If \hat\beta(\tau) is roughly constant across \tau, the program shifts the entire conditional distribution uniformly. The OLS coefficient and the QR coefficients tell the same story. Fine, move on.
- If \hat\beta(\tau) is downward-sloping (higher at low \tau, lower at high \tau), the program compresses the conditional income distribution. The poor gained more than the rich. This is the headline result for a poverty-targeted intervention.
- If \hat\beta(\tau) is upward-sloping, the program stretches the distribution. The rich gained more. This may still be acceptable (productivity-enhancing investments often do this), but it is not what a rural-credit program is supposed to look like.
- If \hat\beta(\tau) is non-monotone (say, large in the middle and small at the tails), interpretation requires care. Common in programs whose binding constraint relaxes for some households but not others.
Confidence bands matter. A downward-sloping point estimate with bands that overlap horizontally across all \tau is consistent with a uniform effect. The visual impression of “the line slopes down” is not the same as “the effect at \tau = 0.1 is statistically distinguishable from the effect at \tau = 0.9.” Use a formal test (Koenker’s Wald or Khmaladze) before reporting heterogeneity as a finding.
A representative coefficient plot for the credit example would show \tau on the horizontal axis from 0.05 to 0.95, the estimated treatment effect \hat\beta_D(\tau) on the vertical axis with a shaded 95 percent CI, and a horizontal dashed line at the OLS estimate. Three numbers (mean, low quantile, high quantile) replaced by one picture that contains all of them.
8.5 Worked example: distributional effect of a rural credit program
The setup. Rural Portuguese households, n = 8000, observed at baseline and 24 months later. Treatment D_i \in \{0,1\} is exposure to a microfinance line of credit (placement was based on village-level eligibility rules; treat as exogenous conditional on baseline covariates for the worked example; in a real paper you would need an IV or a diff-in-diff design, treated in Section 8.7). Outcome Y_i is log per-capita household consumption at 24 months. Controls: household size, log baseline assets, and district fixed effects.
The model:
Q_\tau(Y_i \mid D_i, x_i) = \alpha(\tau) + \beta(\tau) D_i + \gamma(\tau)' x_i + \delta_{d(i)}(\tau).
The object of interest is \beta(\tau) for \tau \in \{0.1, 0.25, 0.5, 0.75, 0.9\} and, more usefully, for the full grid.
R code
library(quantreg)
library(ggplot2)
library(dplyr)
# df has columns: log_cons, D, hh_size, log_assets, district
# Fit at five quantiles to start
fit5 <- rq(log_cons ~ D + hh_size + log_assets + factor(district),
tau = c(0.10, 0.25, 0.50, 0.75, 0.90),
data = df)
summary(fit5, se = "boot", R = 500)
# Fit over a fine grid for the plot
taus <- seq(0.05, 0.95, by = 0.02)
fit_grid <- rq(log_cons ~ D + hh_size + log_assets + factor(district),
tau = taus, data = df)
sm <- summary(fit_grid, se = "boot", R = 500)
# Standard quantreg coefficient plot (all coefficients at once)
plot(sm, parm = "D")
# A nicer ggplot version, treatment effect only
coef_D <- sapply(sm, function(s) s$coefficients["D", "Value"])
se_D <- sapply(sm, function(s) s$coefficients["D", "Std. Error"])
ols_D <- coef(lm(log_cons ~ D + hh_size + log_assets + factor(district),
data = df))["D"]
plot_df <- data.frame(tau = taus, beta = coef_D, se = se_D) %>%
mutate(lo = beta - 1.96*se, hi = beta + 1.96*se)
ggplot(plot_df, aes(x = tau, y = beta)) +
geom_ribbon(aes(ymin = lo, ymax = hi), alpha = 0.2) +
geom_line(linewidth = 0.8) +
geom_hline(yintercept = ols_D, linetype = "dashed") +
geom_hline(yintercept = 0, linetype = "dotted") +
labs(x = expression(tau),
y = expression(hat(beta)[D](tau)),
title = "Treatment effect on log consumption, by quantile",
subtitle = "Dashed line: OLS estimate. Shaded: 95% bootstrap CI.") +
theme_minimal(base_size = 12)Stata code
* Single-quantile fit
qreg log_cons D hh_size log_assets i.district, quantile(0.5)
* Simultaneous quantile regression with bootstrap SEs
* (allows tests of cross-quantile equality)
sqreg log_cons D hh_size log_assets i.district, ///
quantiles(0.10 0.25 0.50 0.75 0.90) reps(500)
* Test equality of the D coefficient across quantiles
test [q10]D = [q25]D = [q50]D = [q75]D = [q90]D
* Coefficient plot across a fine grid (user-written, ssc install grqreg)
qreg log_cons D hh_size log_assets i.district, quantile(0.5)
grqreg D, ci ols olsci reps(500)Interpreting the output
Suppose the fitted pattern at the five reported quantiles is
| \tau | \hat\beta_D(\tau) | SE |
|---|---|---|
| 0.10 | 0.087 | 0.021 |
| 0.25 | 0.062 | 0.014 |
| 0.50 | 0.041 | 0.011 |
| 0.75 | 0.028 | 0.013 |
| 0.90 | 0.009 | 0.019 |
OLS gives 0.034.
The headline: the credit line raised the 10th conditional percentile of log consumption by roughly 8.7 percent, the median by 4.1 percent, and the 90th percentile by less than 1 percent (and that estimate is not statistically distinguishable from zero). The OLS coefficient of 3.4 percent is a real average effect, but it conceals a substantial compression of the conditional consumption distribution. The Wald test of equality across the five quantiles rejects at the one percent level.
This is the kind of finding that changes the story you can tell. To a Gates Foundation officer or an IFC desk, “the bottom decile gained nine percent” is qualitatively different from “the average household gained three percent.” Same data. Different methods. Different memo.
8.6 Conditional quantiles versus unconditional quantiles (RIF)
A subtle point trips up almost everyone the first time. The \hat\beta(\tau) from quantile regression is the effect of a covariate on the conditional \tau-th quantile, holding the other covariates fixed. It is not, in general, the effect on the unconditional \tau-th quantile of y.
Why does this matter? Because policy questions are usually about the unconditional distribution. “Did the program raise the 10th percentile of rural household income in this district?” is an unconditional question. The conditional 10th percentile (the 10th percentile of y among households with a specific value of x) is a different object.
Firpo, Fortin, and Lemieux (2009) developed recentered influence function (RIF) regression to bridge this gap. The idea is to compute, for each observation, the influence function of the chosen distributional statistic (the unconditional 10th percentile, the Gini coefficient, the 90/10 ratio, the variance of log income, whatever the question requires), then regress that influence function on the covariates. The coefficient gives the marginal effect of a small change in the distribution of x on the statistic.
For the unconditional \tau-th quantile q_\tau of Y, the recentered influence function is
\text{RIF}(y; q_\tau) = q_\tau + \frac{\tau - \mathbf{1}\{y \leq q_\tau\}}{f_Y(q_\tau)},
where f_Y(q_\tau) is the unconditional density of Y at q_\tau (estimated by kernel). Run OLS of \text{RIF}(y_i; \hat q_\tau) on x_i and read the coefficients as marginal effects on q_\tau.
For policy targeting, the RIF coefficient is often the right object. The conditional quantile coefficient answers “for households like this, how does the treatment shift their position?” The RIF coefficient answers “how does the treatment shift the population-level statistic I care about?” Different questions. Sometimes the answers agree, sometimes they do not.
R packages: dineq, Counterfactual (Chernozhukov et al.), or hand-rolled (the RIF is a one-line computation once \hat q_\tau and \hat f_Y are in hand).
8.7 IV quantile regression
The setup so far has assumed exogeneity of the treatment (conditional on covariates). In any real impact evaluation, this assumption is doing heavy lifting, and a serious paper needs an instrument or a quasi-experimental design.
Chernozhukov and Hansen (2005, 2008) developed instrumental-variable quantile regression (IVQR), which recovers the structural quantile treatment effect under a rank-invariance (or rank-similarity) condition: the household’s rank in the potential-outcome distribution does not change with treatment. Under this assumption, the IVQR estimand at quantile \tau is the analog of the LATE at that quantile (the effect on the \tau-th quantile of the latent outcome distribution, identified off the instrument-induced variation).
The estimating equation:
E\bigl[\,\bigl(\tau - \mathbf{1}\{Y \leq D \alpha(\tau) + X' \gamma(\tau)\}\bigr) \cdot \Psi(Z, X)\,\bigr] = 0,
where Z is the instrument and \Psi is a vector of instruments-plus-controls. The estimator is computed by an inverse-quantile search procedure: for a grid of candidate \alpha, fit the standard quantile regression with Y - D\alpha as the outcome on X and Z, and pick the \hat\alpha(\tau) that makes the coefficient on Z closest to zero (the instrument should not enter the conditional quantile of the structural residual).
R packages: IVQR, ivqte (the latter for the related but distinct quantile-treatment-effect framework of Frolich-Melly 2013, which estimates effects on quantiles of the marginal outcome distribution among compliers). Both have GitHub-current implementations as of late 2025.
Stata: this is the place where R wins decisively. There is no maintained official command for IVQR in Stata; user-written ivqregress (Kaplan) handles a related but distinct estimand. If a project needs IVQR, plan to do it in R.
The rank-invariance condition deserves a sentence of caution. It is strong and often violated in development applications (treatment may shuffle the ordering of households by changing who succeeds). The Chernozhukov-Hansen results extend to “rank similarity,” a weaker condition allowing some shuffling on average, but the assumption still binds. State it explicitly in any IVQR paper.
8.8 Common traps
Five places where the literature has watched people stumble.
Fixed effects. Quantile regression with high-dimensional fixed effects is genuinely hard, and the standard “within transformation” trick that works for OLS does not work for QR (the median of demeaned y is not the demeaned median). Koenker (2004) proposed a penalized QR estimator that handles individual fixed effects in panel data. Machado and Santos Silva (2019) proposed a method-of-moments quantile regression (MMQR) that allows for fixed effects under a location-scale model assumption. Both are workable, both have caveats. MMQR is the most popular Stata-friendly option (xtqreg in user-written form, or mmqreg), but the location-scale assumption is restrictive (it forces the conditional quantiles to be parallel shifts of each other up to a scale factor, which is exactly the kind of heterogeneity QR is supposed to detect). Use with care, report robustness.
Cross-\tau interpretation. The OLS coefficient is the average causal effect under unconfoundedness on the conditional mean. The QR coefficient at \tau is the effect on the conditional \tau-th quantile under unconfoundedness on the conditional \tau-th quantile, which is a stronger and quantile-specific assumption. Do not casually port OLS identification arguments to QR. If the DAG justifies controlling for X for the mean, it does not automatically do so for every quantile.
Rank invariance. Even outside the IV setting, the interpretation “the treatment effect at \tau” conflates two things: the effect on the conditional \tau-th quantile of y (an effect on a population-level statistic), and the effect on the people who would be at the \tau-th quantile in the absence of treatment (a treatment effect on a specific subpopulation). These coincide only under rank invariance. They are usually reported as if they coincide. They do not.
Clustered standard errors. If the data has clustering (villages, schools, districts), the iid bootstrap is wrong. Use a cluster bootstrap (resample clusters, not observations) or a wild cluster bootstrap. In quantreg, this means writing a bootstrap loop by hand; the default se = "boot" is iid.
Choice of \tau grid. The conditional quantile function is estimated pointwise. Estimates at \tau = 0.02 or \tau = 0.98 are noisy and rely on a handful of observations in the tail. Restrict the reported grid to \tau \in [0.05, 0.95] unless there is a substantive reason and the sample size to push further. To show extreme quantiles, increase the bootstrap reps.
8.9 Reporting checklist
Five things that should appear in any QR result section.
- The plot, not just a table. A plot of \hat\beta(\tau) versus \tau with bands, for every coefficient you care about. Tables of three or five quantiles are fine as a supplement but should never be the only artifact.
- A formal test of cross-quantile equality. Either Koenker’s Wald test (works in
quantreg::anova.rq) or the Khmaladze test for the location-shift hypothesis. State the null and the p-value. - Robustness to the choice of \tau grid. Show that headline conclusions do not depend on the specific quantiles reported.
- Bootstrap confidence intervals. Default to bootstrap with at least 500 reps unless n is large enough that asymptotic SEs are clearly reliable. Use cluster bootstrap when clustering is present.
- Comparison to OLS. Always include the OLS estimate on the coefficient plot as a horizontal reference. The whole point of QR is to show what OLS misses; show the comparison explicitly.
8.10 Why this matters for a career in blended finance
Blended-finance impact evaluations have a structural bias toward means. Funders want one number, evaluators want a citation-friendly point estimate, and the median paper in this literature reports an average treatment effect with a clustered standard error and calls it a day.
The questions the field actually cares about are distributional. Did the credit reach the bottom? Did the off-grid solar program raise consumption at the 10th percentile or did the gains accrue to households already near the median? Did the climate-resilient seed variety protect the bottom decile from yield collapse, or did it raise mean yields by helping the better-off? Every one of those is a quantile question, and answering it with a mean is technically correct in the way that “people on average have one ovary” is technically correct.
The professional move, when building a portfolio of impact evaluations in this space, is to make quantile reporting a default. Run OLS for the mean. Run QR for the distribution. Run RIF for the unconditional statistic. Report all three when they agree (confidence builds). Report all three when they disagree (and explain which one matches the policy question). A funder who sees an evaluator routinely produce the distributional picture instead of the convenient summary number learns to trust that evaluator’s results more, not less.
There is also a defensive reason. The mean is a single number, and a single number is easy to attack. The quantile picture is a function, and a function is harder to attack because it carries its own internal consistency check (does the pattern make economic sense? does it match what you know about the targeting mechanism?). When a reviewer or a critical funder asks “but what about the bottom of the distribution?” the right answer is not a back-of-envelope subset regression. The right answer is a plot already shown in Figure 3.
Make the plot. Show the function. The mean is one slice of it. Most of the policy interest is in the rest.
8.11 References
Core methodology
- Koenker, R. and Bassett, G. (1978). “Regression Quantiles.” Econometrica 46(1): 33-50. The founding paper. Read at least the introduction and the LP formulation.
- Koenker, R. (2005). Quantile Regression. Econometric Society Monograph No. 38. Cambridge University Press. The reference text. Chapters 1-4 are the core.
- Koenker, R. (2004). “Quantile Regression for Longitudinal Data.” Journal of Multivariate Analysis 91(1): 74-89. Penalized QR with fixed effects.
- Powell, J. L. (1991). “Estimation of Monotonic Regression Models under Quantile Restrictions.” In Nonparametric and Semiparametric Methods in Econometrics and Statistics. Source for the sandwich variance estimator.
Unconditional / RIF
- Firpo, S., Fortin, N. M., and Lemieux, T. (2009). “Unconditional Quantile Regressions.” Econometrica 77(3): 953-973. The RIF approach.
- Rios-Avila, F. (2020). “Recentered Influence Functions (RIFs) in Stata: RIF Regression and RIF Decomposition.” Stata Journal 20(1): 51-94.
IV quantile regression
- Chernozhukov, V. and Hansen, C. (2005). “An IV Model of Quantile Treatment Effects.” Econometrica 73(1): 245-261.
- Chernozhukov, V. and Hansen, C. (2008). “Instrumental Variable Quantile Regression: A Robust Inference Approach.” Journal of Econometrics 142(1): 379-398.
- Frolich, M. and Melly, B. (2013). “Unconditional Quantile Treatment Effects under Endogeneity.” Journal of Business and Economic Statistics 31(3): 346-357.
Panel / fixed effects
- Machado, J. A. F. and Santos Silva, J. M. C. (2019). “Quantiles via Moments.” Journal of Econometrics 213(1): 145-173. The MMQR estimator.
- Canay, I. A. (2011). “A Simple Approach to Quantile Regression for Panel Data.” Econometrics Journal 14(3): 368-386.
Applied development and blended-finance
- Banerjee, A., Duflo, E., Glennerster, R., and Kinnan, C. (2015). “The Miracle of Microfinance? Evidence from a Randomized Evaluation.” American Economic Journal: Applied Economics 7(1): 22-53. Includes quantile treatment effect estimates showing that microcredit raises the right tail of business profits more than the left, a counter-pattern worth understanding.
- Crepon, B., Devoto, F., Duflo, E., and Pariente, W. (2015). “Estimating the Impact of Microcredit on Those Who Take It Up: Evidence from a Randomized Experiment in Morocco.” American Economic Journal: Applied Economics 7(1): 123-150. Quantile treatment effects on consumption.
- Karlan, D. and Zinman, J. (2010). “Expanding Credit Access: Using Randomized Supply Decisions to Estimate the Impacts.” Review of Financial Studies 23(1): 433-464. Distributional analysis of consumer credit access.
- Beegle, K., Christiaensen, L., Dabalen, A., and Gaddis, I. (2016). Poverty in a Rising Africa. World Bank. Chapters using quantile decompositions of household consumption.
- World Bank (2018). Riding the Wave: An East Asian Miracle for the 21st Century. Quantile-based growth-incidence analysis of poverty reduction.
- Bourguignon, F., Ferreira, F. H. G., and Lustig, N. (2005). The Microeconomics of Income Distribution Dynamics in East Asia and Latin America. World Bank / Oxford University Press. The classic reference for decomposing distributional change using quantile methods.
Software
- Koenker, R. (2024).
quantreg: Quantile Regression. R package version 5.97. The canonical implementation. - Wickham, H. (2016).
ggplot2: Elegant Graphics for Data Analysis. Springer. For the coefficient plot. - Jann, B. (various).
grqreg,qreg2, and related Stata user-written commands. Boston College Statistical Software Components.
Next chapter: nonparametric and semiparametric methods. After you can see the distribution, the next step is to stop assuming the conditional expectation function is linear.