This page demonstrates the instrumental-variable estimators in py-qte. All three estimate effects of an endogenous treatment, which is why they require an instrument.
Instrumental-variable quantile regression (Chernozhukov & Hansen 2004, 2005, 2006), which targets a structural quantile function rather than a complier effect.
The unconditional and conditional local quantile treatment effect estimators are similar in spirit to the local average treatment effect (LATE) of Imbens & Angrist 1994 in that they generally identify an effect on the complier subpopulation when the standard LATE assumptions hold. They also require a binary instrument and a binary treatment. The instrumental-variable quantile regression (IVQR) estimator estimates a population-level structural quantile effect in a framework in which the researcher must specify a structural quantile function.
Throughout the page we use different datasets to demonstrate the mechanics of the py-qte package for IV estimation. For the binary-instrument, binary-treatment case, we also show how the package produces useful descriptive statistics.
The implementations are inspired by the Stata ivqte package. The IVQR routine additionally follows the R IVQR package.
Listing 1 displays the quantiles used throughout and the bootstrap configuration.
The object of interest is the local quantile treatment effect (LQTE) for compliers. At quantile \(\tau \in (0, 1)\), it is defined as
\[
\Delta_\tau = Q_\tau(Y(1)\mid c) - Q_\tau(Y(0)\mid c),
\]
where \(Q_\tau(Y(d)\mid c)\) is the \(\tau\)-quantile of the potential outcome \(Y(d)\) in the complier subpopulation. The corresponding LATE is the difference in means, \(E[Y(1) - Y(0) \mid c]\). Both the conditional and the unconditional LQTE estimators assume that the standard LATE assumptions hold conditional on covariates:
Exclusion:\(Y(z, d) = Y(d)\) for \(z \in \{0, 1\}\).
Monotonicity:\(D(1) \ge D(0)\) almost surely.
Relevance:\(E[D \mid Z = 1, X] \ne E[D \mid Z = 0, X]\).
Here \(D(z)\) is the potential treatment under instrument value \(z\), and \(Y(z, d)\) is the potential outcome under instrument value \(z\) and treatment value \(d\). Both estimators use Abadie’s kappa weights (Abadie 2003) to identify transformations of potential outcomes in the subpopulation of compliers. Testable implications of these assumptions for a binary instrument and a binary treatment are discussed on the instrument-validity page.
Unconditional Local Quantile Treatment Effects
The unconditional LQTE is the LQTE defined above, i.e. the effect is not conditional on covariates. We thus require the potential outcomes’ cumulative distribution function, which is the inverse of \(Q_\tau(\cdot \mid c)\):
Here \(p(X) = P(Z = 1 \mid X)\) is the instrument probability.
A general problem here is that the empirical CDFs might not be monotone. One must therefore specify how to deal with this non-monotonicity. In this setting, one can either use the original weights given above and impose an ad hoc rule for the value corresponding to a particular quantile of the possibly non-monotone empirical CDF, or project the weights on the outcome and the treatment to make them positive.
The following section demonstrates how to conduct an analysis with this estimator using the py-qte package.
Card (1995) Data
The Card (1995) data consist of 3,010 men from the 1976 National Longitudinal Survey of Young Men. The dataset can be used to study the effect of education on labour market outcomes, using whether the man grew up in close proximity to a college as an instrument. The instrument nearc4 indicates whether a man grew up in a local labour market with a four-year college, and the outcome of interest lwage is the log wage. The treatment is a binary indicator for having at least 13 years of education, i.e. some college. Following Tübbicke 2023, who in turn follows Słoczyński 2021, the estimation sample restricts the data to covariate cells with at least five observations. A cell is one of the observed combinations of black, south66, south, smsa66 and smsa; this drops 22 observations and leaves 2,988. Listing 2 shows how to load the dataset and produce a table of descriptive statistics with the py-qte package.
Listing 2
from qte.datasets import load_cardfrom qte.iv.descriptives import make_descriptive_statisticsCARD_CELLS = ["black", "south66", "south", "smsa66", "smsa"]CARD_COVARIATES = ("exper + expersq + black + south + smsa + smsa66 ""+ reg662 + reg663 + reg664 + reg665 + reg666 + reg667 + reg668 + reg669")sample = load_card(treatment_cutoff=13)card = sample.filter(pl.len().over(CARD_CELLS) >=5)print(f"{sample.height} observations, {sample.height - card.height} dropped, {card.height} left")card_desc = make_descriptive_statistics( card,"lwage","college","nearc4", covariates=["exper", "educ", "age", "black", "smsa66", "south66"], labels={"lwage": "Log wage","college": "College","exper": "Experience","educ": "Years of education","age": "Age","black": "Black","smsa66": "SMSA in 1966","south66": "South in 1966", }, title="Card Data, Means and Standard Deviations",)
3010 observations, 22 dropped, 2988 left
card_desc
Table 1
Card Data, Means and Standard Deviations
Entire Sample
Assignment
Treatment
Treatment
Control
Diff.
(t-stat.)
Treatment
Control
Diff.
(t-stat.)
Sample
Number of observations
2,988
2,038
950
1,512
1,476
Treatment
College
0.51
0.55
0.42
0.12
1.00
0.00
1.00
[0.50]
[0.50]
[0.49]
(6.32)
[0.00]
[0.00]
Outcome variable
Log wage
6.26
6.31
6.16
0.15
6.36
6.16
0.19
[0.44]
[0.44]
[0.43]
(9.07)
[0.43]
[0.44]
(12.21)
Baseline Characteristics
Experience
8.84
8.67
9.21
−0.54
6.66
11.08
−4.41
[4.14]
[4.06]
[4.28]
(-3.24)
[3.20]
[3.78]
(-34.41)
Years of education
13.27
13.53
12.69
0.84
15.36
11.12
4.24
[2.67]
[2.58]
[2.79]
(7.84)
[1.64]
[1.61]
(71.26)
Age
28.11
28.20
27.90
0.30
28.02
28.19
−0.17
[3.14]
[3.18]
[3.04]
(2.50)
[3.03]
[3.24]
(-1.49)
Black
0.23
0.21
0.28
−0.07
0.14
0.32
−0.17
[0.42]
[0.41]
[0.45]
(-4.03)
[0.35]
[0.47]
(-11.54)
SMSA in 1966
0.65
0.80
0.33
0.47
0.70
0.60
0.10
[0.48]
[0.40]
[0.47]
(26.98)
[0.46]
[0.49]
(5.92)
South in 1966
0.41
0.33
0.60
−0.27
0.35
0.49
−0.14
[0.49]
[0.47]
[0.49]
(-14.10)
[0.48]
[0.50]
(-7.75)
Standard deviations are shown in square brackets. Differences in means are followed by Welch t-statistics in parentheses.
Table 1 reports means and standard deviations for the full sample, by instrument arm and by observed treatment status, with mean differences and Welch t-statistics. The estimation below conditions the instrument probability on the covariates.
Listing 3 shows how to estimate the unconditional LQTE with the py-qte package. Here we use Estimator.SIGNED to handle the possibly non-monotone empirical distribution function, as described in the theory above.
Table 2 and Figure 1 show the results in tabular and graphical form. As usual in py-qte, the quantile effect of interest (here the LQTE) and the corresponding average effect (here the LATE) are reported.
card_res.tabulate(quantiles=QS)
Table 2
Quantile & Average Treatment Effects
Outcome : lwage
Estimator : signed
Confidence Lvl : 0.95
Quantile
Effect Estimate
Std. Error
Lower CI
Upper CI
Quantile Treatment Effects
0.10
0.33
0.23
−0.13
0.78
0.25
0.50
0.28
−0.05
1.06
0.50
0.35
0.27
−0.18
0.88
0.75
0.30
0.24
−0.16
0.77
0.90
0.13
0.25
−0.36
0.61
Average Treatment Effects
-
0.31
0.20
−0.09
0.71
show_chart(card_res.plot())
Figure 1: Local quantile treatment effects on the Card data.
\[
Q_{\theta}(Y \mid X, D, c) = \alpha_{\theta} D + X' \beta_{\theta},
\]
where \(\alpha_{\theta}\) and \(\beta_{\theta}\) can be obtained via weighted quantile regression with Abadie’s kappa weights. Under the maintained assumptions, \(\alpha_{\theta}\) corresponds to the conditional (on covariate values) LQTE. Notice that, even though the conditional LQTE is assumed to be constant across covariates, it does not generally correspond to the unconditional LQTE. This is because integrating out the covariates from the conditional quantiles does not give the marginal quantile in general.
Generally, the sample version of the above quantile regression problem is difficult to solve because Abadie’s kappa weights can be negative, which makes the problem non-convex. The paper shows that this can be remedied by replacing the weights with their conditional expectation given \(U = (Y, D, X)\), which is guaranteed to be nonnegative and still identifies \(\alpha\) via weighted quantile regression as described above. In particular, these weights are given by
and \(p(X) = P(Z = 1 \mid X)\) is the instrument probability.
JTPA Data
The JTPA data come from a randomized evaluation of a job-training program. Assignment to training (assignmt) is randomized, but not everyone assigned to training actually enrolled (training), so assignment is an instrument for actual training. The extract contains 11,204 applicants; the analysis uses the 6,102 women, following Abadie, Angrist & Imbens 2002. The outcome is total 30-month earnings. Listing 4 shows how to load the dataset and produce a table of descriptive statistics with the py-qte package.
Table 3 shows the descriptive statistics for the dataset.
jtpa_desc
Table 3
JTPA Women, Means and Standard Deviations
Entire Sample
Assignment
Treatment
Treatment
Control
Diff.
(t-stat.)
Treatment
Control
Diff.
(t-stat.)
Sample
Number of observations
6,102
4,088
2,014
2,722
3,380
Treatment
Training
0.45
0.66
0.02
0.64
1.00
0.00
1.00
[0.50]
[0.47]
[0.13]
(80.24)
[0.00]
[0.00]
Outcome variable
Earnings
13,029
13,439
12,197
1,243
14,211
12,078
2,133
[13,415]
[13,614]
[12,964]
(3.46)
[13,550]
[13,230]
(6.18)
Baseline Characteristics
Age
33.33
33.33
33.35
−0.02
33.11
33.52
−0.41
[9.78]
[9.77]
[9.81]
(-0.09)
[9.71]
[9.84]
(-1.62)
Black
0.26
0.27
0.26
0.01
0.26
0.27
−0.01
[0.44]
[0.44]
[0.44]
(0.95)
[0.44]
[0.44]
(-0.97)
Hispanic
0.12
0.12
0.12
−0.01
0.13
0.11
0.01
[0.32]
[0.32]
[0.33]
(-0.89)
[0.33]
[0.32]
(1.29)
Married
0.22
0.22
0.21
0.02
0.23
0.21
0.01
[0.40]
[0.40]
[0.39]
(1.55)
[0.40]
[0.39]
(1.35)
HS or GED
0.72
0.73
0.70
0.02
0.75
0.70
0.06
[0.43]
[0.43]
[0.44]
(2.01)
[0.42]
[0.45]
(5.07)
AFDC
0.31
0.30
0.31
−0.01
0.32
0.29
0.02
[0.46]
[0.46]
[0.46]
(-1.03)
[0.47]
[0.46]
(1.92)
Prior earnings
2,481
2,475
2,494
−19
2,417
2,533
−117
[3,147]
[3,133]
[3,176]
(-0.22)
[2,920]
[3,318]
(-1.46)
Standard deviations are shown in square brackets. Differences in means are followed by Welch t-statistics in parentheses.
Listing 5 shows how to estimate the conditional LQTE with the py-qte package. Because assignment is randomized (with imperfect compliance), we set instrument_probability_formula=None. This does not skip the instrument-probability step: the implementation fits an intercept-only logit, so the instrument probability is constant. weight_formula and weight_adjustment specify how the adjusted nonnegative weights are computed.
Figure 2: Conditional local quantile treatment effects on the JTPA data.
Instrumental-Variable Quantile Regression
The model underlying the instrumental-variable quantile regression (IVQR) estimator was developed by Chernozhukov & Hansen 2004. The model assumes that potential outcomes are generated in accordance with \(Y(d) = q(d, X, U_d)\). The function \(q\) is nondecreasing in \(U_d\), and \(U_d \sim U(0, 1)\). Conditional on covariates \(X\), \(U_d\) is independent of \(Z\). Selection into treatment is determined in accordance with \(D = \delta(Z, X, V)\). Conditional on \((Z, X, V)\), the \(\{U_d\}\) are identically distributed (rank similarity), and the observed data are \(Y\), \(D\), \(X\) and \(Z\).
For this set of assumptions one can show that
\[
P[Y \le q(D, X, \tau) \mid X, Z] = \tau.
\]
This is essentially a conditional moment restriction that can be used to estimate quantile treatment effects.
\[
q_\tau(Y \mid D = d, X = x) = d' \alpha(\tau) + x' \beta(\tau).
\]
Here again, \(\alpha\) corresponds to the treatment effect under the maintained assumptions.
The parameters \(\alpha\) and \(\beta\) can be estimated via inverse quantile regression. For each quantile \(\tau\) and each candidate value of \(\alpha\) on a user-supplied grid, the outcome is shifted to \(Y - D\alpha\), the treatment is replaced by its first-stage fitted value, and a conventional quantile regression is run on the fitted treatment and the covariates. The selected \(\alpha\) then minimizes the Wald statistic for the coefficient on the fitted treatment, which reflects the exclusion restriction that the instrument \(Z\)does not directly influence outcomes. Notice that the algorithm generally requires, for each \(\tau\), one quantile regression per grid point for \(\alpha\). Each quantile regression has as parameters the fitted treatment and the covariates. The algorithm therefore tends to be computationally demanding, even though the standard errors are obtained analytically.
Notice that the py-qte implementation is less general than the model. We allow only a single treatment variable, whereas the model can accommodate multiple treatment variables. The algorithm would quickly run into the curse of dimensionality with multiple treatments because the number of grid points to search over grows exponentially. The implementation does, however, allow multiple instruments.
401(k) Pension Data
The 401(k) pension data of Chernozhukov & Hansen 2004 come from the 1991 Survey of Income and Program Participation. The outcome is net financial assets (net_tfa), the endogenous treatment is 401(k) participation (p401), and the instrument is 401(k) eligibility (e401). The controls are income and education categories plus demographic and pension variables. Listing 6 shows how to load these data and generate a table of descriptive statistics for them.
401(k) Pension Data, Means and Standard Deviations
Entire Sample
Assignment
Treatment
Treatment
Control
Diff.
(t-stat.)
Treatment
Control
Diff.
(t-stat.)
Sample
Number of observations
9,915
3,682
6,233
2,594
7,321
Treatment
401(k) participation
0.26
0.70
0.00
0.70
1.00
0.00
1.00
[0.44]
[0.46]
[0.00]
(93.68)
[0.00]
[0.00]
Outcome variable
Net financial assets
18,052
30,347
10,788
19,559
38,262
10,890
27,372
[63,523]
[74,800]
[54,518]
(13.84)
[79,088]
[55,257]
(16.28)
Baseline Characteristics
Age
41.06
41.48
40.81
0.67
41.51
40.90
0.61
[10.34]
[9.61]
[10.75]
(3.21)
[9.66]
[10.57]
(2.69)
Education
13.21
13.76
12.88
0.88
13.81
12.99
0.82
[2.81]
[2.64]
[2.86]
(15.59)
[2.67]
[2.83]
(13.27)
Income
37,201
46,862
31,494
15,368
49,367
32,890
16,477
[24,774]
[25,958]
[22,151]
(30.04)
[27,208]
[22,316]
(27.72)
Family size
2.87
2.90
2.84
0.06
2.92
2.85
0.07
[1.54]
[1.48]
[1.57]
(1.87)
[1.47]
[1.56]
(1.99)
Married
0.60
0.67
0.56
0.11
0.69
0.57
0.12
[0.49]
[0.47]
[0.50]
(10.84)
[0.46]
[0.49]
(10.77)
Two earners
0.38
0.48
0.32
0.16
0.50
0.34
0.17
[0.49]
[0.50]
[0.47]
(16.27)
[0.50]
[0.47]
(14.65)
Defined benefit
0.27
0.42
0.19
0.23
0.39
0.23
0.16
[0.44]
[0.49]
[0.39]
(24.34)
[0.49]
[0.42]
(15.18)
IRA
0.24
0.32
0.20
0.12
0.36
0.20
0.16
[0.43]
[0.47]
[0.40]
(12.96)
[0.48]
[0.40]
(15.22)
Homeowner
0.64
0.74
0.57
0.17
0.77
0.59
0.18
[0.48]
[0.44]
[0.49]
(17.73)
[0.42]
[0.49]
(17.41)
Standard deviations are shown in square brackets. Differences in means are followed by Welch t-statistics in parentheses.
Listing 7 shows how to perform IVQR estimation for the 401(k) data using the same covariate specification as the original application. Notice that, alongside the name of the treatment variable, we must specify a grid over which to search for the optimal value of the treatment effect.
Figure 3: IVQR quantile effects on the 401(k) pension data.
Notice that the reported standard errors are analytical. The reported average effects are averages over the requested quantiles, which implies that they are only meaningful when the quantile grid is dense. For comparison, we also report the two-stage least squares estimate of the average effect in Table 6.
References
Imbens, G. W., & Angrist, J. D. (1994). Identification and estimation of local average treatment effects. Econometrica, 62(2), 467–475. doi:10.2307/2951620
Abadie, A. (2003). Semiparametric instrumental variable estimation of treatment response models. Journal of Econometrics, 113(2), 231–263. doi:10.1016/S0304-4076(02)00201-4
Abadie, A., Angrist, J., & Imbens, G. (2002). Instrumental variables estimates of the effect of subsidized training on the quantiles of trainee earnings. Econometrica, 70(1), 91–117. doi:10.1111/1468-0262.00270
Card, D. (1995). Using geographic variation in college proximity to estimate the return to schooling. In L. N. Christofides, E. K. Grant, & R. Swidinsky (Eds.), Aspects of labour market behaviour: Essays in honour of John Vanderkamp (pp. 201–222). University of Toronto Press.
Frölich, M., & Melly, B. (2013). Unconditional quantile treatment effects under endogeneity. Journal of Business & Economic Statistics, 31(3), 346–357. doi:10.1080/07350015.2013.803869
Chernozhukov, V., & Hansen, C. (2004). The effects of 401(k) participation on the wealth distribution: An instrumental quantile regression analysis. The Review of Economics and Statistics, 86(3), 735–751.
Chernozhukov, V., & Hansen, C. (2005). An IV model of quantile treatment effects. Econometrica, 73(1), 245–261.
Chernozhukov, V., & Hansen, C. (2006). Instrumental quantile regression inference for structural and treatment effect models. Journal of Econometrics, 132(2), 491–525.
Słoczyński, T. (2021). When should we (not) interpret linear IV estimands as LATE? IZA Discussion Paper No. 14349. Institute of Labor Economics. doi:10.2139/ssrn.3842328
Tübbicke, S. (2023). When to use matching and weighting or regression in instrumental variable estimation? Evidence from college proximity and returns to college. Empirical Economics, 65(6), 2979–2999. doi:10.1007/s00181-023-02441-7