Package 'qte'

Title: Quantile Treatment Effects
Description: Provides several methods for computing the Quantile Treatment Effect (QTE) and Quantile Treatment Effect on the Treated (QTT). The main cases covered are (i) treatment is randomly assigned, (ii) treatment is as good as randomly assigned after conditioning on covariates (selection on observables) using the methods of Firpo (2007) <doi:10.1111/j.1468-0262.2007.00738.x>, and (iii) identification is based on a Difference in Differences assumption, with support for several varieties including Athey and Imbens (2006) <doi:10.1111/j.1468-0262.2006.00668.x>, Callaway and Li (2019) <doi:10.3982/QE935>, and Callaway, Li, and Oka (2018) <doi:10.1016/j.jeconom.2018.06.008>. Version 2.0 adds a unified staggered treatment adoption API (built on 'ptetools') for all DiD-based estimators, as well as a new lagged-outcome unconfoundedness estimator ('lou_qtt').
Authors: Brantly Callaway [aut, cre]
Maintainer: Brantly Callaway <[email protected]>
License: GPL-3
Version: 2.1.0
Built: 2026-11-20 16:40:16 UTC
Source: https://github.com/bcallaway11/qte

Help Index


qte: A package for computing quantile treatment effects

Description

logo

Provides several methods for computing the Quantile Treatment Effect (QTE) and Quantile Treatment Effect on the Treated (QTT). The main cases covered are (i) treatment is randomly assigned, (ii) treatment is as good as randomly assigned after conditioning on covariates (selection on observables) using the methods of Firpo (2007) doi:10.1111/j.1468-0262.2007.00738.x, and (iii) identification is based on a Difference in Differences assumption, with support for several varieties including Athey and Imbens (2006) doi:10.1111/j.1468-0262.2006.00668.x, Callaway and Li (2019) doi:10.3982/QE935, and Callaway, Li, and Oka (2018) doi:10.1016/j.jeconom.2018.06.008. Version 2.0 adds a unified staggered treatment adoption API (built on 'ptetools') for all DiD-based estimators, as well as a new lagged-outcome unconfoundedness estimator ('lou_qtt').

Author(s)

Maintainer: Brantly Callaway [email protected]

Authors:

See Also

Useful links:


autoplot.QTE

Description

Plot a QTE object as a quantile treatment effect curve with optional confidence bands.

Usage

## S3 method for class 'QTE'
autoplot(object, cband = TRUE, ylab = "QTE", ...)

Arguments

object

a QTE object, as returned by unc_qte.

cband

logical; if TRUE (default), show the uniform confidence band, qte ±\pm c ×\times qte.se (as stored by unc_qte with cband = TRUE). If FALSE, show pointwise intervals computed from object$qte.se.

ylab

label for the y-axis. Default "QTE".

...

unused.

Value

a ggplot object.


Difference-in-Differences in Distribution Functions

Description

Computes the Quantile Treatment Effect on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) under parallel trends in the distribution functions of untreated potential outcomes, with staggered treatment adoption, for panel data or repeated cross sections.

Identification. For each group gg and period tt,

FYt(0)∣G=g(y)−FYt−1(0)∣G=g(y)=FYt(0)∣C(y)−FYt−1(0)∣C(y)for all y,F_{Y_t(0)|G=g}(y) - F_{Y_{t-1}(0)|G=g}(y) = F_{Y_t(0)|C}(y) - F_{Y_{t-1}(0)|C}(y) \quad \text{for all } y,

with CC the comparison group: parallel trends for the distribution function rather than the mean (DiD) or the quantile function (QDiD). Roth and Sant'Anna (2023) show this is the condition under which parallel trends holds for every transformation of the outcome. It point-identifies the counterfactual distribution, so the QTT, for discrete outcomes too, and the implied ATT is the usual DiD ATT. Covariates make the assumption conditional on XX.

See cdf_did_gt for how the counterfactual distribution is estimated (including the rearrangement into a valid distribution function and the three covariate methods).

Usage

cdf_did(
  yname,
  gname,
  tname,
  idname = NULL,
  data,
  panel = TRUE,
  xformula = ~1,
  est_method = c("aipw", "ipw", "reg"),
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  gt_type = c("att", "qtt"),
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable. Required when panel = TRUE.

data

A data frame.

panel

Logical. TRUE (default) for panel data; FALSE for repeated cross sections (see the section on repeated cross sections).

xformula

One-sided formula of covariates. Default ~1. With panel data, each unit's covariates are taken from the base period of each group-time cell (never from a post-treatment period); with repeated cross sections, each observation's own values are used.

est_method

With covariates: "aipw" (default; doubly robust), "ipw" or "reg" (outcome regression, as in did).

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()). With the empirical bootstrap, whole clusters are resampled.

control_group

"notyettreated" (default) or "nevertreated".

anticipation

Number of time periods before treatment during which units may anticipate it. Default 0.

alp

Significance level. Default 0.05.

cband

Logical; uniform confidence bands. Default TRUE.

biters

Number of bootstrap iterations. Default 100.

cl

Number of cores for the bootstrap. Default 1.

gt_type

"att" (default) for the ATT and event study, or "qtt" for the QTT curve.

probs

For gt_type = "qtt", the quantiles at which to report the QTT. Default seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_emp_boot object; for gt_type = "qtt", a pte_qtt object. Both include outcome_discreteness.

Discrete outcomes

The counterfactual distribution is identified for discrete outcomes as well, unlike for rank- or quantile-based estimators such as cic. Quantile effects still jump at mass points and their bootstrap inference can be unreliable, so gt_type = "qtt" warns (once per call) when the outcome looks discrete; see cic.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Roth, Jonathan, and Pedro H. C. Sant'Anna. “When Is Parallel Trends Sensitive to Functional Form?” Econometrica 91(2), pp. 737-747, 2023.

Sant'Anna, Pedro H. C., and Jun Zhao. “Doubly Robust Difference-in-Differences Estimators.” Journal of Econometrics 219(1), pp. 101-122, 2020.

Examples

data(mpdta, package = "did")
res <- cdf_did(yname = "lemp", gname = "first.treat", tname = "year",
               idname = "countyreal", data = mpdta, gt_type = "qtt",
               probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res)

CDF Difference-in-Differences for a Single 2x2 Cell

Description

Computes the ATT and the distributions needed for the QTT for one group-time cell under parallel trends in the distribution functions of untreated potential outcomes. Used as the attgt_fun in pte by cdf_did.

Usage

cdf_did_gt(gt_data, xformula = ~1, est_method = c("aipw", "ipw", "reg"), ...)

Arguments

gt_data

A gt_data_frame for one (g,t) cell, as produced by ptetools::two_by_two_subset (panel) or ptetools::two_by_two_rcs_subset (repeated cross sections), with columns Y, D, name, id, .w and any covariates.

xformula

One-sided formula of covariates. Default ~1.

est_method

With covariates: "aipw" (default, doubly robust), "ipw", or "reg" (outcome regression). Ignored without covariates.

...

Additional arguments passed by ptetools; ignored.

Details

The counterfactual distribution of untreated outcomes for the treated group in the post period is

F0(y)=Fpre,D=1(y)+Fpost,D=0(y)−Fpre,D=0(y),F_{0}(y) = F_{\text{pre},D=1}(y) + F_{\text{post},D=0}(y) - F_{\text{pre},D=0}(y),

evaluated exactly at every point of the pooled support of the three distributions on the right. The raw F0F_0 need not be a valid distribution function (it can decrease, or leave 0, 1); it is made one by monotone rearrangement (sorting its values; Chernozhukov, Fernandez-Val and Galichon 2010) and clipping to 0, 1. The largest change this makes is returned as cdf_violation; large values are evidence against the identifying assumption.

The ATT is the mean of the treated group's observed post-period outcomes minus the mean of the raw F0F_0, which is what the assumption identifies. Without covariates this equals the usual DiD ATT.

With covariates, the comparison group's change in CDFs is averaged over the treated group's covariate distribution. For each yy this is a DiD for the outcome 1{Y≤y}1\{Y \le y\}, estimated as in Sant'Anna and Zhao (2020): by outcome regression (distribution regression of 1{Y≤y}1\{Y \le y\} on the covariates, in each period), by inverse probability weighting, or doubly robust (AIPW, the default). IPW is exact on the data's support points; outcome regression and AIPW use the distribution regression's threshold grid (see cic_gt's cond_dist = "dr"). The propensity score is a weighted logit of treatment on the pre-period covariates.

The distribution of individual treatment effects is not identified, so Fte is NULL.

Value

A ptetools::attgt_noif object with the ATT and, in extra_gt_returns, F0 (rearranged counterfactual distribution), F1 (treated post-period distribution), Fte = NULL, and cdf_violation.

References

Roth, Jonathan, and Pedro H. C. Sant'Anna. “When Is Parallel Trends Sensitive to Functional Form?” Econometrica 91(2), pp. 737-747, 2023.

Sant'Anna, Pedro H. C., and Jun Zhao. “Doubly Robust Difference-in-Differences Estimators.” Journal of Econometrics 219(1), pp. 101-122, 2020.

Chernozhukov, Victor, Ivan Fernandez-Val, and Alfred Galichon. “Quantile and Probability Curves Without Crossing.” Econometrica 78(3), pp. 1093-1125, 2010.


Change in Changes

Description

Computes Quantile Treatment effects on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) using the Change in Changes identification strategy of Athey and Imbens (2006). Handles two-period data and staggered treatment adoption uniformly: a two-period, two-group dataset is the degenerate single-(g,t) case. Supports both panel and repeated cross sections data.

Usage

cic(
  yname,
  gname,
  tname,
  idname = NULL,
  data,
  panel = TRUE,
  xformula = ~1,
  cond_dist = c("qr", "dr"),
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  ret_quantile = NULL,
  gt_type = "att",
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable. Required when panel = TRUE.

data

A data frame.

panel

Logical; TRUE (default) for panel data, FALSE for repeated cross sections (see the section on repeated cross sections).

xformula

One-sided formula for covariates used in the covariate adjustment. Default ~1 uses no covariates. With panel data, each unit's covariates are taken from the base period of each group-time cell (never from a post-treatment period); with repeated cross sections, each observation's own values are used.

cond_dist

How the conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression at the percentiles 0.01, ..., 0.99, or "dr" for distribution regression (a logit of 1{Y≤y}1\{Y \le y\} on the covariates at a grid of thresholds; Chernozhukov, Fernandez-Val and Melly 2013). Distribution regression handles outcomes with mass points (e.g. many zeros) naturally. Ignored without covariates.

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

Which units to use as the comparison group: "notyettreated" (default) or "nevertreated".

anticipation

Number of periods of anticipation. Default 0.

alp

Significance level for confidence bands. Default 0.05.

cband

Logical; if TRUE (default) compute a uniform confidence band rather than pointwise intervals.

biters

Number of bootstrap iterations. Default 100.

cl

Number of clusters for parallel computation. Default 1.

ret_quantile

Passed through to ptetools for the "qott" case. Ignored when gt_type = "qtt" (use probs instead).

gt_type

Type of group-time effect to compute. "att" (default) returns ATT(g,t). "qtt" returns the full QTT curve over probs using mixture-CDF aggregation. "qott" returns the quantile of the individual treatment effect distribution under rank invariance (panel only).

probs

For gt_type = "qtt", the quantile grid at which to evaluate the QTT curve. Default is seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_results object from ptetools. For gt_type = "qtt", a pte_qtt object with overall, group-specific, and dynamic QTT curves and bootstrap SEs.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.

Examples

data(mpdta, package = "did")

## ATT aggregated across all groups and periods
res_att <- cic(yname = "lemp", gname = "first.treat", tname = "year",
               idname = "countyreal", data = mpdta,
               gt_type = "att", biters = 20)
summary(res_att)

## Full QTT curve at selected quantiles
res_qtt <- cic(yname = "lemp", gname = "first.treat", tname = "year",
               idname = "countyreal", data = mpdta,
               gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res_qtt)

Change in Changes: group-time estimator

Description

Computes the Change in Changes (CiC) ATT and counterfactual outcome distribution for a single 2x2 (pre/post x treated/control) data subset. Serves directly as the attgt_fun argument to ptetools::pte. Panel vs. repeated cross sections is detected automatically from whether the same unit ids appear in both periods.

Usage

cic_gt(gt_data, xformula = ~1, cond_dist = c("qr", "dr"), ...)

Arguments

gt_data

A data frame (typically a gt_data_frame from ptetools) with columns name ("pre" or "post"), D (treatment dummy), Y (outcome), id (unit identifier), and any covariate columns referenced by xformula.

xformula

One-sided formula for covariates. Default ~1 uses no covariates. With covariates, the control group's conditional outcome distributions are estimated by the method in cond_dist, following Athey and Imbens (2006).

cond_dist

How the conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression at the percentiles 0.01, ..., 0.99, or "dr" for distribution regression (a logit of 1{Y≤y}1\{Y \le y\} on the covariates at a grid of thresholds; Chernozhukov, Fernandez-Val and Melly 2013). Distribution regression handles outcomes with mass points (e.g. many zeros) naturally. Ignored without covariates.

...

Additional arguments passed through by ptetools; not used directly.

Value

A ptetools::attgt_noif object with the ATT estimate and, in extra_gt_returns, three objects: F1 (ECDF of observed treated outcomes in the post period), F0 (ECDF of counterfactual untreated outcomes for the treated group), and Fte (ECDF of individual treatment effects under rank invariance; NULL for repeated cross sections).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.

Chernozhukov, Victor, Ivan Fernandez-Val and Blaise Melly. “Inference on Counterfactual Distributions.” Econometrica 81(6), pp. 2205-2268, 2013.


Distributional Difference-in-Differences

Description

Computes Quantile Treatment effects on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) using the distributional DiD identification strategy of Callaway, Li, and Oka (2018). Handles two-period data and staggered treatment adoption uniformly via ptetools. Requires panel data.

Identification. Under distributional parallel trends and a copula restriction (the rank correlation of untreated potential outcomes between the treated and control groups in the pre-period is preserved), the counterfactual distribution FY(0),post∣D=1F_{Y(0),\text{post}|D=1} is recovered by adding each control unit's actual change ΔYctrl,j\Delta Y_{\text{ctrl},j} to the treated pre-period quantile at that control unit's rank. This point-identifies the QTT with only two time periods, in contrast to methods (e.g. panel_qtt) that require three periods.

Panel data required. Unlike cic, qdid, and mdid, this estimator cannot be applied to repeated cross sections because it requires observing the within-unit outcome change for each control unit.

Usage

ddid(
  yname,
  gname,
  tname,
  idname,
  data,
  xformula = ~1,
  cond_dist = c("qr", "dr"),
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  gt_type = "att",
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable (required).

data

A data frame.

xformula

One-sided formula for covariates. Default ~1 uses no covariates. Each unit's covariates are taken from the base period of each group-time cell.

cond_dist

How conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

Which units to use as the comparison group: "notyettreated" (default) or "nevertreated".

anticipation

Number of periods of anticipation. Default 0.

alp

Significance level for confidence bands. Default 0.05.

cband

Logical; if TRUE (default) compute a uniform confidence band rather than pointwise intervals.

biters

Number of bootstrap iterations. Default 100.

cl

Number of clusters for parallel computation. Default 1.

gt_type

Type of group-time effect to compute. "att" (default) returns ATT(g,t). "qtt" returns the full QTT curve over probs using mixture-CDF aggregation.

probs

For gt_type = "qtt", the quantile grid. Default is seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_results object from ptetools. For gt_type = "qtt", a pte_qtt object.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Callaway, Brantly, Tong Li, and Tatsushi Oka. “Quantile Treatment Effects in Difference in Differences Models under Dependence Restrictions and with Only Two Time Periods.” Journal of Econometrics 206(2), pp. 395-413, 2018.

Examples

data(mpdta, package = "did")

## ATT aggregated across all groups and periods
res_att <- ddid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "att", biters = 20)
summary(res_att)

## Full QTT curve at selected quantiles
res_qtt <- ddid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res_qtt)

Distributional DiD: group-time estimator

Description

Computes the distributional DiD ATT and counterfactual outcome distribution for a single 2x2 (pre/post x treated/control) data subset. Serves directly as the attgt_fun argument to ptetools::pte.

Identification. Under distributional parallel trends and a copula restriction (Callaway, Li, and Oka 2018), the counterfactual outcome for each control unit jj is

kcfj=ΔYctrl,j+Q1,pre(uj)kcf_j = \Delta Y_{\text{ctrl},j} + Q_{1,\text{pre}}(u_j)

where ΔYctrl,j=Ypost,j−Ypre,j\Delta Y_{\text{ctrl},j} = Y_{\text{post},j} - Y_{\text{pre},j} is the observed change for control unit jj, uj=F0,pre(Ypre,j)u_j = F_{0,\text{pre}}(Y_{\text{pre},j}) is that unit's rank in the control pre-period distribution, and Q1,preQ_{1,\text{pre}} is the quantile function of the treated pre-period distribution. The unconditional counterfactual distribution FY(0),post∣D=1F_{Y(0),\text{post}|D=1} is then the (weighted) empirical CDF of {kcfj}\{kcf_j\}.

Unlike CiC, QDiD, and MDiD, the counterfactual is indexed over control units, not treated units. Consequently F0 and the ATT counterfactual term are weighted by w_pre_ctrl, and no individual treatment effect distribution (Fte) is returned.

Panel data required. The estimator needs the actual change ΔYctrl,j\Delta Y_{\text{ctrl},j} for each control unit, which requires observing the same units in both periods.

Usage

ddid_gt(gt_data, xformula = ~1, cond_dist = c("qr", "dr"), ...)

Arguments

gt_data

A data frame (typically a gt_data_frame from ptetools) with columns name ("pre" or "post"), D (treatment dummy), Y (outcome), id (unit identifier), .w (sampling weights), and any covariate columns referenced by xformula. Control units must be observed in both periods.

xformula

One-sided formula for covariates. Default ~1 uses no covariates. With covariates, the unconditional rank uju_j is replaced by a conditional rank estimated via quantile regression on the control pre-period (QR0tmin1), and the treated pre-period quantile is replaced by a conditional quantile (QR1tmin1) evaluated at that rank and the control unit's own covariate values.

cond_dist

How the conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

...

Additional arguments passed through by ptetools; not used directly.

Value

A ptetools::attgt_noif object with the ATT estimate and, in extra_gt_returns, F0 (weighted ECDF of counterfactual outcomes indexed over control units), F1 (weighted ECDF of observed treated post-period outcomes), and Fte = NULL (individual treatment effect distribution is not identified for this estimator).

References

Callaway, Brantly, Tong Li, and Tatsushi Oka. “Quantile Treatment Effects in Difference in Differences Models under Dependence Restrictions and with Only Two Time Periods.” Journal of Econometrics 206(2), pp. 395-413, 2018.


Lalonde (1986)'s NSW Dataset

Description

lalonde contains data from the National Supported Work Demonstration. This program randomly assigned applicants to the job training program (or out of the job training program). The dataset is discussed in Lalonde (1986). The experimental part of the dataset is combined with an observational dataset from the Panel Study of Income Dynamics (PSID). Lalonde (1986) and many subsequent papers (e.g. Heckman and Hotz (1989), Dehejia and Wahba (1999), Smith and Todd (2005), and Firpo (2007) have used this combination to study the effectiveness of various ‘observational’ methods (e.g. regression, Heckman selection, Difference in Differences, and propensity score matching) of estimating the Average Treatment Effect (ATE) of participating in the job training program. The idea is that the results from the observational method can be compared to results that can be easily obtained from the experimental portion of the dataset.

To be clear, the observational data combines the observations that are treated from the experimental portion of the data with untreated observations from the PSID.

Usage

data(lalonde)

Format

Four data.frames: (i) lalonde.exp contains a cross sectional version of the experimental data, (ii) lalonde.psid contains a cross sectional version of the observational data, (iii) lalonde.exp.panel contains a panel version of the experimental data, and (iv) lalonde.psid.panel contains a panel version of the observational data. Note: the cross sectional and panel versions of each dataset are identical up to their shape; in demonstrating each of the methods, it is sometimes convenient to have one form of the data or the other.

References

LaLonde, Robert. “Evaluating the Econometric Evaluations of Training Programs with Experimental Data.” The American Economics Review, pp. 604-620, 1986. @source The dataset comes from Lalonde (1986) and has been studied in much subsequent work. The qte package uses a version from the causalsens package (https://CRAN.R-project.org/package=causalsens)


Lalonde's Experimental Dataset

Description

The cross sectional verion of the experimental part of the lalonde dataset. It is loaded with all the datasets with the command data(lalonde)


Lalonde's Panel Experimental Dataset

Description

The panel verion of the experimental part of the lalonde dataset. It is loaded with all the datasets with the command data(lalonde)


Lalonde's Observational Dataset

Description

The cross sectional verion of the observational part of the lalonde dataset. It is loaded with all the datasets with the command data(lalonde)


Lalonde's Panel Observational Dataset

Description

The panel verion of the observational part of the lalonde dataset. It is loaded with all the datasets with the command data(lalonde)


Lagged Outcome Unconfoundedness QTT

Description

Estimates the Quantile Treatment Effect on the Treated (QTT) and Average Treatment Effect on the Treated (ATT) under a lagged-outcome unconfoundedness assumption with staggered treatment adoption. The key identifying assumption is Yg,t(0)⊥D∣X,YpreY_{g,t}(0) \perp D \mid X, Y_{\text{pre}}, i.e., conditional on observed covariates and the pre-treatment outcome, treatment is as good as randomly assigned within each cohort-period cell.

Estimation operates at the (g,t) level: for each cohort gg and post-treatment period tt, a cross-sectional comparison is made between the treated group and a not-yet-treated (or never-treated) comparison group, adjusting for covariates and (optionally) the pre-treatment outcome. Group-time estimates are then aggregated to overall, dynamic, and group-specific summaries.

Three estimation methods are available:

"ipw"

Propensity-score reweighting. Control units are reweighted by p^(X,Ypre)/(1−p^(X,Ypre))\hat p(X,Y_{\text{pre}})/(1-\hat p(X,Y_{\text{pre}})) to approximate the covariate distribution of the treated group.

"reg"

Outcome regression. A quantile regression model is fit on control units' post-period outcomes as a function of (X,Ypre)(X, Y_{\text{pre}}), then predicted at treated units to construct the counterfactual distribution (Melly 2006; Chernozhukov, Fernandez-Val, and Melly 2013).

"aipw"

Doubly-robust augmented IPW. Combines the propensity score and outcome models. Consistent if either model is correctly specified.

When lagged_outcome_cov = FALSE and xformula = ~1, all three methods reduce to a simple distribution comparison within each (g,t) cell, which is consistent under unconditional unconfoundedness.

The ATT analogue (without the QTT) for staggered adoption under lagged-outcome unconfoundedness is developed in Callaway (2023).

Usage

lou_qtt(
  yname,
  gname,
  tname,
  idname = NULL,
  data,
  xformula = ~1,
  lagged_outcome_cov = TRUE,
  est_method = c("ipw", "reg", "aipw"),
  cond_dist = c("qr", "dr"),
  panel = TRUE,
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  gt_type = c("att", "qtt"),
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable. Required when panel = TRUE.

data

A data frame.

xformula

One-sided formula for additional covariates used in the propensity score and/or outcome model. Default ~1 uses no additional covariates beyond the lagged outcome (when lagged_outcome_cov = TRUE). With panel data, each unit's covariates are taken from the base period of each group-time cell (never from a post-treatment period); with repeated cross sections, each observation's own values are used.

lagged_outcome_cov

Logical; if TRUE (default), the pre-treatment outcome is added as a covariate in both the propensity score and outcome models. Requires panel = TRUE.

est_method

Estimation method: "ipw" (default), "reg" ("or" is a deprecated alias), or "aipw". See Details.

cond_dist

For est_method = "reg" or "aipw", how the conditional distribution of the untreated outcome is estimated: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored for "ipw".

panel

Logical; TRUE (default) for panel data, FALSE for repeated cross sections. lagged_outcome_cov = TRUE requires panel = TRUE.

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

Which units to use as the comparison group: "notyettreated" (default) or "nevertreated".

anticipation

Number of periods of anticipation. Default 0.

alp

Significance level for confidence intervals. Default 0.05.

cband

Logical; if TRUE (default), report a simultaneous confidence band (uniform over all quantiles in probs) in addition to pointwise intervals.

biters

Number of bootstrap iterations. Default 100.

cl

Number of clusters for parallel bootstrap. Default 1.

gt_type

Type of group-time effect to compute. "att" (default) returns the ATT curve aggregated over (g,t) cells. "qtt" returns the full QTT curve over probs using mixture-CDF aggregation.

probs

For gt_type = "qtt", the quantile grid at which to evaluate the QTT. Default seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_emp_boot object. For gt_type = "qtt", a pte_qtt object with overall, group-specific, and dynamic QTT curves, bootstrap standard errors, and pointwise and uniform confidence bands.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Callaway, Brantly. “Policy Evaluation during a Pandemic.” Journal of Econometrics 236(2), 2023.

Melly, Blaise. “Estimation of Counterfactual Distributions Using Quantile Regression.” Working paper, University of St. Gallen, 2006.

Chernozhukov, Victor, Ivan Fernandez-Val, and Blaise Melly. “Inference on Counterfactual Distributions.” Econometrica 81(6), pp. 2205–2268, 2013.

See Also

unc_qte for the cross-sectional (non-staggered) version. cic, qdid, mdid for alternative identification strategies with staggered adoption.

Examples

data(mpdta, package = "did")

## ATT under lagged-outcome unconfoundedness (IPW with pre-period outcome)
res_att <- lou_qtt(
  yname = "lemp", gname = "first.treat", tname = "year",
  idname = "countyreal", data = mpdta,
  lagged_outcome_cov = TRUE, est_method = "ipw",
  gt_type = "att", biters = 20
)
summary(res_att)

## QTT with doubly-robust estimation
res_qtt <- lou_qtt(
  yname = "lemp", gname = "first.treat", tname = "year",
  idname = "countyreal", data = mpdta,
  lagged_outcome_cov = TRUE, est_method = "aipw",
  gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20
)
summary(res_qtt)

Mean Difference-in-Differences

Description

Computes Quantile Treatment effects on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) using the Mean Difference-in-Differences identification strategy. Handles two-period data and staggered treatment adoption uniformly. Supports both panel and repeated cross sections data.

Identification. MDiD assumes the counterfactual distribution of untreated potential outcomes is a location shift of the treated group's pre-treatment distribution. The size of the shift is the mean DiD Δ=E[Ypost∣D=0]−E[Ypre∣D=0]\Delta = E[Y_{\text{post}}|D=0] - E[Y_{\text{pre}}|D=0], so QY(0),post∣D=1(τ)=QY,pre∣D=1(τ)+ΔQ_{Y(0),\text{post}|D=1}(\tau) = Q_{Y,\text{pre}|D=1}(\tau) + \Delta. This is stronger than parallel trends in means alone: it additionally requires that the shape of the treated group's outcome distribution is unchanged in the counterfactual. MDiD is a special case of QDiD that applies a single mean shift rather than a rank-specific distributional shift.

Covariate adjustment. When xformula is specified, the scalar shift is replaced by a unit-specific conditional mean shift Δ(Xi)=E[Ypost∣D=0,Xi]−E[Ypre∣D=0,Xi]\Delta(X_i) = E[Y_{\text{post}}|D=0,X_i] - E[Y_{\text{pre}}|D=0,X_i], estimated by weighted OLS. The counterfactual for treated unit ii is Ypre,i+Δ(Xi)Y_{\text{pre},i} + \Delta(X_i), and the unconditional counterfactual distribution is the empirical CDF of these values. By the law of iterated expectations, this consistently estimates FY(0),post∣D=1F_{Y(0),\text{post}|D=1}.

Usage

mdid(
  yname,
  gname,
  tname,
  idname = NULL,
  data,
  panel = TRUE,
  xformula = ~1,
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  ret_quantile = NULL,
  gt_type = "att",
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable. Required when panel = TRUE.

data

A data frame.

panel

Logical; TRUE (default) for panel data, FALSE for repeated cross sections (see the section on repeated cross sections).

xformula

One-sided formula for covariates. Default ~1 uses no covariates. With panel data, each unit's covariates are taken from the base period of each group-time cell (never from a post-treatment period); with repeated cross sections, each observation's own values are used.

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

Which units to use as the comparison group: "notyettreated" (default) or "nevertreated".

anticipation

Number of periods of anticipation. Default 0.

alp

Significance level for confidence bands. Default 0.05.

cband

Logical; if TRUE (default) compute a uniform confidence band rather than pointwise intervals.

biters

Number of bootstrap iterations. Default 100.

cl

Number of clusters for parallel computation. Default 1.

ret_quantile

Passed through to ptetools for the "qott" case.

gt_type

Type of group-time effect to compute. "att" (default) returns ATT(g,t). "qtt" returns the full QTT curve over probs using mixture-CDF aggregation. "qott" returns the quantile of the individual treatment effect distribution (panel only).

probs

For gt_type = "qtt", the quantile grid at which to evaluate the QTT curve. Default is seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_results object from ptetools. For gt_type = "qtt", a pte_qtt object with overall, group-specific, and dynamic QTT curves and bootstrap SEs.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.

Thuysbaert, Bram. “Distributional Comparisons in Difference in Differences Models.” Working Paper, 2007.

Examples

data(mpdta, package = "did")

## ATT aggregated across all groups and periods
res_att <- mdid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "att", biters = 20)
summary(res_att)

## Full QTT curve at selected quantiles
res_qtt <- mdid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res_qtt)

Mean Difference-in-Differences: group-time estimator

Description

Computes the MDiD ATT and counterfactual outcome distribution for a single 2x2 (pre/post x treated/control) data subset. Serves directly as the attgt_fun argument to ptetools::pte. Panel vs. repeated cross sections is detected automatically from whether the same unit ids appear in both periods.

Identification. MDiD assumes that the counterfactual distribution of untreated potential outcomes for the treated group in the post period is a location shift of the treated group's pre-period distribution:

FY(0),post∣D=1(y)=FY,pre∣D=1(y−Δ)F_{Y(0),\text{post}|D=1}(y) = F_{Y,\text{pre}|D=1}(y - \Delta)

where Δ=E[Ypost∣D=0]−E[Ypre∣D=0]\Delta = E[Y_{\text{post}}|D=0] - E[Y_{\text{pre}}|D=0] is the mean DiD (the change in mean outcomes for the untreated group). The counterfactual quantile function is therefore QY(0),post∣D=1(τ)=QY,pre∣D=1(τ)+ΔQ_{Y(0),\text{post}|D=1}(\tau) = Q_{Y,\text{pre}|D=1}(\tau) + \Delta.

Covariate adjustment. With covariates, the scalar shift Δ\Delta is replaced by a unit-specific conditional mean shift Δ(Xi)=E[Ypost∣D=0,Xi]−E[Ypre∣D=0,Xi]\Delta(X_i) = E[Y_{\text{post}}|D=0, X_i] - E[Y_{\text{pre}}|D=0, X_i], estimated by weighted OLS on the control group in each period. The counterfactual for treated pre-period unit ii is Ypre,i+Δ(Xi)Y_{\text{pre},i} + \Delta(X_i). The unconditional counterfactual distribution is the empirical CDF of these shifted values, which by the law of iterated expectations consistently estimates FY(0),post∣D=1(y)=∫FY,pre∣D=1,X=x(y−Δ(x)) dFX∣D=1(x)F_{Y(0),\text{post}|D=1}(y) = \int F_{Y,\text{pre}|D=1,X=x}(y - \Delta(x))\,dF_{X|D=1}(x).

Usage

mdid_gt(gt_data, xformula = ~1, ...)

Arguments

gt_data

A data frame (typically a gt_data_frame from ptetools) with columns name ("pre" or "post"), D (treatment dummy), Y (outcome), id (unit identifier), .w (sampling weights), and any covariate columns referenced by xformula.

xformula

One-sided formula for covariates. Default ~1 uses no covariates. With covariates, separate weighted OLS regressions are fit on the control group in each period; see Details above.

...

Additional arguments passed through by ptetools; not used directly.

Value

A ptetools::attgt_noif object with the ATT estimate and, in extra_gt_returns, three objects: F1 (weighted ECDF of observed treated outcomes in the post period), F0 (weighted ECDF of counterfactual untreated outcomes for the treated group), and Fte (weighted ECDF of individual treatment effects; NULL for repeated cross sections).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.

Thuysbaert, Bram. “Distributional Comparisons in Difference in Differences Models.” Working Paper, 2007.


Panel QTT (Callaway-Li 2019)

Description

Computes Quantile Treatment Effects on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) using the three-period panel identification strategy of Callaway and Li (2019). Handles two-period (one post + two pre-treatment periods) and staggered treatment adoption via ptetools. Requires panel data for both groups.

Identification. Under a copula stability assumption and distributional parallel trends on changes, the counterfactual distribution FY(0)post∣D=1F_{Y(0)^{\text{post}}|D=1} is recovered from three periods of panel data without requiring rank invariance.

pre_copula. Controls which pre-treatment periods are used as the copula-transfer base for post-treatment cells (g, g+e):

"long" (default)

pre2 is as many periods before pre1 as the post period is after it, matching the copula window to the event horizon. pre1 is the last period at least anticipation before g (in units of the time variable). Cells where pre2 does not exist in the data are excluded from aggregation with two-step weight renormalization.

"short"

pre2 is the period just before pre1, always anchored at treatment onset.

Pre-test placebo cells always use the sliding base regardless of pre_copula.

Usage

panel_qtt(
  yname,
  gname,
  tname,
  idname,
  data,
  xformula = ~1,
  cond_dist = c("qr", "dr"),
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  gt_type = "att",
  probs = NULL,
  pre_copula = "long"
)

Arguments

yname

Name of the outcome variable.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable (required).

data

A data frame.

xformula

One-sided formula for covariates. Default ~1. Each unit's covariates are taken from the earliest period the group-time cell uses (the second pre-treatment period), so they are fixed across all three periods.

cond_dist

How conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

weightsname

Name of the sampling weights column. Default NULL.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

"notyettreated" (default) or "nevertreated".

anticipation

Anticipation, in units of the time variable. Default 0.

alp

Significance level. Default 0.05.

cband

Logical; uniform confidence band if TRUE (default).

biters

Number of bootstrap iterations. Default 100.

cl

Number of parallel clusters. Default 1.

gt_type

"att" (default) or "qtt".

probs

Quantile grid for gt_type = "qtt". Default seq(0.05, 0.95, 0.05).

pre_copula

"long" (default) or "short". See Details.

Value

For gt_type = "att", a pte_emp_boot object. For gt_type = "qtt", a pte_qtt object.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Callaway, Brantly and Tong Li. “Quantile Treatment Effects in Difference-in-Differences Models with Panel Data.” Quantitative Economics 10(4), pp. 1579-1618, 2019.

See Also

cic, qdid, mdid, ddid

Examples

data(mpdta, package = "did")

## Panel QTT with rolling pre-period copula (default pre_copula = "long")
res <- panel_qtt(yname = "lemp", gname = "first.treat", tname = "year",
                 idname = "countyreal", data = mpdta,
                 gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res)

Panel QTT: group-time estimator (Callaway-Li 2019)

Description

Computes the panel QTT and counterfactual outcome distribution for a single (g,t) cell using the three-period copula-stability estimator of Callaway and Li (2019). Serves directly as the attgt_fun argument to ptetools::pte.

Identification. Under copula stability

C(FYpre2∣D=1, FΔYpre∣D=1)=C(FYpre1(0)∣D=1, FΔYpost(0)∣D=1)C(F_{Y^{\text{pre2}}|D=1},\, F_{\Delta Y^{\text{pre}}|D=1}) = C(F_{Y^{\text{pre1}}(0)|D=1},\, F_{\Delta Y^{\text{post}}(0)|D=1})

and distributional parallel trends on changes

FΔYpost(0)∣D=1=FΔYctrlF_{\Delta Y^{\text{post}}(0)|D=1} = F_{\Delta Y^{\text{ctrl}}}

the counterfactual outcome for each treated unit ii is kcfi=Li+Ci,kcf_i = L_i + C_i, where Li=QYpre1∣D=1(ui)L_i = Q_{Y^{\text{pre1}}|D=1}(u_i) is the treated pre1 quantile at rank ui=FYpre2∣D=1(Yipre2)u_i = F_{Y^{\text{pre2}}|D=1}(Y^{\text{pre2}}_i) (the Rosenblatt transform), and Ci=QΔYctrl(vi)C_i = Q_{\Delta Y^{\text{ctrl}}}(v_i) is the control change at rank vi=FΔYpre∣D=1(ΔYipre)v_i = F_{\Delta Y^{\text{pre}}|D=1}(\Delta Y^{\text{pre}}_i). The goal is distributional: {kcfi}\{kcf_i\} is a sample from FY(0)post∣D=1F_{Y(0)^{\text{post}}|D=1}, not individual counterfactuals.

Panel data required for both groups. Three periods for treated (pre2, pre1, post) and two for control (pre1, post).

Usage

panel_qtt_gt(gt_data, xformula = ~1, cond_dist = c("qr", "dr"), ...)

Arguments

gt_data

A gt_data_frame with columns name ("pre2", "pre1", "post"), D, Y, id, .w, and any covariate columns.

xformula

One-sided formula for covariates. Default ~1.

cond_dist

How the conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

...

Additional arguments passed through by ptetools.

Value

A ptetools::attgt_noif object with att and, in extra_gt_returns, F0 (counterfactual ECDF), F1 (observed post ECDF), and Fte (individual-effect ECDF).

References

Callaway, Brantly and Tong Li. “Quantile Treatment Effects in Difference-in-Differences Models with Panel Data.” Quantitative Economics 10(4), pp. 1579-1618, 2019.


plot.QTE

Description

Plots a QTE object using autoplot.QTE.

Usage

## S3 method for class 'QTE'
plot(x, cband = TRUE, ylab = "QTE", ...)

Arguments

x

a QTE object, as returned by unc_qte.

cband

logical; if TRUE (default), show the uniform confidence band. If FALSE, show pointwise intervals.

ylab

label for the y-axis. Default "QTE".

...

passed to autoplot.QTE.

Value

invisibly returns the ggplot object.


Print summary.QTE

Description

Prints a summary.QTE object.

Usage

## S3 method for class 'summary.QTE'
print(x, ...)

Arguments

x

A summary.QTE object.

...

unused.

Value

None. Called for its side effect of printing.


Quantile Difference-in-Differences

Description

Computes Quantile Treatment effects on the Treated (QTT) and the Average Treatment Effect on the Treated (ATT) using the Quantile Difference-in-Differences identification strategy of Athey and Imbens (2006). Handles two-period data and staggered treatment adoption uniformly. Supports both panel and repeated cross sections data.

Usage

qdid(
  yname,
  gname,
  tname,
  idname = NULL,
  data,
  panel = TRUE,
  xformula = ~1,
  cond_dist = c("qr", "dr"),
  weightsname = NULL,
  clustervars = NULL,
  control_group = "notyettreated",
  anticipation = 0,
  alp = 0.05,
  cband = TRUE,
  biters = 100,
  cl = 1,
  ret_quantile = NULL,
  gt_type = "att",
  probs = NULL
)

Arguments

yname

Name of the outcome variable in data.

gname

Name of the treatment group variable (first treatment period; 0 for never-treated units).

tname

Name of the time period variable.

idname

Name of the unit id variable. Required when panel = TRUE.

data

A data frame.

panel

Logical; TRUE (default) for panel data, FALSE for repeated cross sections (see the section on repeated cross sections).

xformula

One-sided formula for covariates used in the covariate adjustment. Default ~1 uses no covariates. With panel data, each unit's covariates are taken from the base period of each group-time cell (never from a post-treatment period); with repeated cross sections, each observation's own values are used.

cond_dist

How conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

weightsname

Name of the column in data containing sampling weights. Default NULL uses equal weights.

clustervars

Name of a column in data to cluster standard errors on, in addition to idname (as in did::att_gt()): one variable, constant over time within each unit. Default NULL clusters at the unit level. With the empirical bootstrap, whole clusters are resampled.

control_group

Which units to use as the comparison group: "notyettreated" (default) or "nevertreated".

anticipation

Number of periods of anticipation. Default 0.

alp

Significance level for confidence bands. Default 0.05.

cband

Logical; if TRUE (default) compute a uniform confidence band rather than pointwise intervals.

biters

Number of bootstrap iterations. Default 100.

cl

Number of clusters for parallel computation. Default 1.

ret_quantile

Passed through to ptetools for the "qott" case.

gt_type

Type of group-time effect to compute. "att" (default) returns ATT(g,t). "qtt" returns the full QTT curve over probs using mixture-CDF aggregation. "qott" returns the quantile of the individual treatment effect distribution (panel only).

probs

For gt_type = "qtt", the quantile grid at which to evaluate the QTT curve. Default is seq(0.05, 0.95, 0.05).

Value

For gt_type = "att", a pte_results object from ptetools. For gt_type = "qtt", a pte_qtt object with overall, group-specific, and dynamic QTT curves and bootstrap SEs.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

Repeated cross sections

cic(), qdid(), mdid(), cdf_did() and lou_qtt(lagged_outcome_cov = FALSE) also work with repeated cross sections (panel = FALSE; idname not needed). Without covariates they use only each period's outcome distributions, so on panel data the estimates are the same either way; the standard errors differ, because the bootstrap then resamples observations rather than units. Some things need the same units in several periods and so require panel data: ddid() (each comparison unit's change over time), panel_qtt() (the copula between periods), the lagged outcome in lou_qtt(), and gt_type = "qott" (the distribution of individual treatment effects).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.

Examples

data(mpdta, package = "did")

## ATT aggregated across all groups and periods
res_att <- qdid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "att", biters = 20)
summary(res_att)

## Full QTT curve at selected quantiles
res_qtt <- qdid(yname = "lemp", gname = "first.treat", tname = "year",
                idname = "countyreal", data = mpdta,
                gt_type = "qtt", probs = seq(0.1, 0.9, 0.1), biters = 20)
summary(res_qtt)

Quantile Difference-in-Differences: group-time estimator

Description

Computes the QDiD ATT and counterfactual outcome distribution for a single 2x2 (pre/post x treated/control) data subset. Serves directly as the attgt_fun argument to ptetools::pte. Panel vs. repeated cross sections is detected automatically from whether the same unit ids appear in both periods.

Usage

qdid_gt(gt_data, xformula = ~1, cond_dist = c("qr", "dr"), ...)

Arguments

gt_data

A data frame (typically a gt_data_frame from ptetools) with columns name ("pre" or "post"), D (treatment dummy), Y (outcome), id (unit identifier), .w (sampling weights), and any covariate columns referenced by xformula.

xformula

One-sided formula for covariates. Default ~1 uses no covariates. With covariates, conditional quantile regressions are used following Athey and Imbens (2006).

cond_dist

How the conditional distributions are estimated when xformula has covariates: "qr" (default) for quantile regression or "dr" for distribution regression. See cic_gt. Ignored without covariates.

...

Additional arguments passed through by ptetools; not used directly.

Value

A ptetools::attgt_noif object with the ATT estimate and, in extra_gt_returns, three objects: F1 (weighted ECDF of observed treated outcomes in the post period), F0 (weighted ECDF of counterfactual untreated outcomes for the treated group), and Fte (weighted ECDF of individual treatment effects; NULL for repeated cross sections).

References

Athey, Susan and Guido Imbens. “Identification and Inference in Nonlinear Difference-in-Differences Models.” Econometrica 74(2), pp. 431-497, 2006.


Summary

Description

summary.QTE summarizes a QTE object, returning formatted data frames for the overall ATE and the QTE table suitable for printing.

Usage

## S3 method for class 'QTE'
summary(object, ...)

Arguments

object

A QTE object, as returned by unc_qte.

...

unused.

Value

A summary.QTE object (a list with overall_ate and qte_table data frames).


unc_qte

Description

Estimates the Quantile Treatment Effect (QTE) or Quantile Treatment Effect on the Treated (QTT) under unconfoundedness, also known as selection on observables, with cross-sectional data. The key identifying assumption is (Y(0),Y(1))⊥D∣X(Y(0), Y(1)) \perp D \mid X, i.e., potential outcomes are independent of treatment conditional on covariates XX. For staggered treatment adoption with panel or repeated cross-section data, see lou_qtt.

Three estimation methods are available via est_method:

"ipw"

Propensity-score reweighting (Firpo 2007). The propensity score p(X)=P(D=1∣X)p(X) = P(D=1|X) is estimated by logit or probit and used to reweight the sample so that the covariate distributions of the treated and untreated groups match. For the QTE, both groups are reweighted toward the population distribution; for the QTT, only the untreated group is reweighted toward the treated covariate distribution.

"reg"

Outcome regression via quantile regression inversion. rq is fit on a dense internal grid of τ\tau values, yielding a conditional quantile function QY∣X,D=j(τ)Q_{Y|X,D=j}(\tau) for each arm jj. The marginal distribution is recovered by averaging conditional quantile functions over the empirical covariate distribution (Melly 2006; Chernozhukov, Fernandez-Val, and Melly 2013).

"aipw"

Doubly-robust augmented IPW. Combines the propensity score model with the conditional quantile outcome model. The CDF estimator is consistent if either the propensity score or the outcome model is correctly specified (semiparametric efficiency when both are correct).

When xformula = ~1 (the default), all three methods reduce to simple quantile differences between the treated and untreated groups, which is consistent under unconditional unconfoundedness. Covariates are required for covariate-adjusted estimation.

Rows with a missing value in the outcome, treatment, weights or any covariate in xformula are dropped, with a warning.

Standard errors and confidence intervals are computed via the empirical bootstrap, resampling rows of data, or whole clusters when clustervars is given.

Usage

unc_qte(
  yname,
  dname,
  data,
  xformula = ~1,
  weightsname = NULL,
  clustervars = NULL,
  probs = seq(0.05, 0.95, 0.05),
  alp = 0.05,
  biters = 100,
  cband = TRUE,
  boot_type = "empirical",
  method = c("logit", "probit"),
  est_method = c("ipw", "reg", "aipw"),
  target = c("qte", "qtt"),
  cond_dist = c("qr", "dr"),
  cl = 1,
  xformla = NULL
)

Arguments

yname

character; name of the outcome variable in data.

dname

character; name of the binary treatment indicator in data (1 = treated, 0 = untreated).

data

data.frame containing the analysis data.

xformula

one-sided formula for covariates used in the propensity score and/or outcome model, e.g. ~ age + I(age^2) + education. Default ~1 uses no covariates (simple quantile differences).

weightsname

character; name of a column in data containing sampling weights. Default NULL applies equal weights.

clustervars

character; name of a column in data to cluster standard errors on (one variable). The bootstrap then resamples whole clusters instead of rows. Default NULL treats rows as independent.

probs

numeric vector of quantile levels at which to evaluate the QTE or QTT. Default seq(0.05, 0.95, 0.05).

alp

significance level for confidence intervals. Default 0.05.

biters

number of bootstrap iterations for standard errors and confidence bands. Default 100.

cband

logical; if TRUE (default), qte.lower and qte.upper form a uniform confidence band, simultaneous over all quantiles in probs: qte ±\pm c ×\times qte.se, with the bootstrap critical value c computed from draws standardized by qte.se (as the panel estimators' uniform bands are). If FALSE, they are pointwise intervals, qte ±z1−α/2\pm z_{1-\alpha/2} qte.se.

boot_type

bootstrap variant. Currently only "empirical" is supported.

method

propensity score link function: "logit" (default) or "probit". Used by est_method = "ipw" and "aipw".

est_method

estimation method; one of:

  • "ipw" (default) — inverse propensity weighting

  • "reg" — outcome regression via quantile regression inversion ("or" is a deprecated alias)

  • "aipw" — doubly-robust augmented IPW

target

target parameter; one of:

  • "qte" (default) — population QTE: QY(1)(τ)−QY(0)(τ)Q_{Y(1)}(\tau) - Q_{Y(0)}(\tau)

  • "qtt" — QTT (effect on the treated): QY(1)∣D=1(τ)−QY(0)∣D=1(τ)Q_{Y(1)|D=1}(\tau) - Q_{Y(0)|D=1}(\tau)

cond_dist

For est_method = "reg" or "aipw", how the conditional outcome distributions are estimated: "qr" (default) for quantile regression or "dr" for distribution regression (a logit of 1{Y≤y}1\{Y \le y\} on the covariates at a grid of thresholds; Chernozhukov, Fernandez-Val and Melly 2013). Ignored for "ipw".

cl

number of cores for parallel bootstrap. Default 1 (sequential).

xformla

Deprecated; use xformula. Still accepted, with a warning.

Value

An object of class QTE containing:

qte

numeric vector of estimated QTE (or QTT) at each element of probs.

ate

estimated ATE (or ATT when target = "qtt").

qte.se

bootstrap standard errors for qte (the standard deviation of the bootstrap draws).

qte.lower, qte.upper

confidence bounds for qte: a uniform band if cband = TRUE, pointwise intervals otherwise (see cband).

cband

whether qte.lower/qte.upper are a uniform band.

ate.se, ate.lower, ate.upper

SE and CI for ate.

c

bootstrap critical value for a uniform band over probs.

probs

the probs vector passed by the user.

pscore.reg

fitted propensity score glm object (without copies of the data: coef(), vcov(), summary(), fitted() and predict(newdata = ) work; anova() and update() do not), or NULL when est_method = "reg".

F.treated.t, F.treated.t.cf

ECDFs of the estimated quantiles of Y(1)Y(1) and Y(0)Y(0) at probs.

Use summary() to print a formatted table and plot() to display the QTE curve with confidence bands.

Discrete outcomes

Quantile treatment effects usually require a continuous outcome. With mass points (e.g. many zeros) or few distinct values, quantiles jump and effects at quantiles inside a mass point are 0 by construction; identification based on ranks or quantile functions (change-in-changes, quantile DiD, the panel and distributional DiD copula arguments) only bounds the effects (Athey and Imbens 2006, Section 4); and bootstrap inference for quantiles can be unreliable. The estimators warn (once per call, class qte_discrete_outcome) when more than 10\ outcome's observations share one value or it takes at most 20 distinct values, across all groups and periods; the thresholds are the options qte.mass_point_tol and qte.discrete_n_unique. The diagnostics are returned as outcome_discreteness. cdf_did is identified for discrete outcomes.

References

Firpo, Sergio. “Efficient Semiparametric Estimation of Quantile Treatment Effects.” Econometrica 75(1), pp. 259–276, 2007.

Melly, Blaise. “Estimation of Counterfactual Distributions Using Quantile Regression.” Working paper, University of St. Gallen, 2006.

Chernozhukov, Victor, Ivan Fernandez-Val, and Blaise Melly. “Inference on Counterfactual Distributions.” Econometrica 81(6), pp. 2205–2268, 2013.

Examples

data(lalonde)

## IPW, no covariates (simple quantile differences)

q1 <- unc_qte(yname = "re78", dname = "treat", data = lalonde.psid,
              biters = 20, probs = seq(0.05, 0.95, 0.05))
summary(q1)
plot(q1)


## OR with covariates, QTE

xf <- ~ age + I(age^2) + education + black + hispanic + married + nodegree
q2 <- unc_qte(yname = "re78", dname = "treat", data = lalonde.psid,
              xformula = xf, est_method = "reg",
              biters = 20, probs = seq(0.05, 0.95, 0.05))
summary(q2)


## AIPW with covariates, QTT

q3 <- unc_qte(yname = "re78", dname = "treat", data = lalonde.psid,
              xformula = xf, est_method = "aipw", target = "qtt",
              biters = 20, probs = seq(0.05, 0.95, 0.05))
summary(q3)