*! version 1 2024-01-29

Title

did_multiplegt_stat -- Estimation of heterogeneity-robust difference-in-differences (DID) estimators,
with a binary, discrete, or continuous treatment or instrument, in designs with stayers, assuming that past treatments
do not affect the current outcome.

Syntax

[bysort varlist:]
did_multiplegt_stat Y G T D [Z] [if] [in]
[,
estimator(string)
as_vs_was
exact_match
estimation_method(string)
order(#)
controls(varlist)
weights(varname)
cluster(varlist)
noextrapolation
by_fd(#)
by_baseline(#)
other_treatments(varlist)
switchers(string)
placebo(#)
disaggregate
graph_off
bys_graph_off
bootstrap(#)
seed(#)
cross_validation(cv_suboptions)
twfe(twfe_suboptions)]

Y is the outcome variable.

G is the identifier of the unit of analysis.

T is the time period variable. This variable should take integer values, and consecutive time periods should be one integer away
from each other. For instance, a bi-yearly time variable should be recoded by assigning consecutive values to years t and t+2.

D is the treatment variable.

Z (optional) is an instrumental variable.

Description

Data and design. The command uses panel data at the (G,T) level to estimate heterogeneity-robust DID estimators,
with a binary, discrete, or continuous treatment (or instrument). The command can be used in designs where there is at least one
pair of consecutive time periods between which the treatment of some units, the switchers, changes, while the treatment of some
other units, the stayers, does not change.

Target parameters.
The command can estimate the Average Slope (AS) and the Weighted Average Slope (WAS) parameters
introduced in de Chaisemartin et al (2022).
The AS is the average, across switchers, of (Y_t(D_t)-Y_t(D_)/(D_t-D_), the effect
on their period-t outcome of moving their period-t
treatment from its period-(t-1) to its period-t value, scaled by the difference between these two values. The WAS is a weighted
average of switchers' slopes (Y_t(D_t)-Y_t(D_)/(D_t-D_), where slopes receive a weight proportional to |D_t-D_|,
switchers’ absolute treatment change from period-(t-1) to period-t. The variance of the WAS estimator is often smaller
than that of the AS estimator, especially when there are switchers that experience a small treatment change.
The WAS estimator is also amenable to doubly-robust estimation, unlike the AS estimator.

Assumptions.
When the data has more than two time periods, the command assumes a static model: units' outcome at period t only depends on their period-t
treatment, not on their lagged treatments. See the did_multiplegt_dyn command for estimators allowing for dynamic effects.
The command also makes a parallel trends assumption: the counterfactual outcome evolution
switchers would have experienced if their treatment had not changed is assumed to be equal to
the outcome evolution of stayers with the same baseline treatment. Importantly, this parallel-trends
assumption is conditional on the baseline treatment: comparing switchers and stayers
with different baseline treatments would implicitly amount to assuming that the treatment's
effect is constant over time.
To test the parallel trends assumption underlying the estimators,
the command can compute placebo estimators comparing
the outcome evolution of switchers and stayers with the same baseline treatment before switchers' treatment changes.

Estimators, when the exact_match option is specified.
With a binary or discrete treatment, if the exact_match option is specified, the estimators computed by the command compare the
outcome evolution of switchers and stayers
with the same period-(t-1) treatment. Then, the WAS estimator computed by did_multiplegt_stat
is numerically equivalent to the DID_M estimator proposed by
de Chaisemartin and D'Haultfoeuille (2020),
and already computed by the did_multiplegt_old command. did_multiplegt_stat uses an analytic formula
to compute the estimator's variance, while did_multiplegt_old uses the bootstrap.
Thus, the run time of did_multiplegt_stat is typically much lower.
The exact_match option can only be specified when the treatment is binary or discrete:
with a continuously distributed treatment, one cannot find switchers and stayers
with the exact same period-(t-1) treatment.
With a discrete treatment taking a large number of values, specifying this option may be undesirable:
then, there may only be few switchers that can be
matched to a stayer with the exact same period-(t-1) treatment, thus restricting the estimation sample.

Estimators, when the exact_match option is not specified.
When the exact_match option is not specified, the command can use a regression adjustment to recover switchers'
counterfactual outcome evolution: for all t, it runs an OLS regression of Y_t-Y_ on a polynomial in D_ in the sample of (t-1)-to-t stayers,
and uses that regression
to predict switchers' counterfactual outcome evolution. Alternatively, when it estimates the WAS, the command can also use propensity-score
reweighting to recover switchers' counterfactual outcome evolution. First, for all t it estimates a logistic regression of an indicator
for (t-1)-to-t switchers on a polynomial in D_, to predict units' probability of being a switcher.
Then, it computes a weighted average of stayers' outcome evolution, upweighting stayers with a large probability of being switchers,
and downweighting stayers with a low probability of being switchers. Finally, when it estimates the WAS, the command can also combine
regression-adjustment and propensity-score reweighting, thus yielding a doubly-robust estimator.

Instrumental-variable case.
There may be instances where the parallel-trends assumption fails, but one
has at hand an instrument satisfying a similar parallel-trends assumption. For instance, one may
be interested in estimating the price-elasticity of a good's consumption, but prices respond to
supply and demand shocks, and the counterfactual consumption evolution of units experiencing and not experiencing a price
change may therefore not be the same. On the other hand, taxes
may not respond to supply and demand shocks and may satisfy a parallel-trends assumption. In such cases, the command
can compute the IV-WAS estimator introduced in
de Chaisemartin et al (2022).
The IV-WAS estimator is equal to the WAS estimator of the instrument's reduced-form effect on the outcome controlling for D_, divided by the
WAS estimator of the instrument's first-stage effect on the treatment controlling for D_.
See de Chaisemartin et al (2022) for some explanations as to why controlling for D_
is desirable in IV estimation.

Options

Main options

estimator(string) gives the name(s) of the estimator(s) to be estimated. The allowed arguments are: (1) as, (2) was,
and (3) iv-was.

exact_match: with this option, the DID estimators computed by the command compare the outcome evolution of switchers and stayers
with the same period-(t-1) treatment (or instrument) value. This option can only be used when the treatment (or instrument) is binary or discrete:
with a continuously distributed treatment (or instrument), one cannot find switchers and stayers
with the exact same period-(t-1) treatment (or instrument).
With a discrete treatment taking a large number of values, specifying this option may be undesirable: then, there may only be few switchers that can be
matched to a stayer with the exact same period-(t-1) treatment, thus restricting the estimation sample.

estimation_method(string): when the exact_match option is not specified and estimation of the WAS or IV-WAS is requested,
this option can be used to specify which estimation method to use when estimating the WAS or IV-WAS.
The allowed arguments are: (1) ra (regression adjustment), (2) ps (propensity-based reweighting), and (3) dr (doubly-robust).
By default, a doubly-robust estimator is used.

order(#): when the exact_match option is not specified,
this option specifies the polynomial order to be used in the OLS regressions of Y_t-Y_ on a polynomial in D_
and/or in the logistic regressions of an indicator for (t-1)-to-t switchers on a polynomial in D_.
By default, a polynomial of order 1 is used.

placebo(#): when this option is specified, the command computes the
placebo version of each estimator requested. Actual estimators compare the
t-1-to-t outcome evolution of period t-1-to-t switchers and stayers with the same baseline
treatment. When # is equal to 1, placebo estimators compare the
t-2-to-t-1 outcome evolution of period t-1-to-t switchers and stayers with the same baseline
treatment, restricting attention to t-2-to-t-1 stayers. Thus, placebos assess whether switchers and stayers were on parallel trends just before
switchers switched treatment. When # is strictly larger than 1, placebos comparing the outcome evolutions of t-1-to-t switchers and stayers from
t-3 to t-2, from t-4 to t-3,... , and from t-#-1 to t-# are also reported, always restricting attention to stayers between those pairs
of periods.

as_vs_was: shows a test that the AS and WAS are equal. This option can only be used when estimation of the AS and WAS is requested.

controls(varlist): the command can compute estimators with control variables. They rely on a conditional parallel trends assumption:
the counterfactual outcome evolution switchers would have experienced if their treatment had not changed is assumed to be equal
to the outcome evolution of stayers with the same baseline
treatment, and with the same value of varlist. When time-varying control variables are inputted to the command, the command compares the
t-1-to-t outcome evolution of switchers and stayers with the same baseline
treatment, and with the same controls at period t-1.
Specifying too many control variables may lead to noisy estimators. If placebo estimators are small, insignificant and precisely estimated without
control variables, including control variables may not be necessary.

weights(varname) : This option allows to compute estimators weighted by varname.

Options to estimate heterogeneous treatment effects

switchers(string): if the argument up is inputted, the command estimates the AS, WAS, or IV-WAS
for switchers-up only, i.e for units whose treatment (or instrument) increases from period (t-1) to t. If the argument down
is inputted, the command estimates the AS, WAS, or IV-WAS for switchers-down only, i.e. for units whose treament (or instrument)
decreases from period (t-1) to t. By default, the command estimates those parameters for all switchers.

by_fd(#): This option can be used if one wants to assess the heterogeneity of the effect
according to the absolute value of the treatment's (or instrument's) change.
For example, if by_fd(5) is specified, the command
splits switchers into 5 groups: the 20% with the lowest |Delta D_t| (or |Delta Z_t|), and then the next 20%, etc..
Then the command estimates treatment effects for each subsample. If |Delta D_t| has mass points, the command splits switchers into
groups with as-equal-as-possible sizes.

by_baseline(#): This option is similar to the option by_fd(#), except that switchers
are split into subsamples according to their values of D_ (or Z_).

[bysort varlist:] makes did_multiplegt_stat byable. See [D] by. Only time-invariant variables are allowed in varlist.

Standard-error options

bootstrap(#): If the number of switchers or the number of stayers is low,
one may want to check if the analytic standard errors produced by the command are close to
bootstrap standard errors. If they are not, this may indicate that the asymptotic approximation underlying the analytic standard errors may not be reliable.
In that case, there is of course no guarantee that bootstrap standard errors are valid: this comparison is just a diagnostic check
researchers may use to assess if they need to resort to inference methods that do not rely on asymptotic approximations, like permutation tests.
The bootstrap option takes as argument the number of replications. Currently, it is only allowed when the IV-WAS is requested,
as failure of asymptotic approximations are more likely to arise with IV estimators, when the first-stage is weak.

seed(#): This option is only needed when one is using the bootstrap, and it allows to set the seed so as to ensure replicability of the results.

cluster(varlist) : This option allows clustering standard errors at the level of varlist.

Advanced options

other_treatments(varlist) : This option allows controlling for other treatments (in varlist )
that may also change over the panel, see de Chaisemartin and D'Haultfoeuille (2021)
for further details.

noextrapolation: when this option is specified, the command only keeps switchers whose period-(t-1) treatment (or instrument)
is between the minimum and the maximum values of the period-(t-1) treatment (or instrument) of stayers, thus enforcing the overlap condition.

TWFE Comparison

The command allows to compare the estimator specified in estimator() to a TWFE-estimator,
computed via a regression of Y_ on D_ and unit and year fixed effects.
If the iv-was is specified in estimator(), a 2SLS-TWFE is used, using Z_ as the instrument.
With the option twfe, did_multiplegt_stat, on top of the main results,
diplays a table showing the difference between the estimator requested and the TWFE-estimator, the p-value of the test of the difference and the
corresponding condidence interval.
By default, the command runs the test using 100 bootstrap replications.
To increase the number of replications, the user can use the option bootstrap(#) of did_multiplegt_stat.
Also for replicability you should consider using the seed(#) option.

To use the twfe(twfe_suboptions) option you need to specify
which sample you want to estimate the TWFE regression on, so you should always specify
either the full_sample or the same_sample suboption. Further note that when you want to use the twfe option
you can specify only one of the three estimators (was/as/iv-was) available in estimator(string).

twfe_suboptions

same_sample Sometimes, did_multiplegt_stat might not use all time periods in the estimation.
For instance, one might have a panel data where at a particular time (say p) there
is no switcher. In that case, did_multiplegt_stat does not use the pair of periods (p-1, p). Then, the ( as, was, or iv-was)
estimator and the TWFE-estimator will rely on different samples.
To avoid such discrepancy, the option same_sample allows to estimate the TWFE-estimator using the same sample
as did_multiplegt_stat.

full_sample Counterpart to the same_sample option. Use this in case you do not want to impose the sample restrictions
described in same_sample and estimate the TWFE regression in the full sample instead.

percentile By default, did_multiplegt_stat computes the s.e and p-value of the test of the difference
between the (as, was, or iv-was) estimator and the TWFE-estimator
using a t-test and a normal approximation. Instead, one may use the percentile boostrap. Then, one can specify the option percentile
to compute p-values and confidence intervals using the percentile bootstrap method.

Cross-validation

If the treatment is continuous (or if the option exact_match is not specified), and the doubly-robust WAS estimator
is used, instead of specifying the order of the polynomial series
that did_multiplegt_stat uses
to estimate E(Y_t-Y_|D_), P(S_=0|D_), P(S_{+, t}=1|D_), and P(S_{-, t}=1|D_), one may use cross validation.
Then, the command will choose the polynomial order with the best fit. This option can only be used
to compute the doubly-robust WAS estimator: cross-validation does not have proven theoretical guarantees for the other estimators.

To use cross validation you have to specify cross_validation(algorithm(string) cv_suboptions).
The algorithm(string) suboption is required for the cross_validation(cv_suboptions) to function
and has therefore to be specified in any case.

cv_suboptions

algorithm(string) This option specifies which cross-validation algorithm to use.
For now, the allowed argument is kfolds.

tolerance(#) This option allows to set a stop criterion based on the gain in prediction power.
By default, tolerance is set to 0. If tolerance is set, say, to 0.01, the cross-validation stops when the gain in prediction power when
increasing the polynomial order is less than 1%.

max_k(#) This is another stop criterion based on the maximum order to test (the grid-search of the hyperparameter).
By default, the value is set to 5, meaning that the algorithm will look for the best model starting from a polynomial of order 1
to a polynomial of order 5 as long as the tolerance is not reached.

kfolds(#) If kfolds is specified in algorithm(), this option specifies the number of folds to consider.
By default, the number of folds is set to 5.

seed(#) This option allows to set the seed so as to ensure replicability of the results.

Display

disaggregate: when this option is specified, the command shows the estimated AS, WAS, or IV-WAS effects for each
pair of consecutive time periods, on top of the effects aggregated across all time periods. By default, the command only shows
effects aggregated across all time periods.

graph_off: The program displays by default a graph of the aggregated
results (coefficients, effects and placebos, and their confidence intervals). If graph_off is specified,
the graph is not displayed.

bys_graph_off: If the program is by'd (i.e. ran with [bysort varlist:]), or used with the option by_fd(#)
or by_baseline(#), it automatically displays a graph of the aggregated
results (coefficients and confidence intervals) by level of varlist, or quantiles, respectively. If bys_graph_off is specified,
the graph is not displayed.

Notes

1. The command is compatible with estout

2. The command is byable. See [D] by.

Examples

These examples follow Section 7 of de Chaisemartin et al (2022).
The dataset used is an excerpt of that of Li et al (2014),
which contains gasoline taxes, prices, and consumption for 48 US states, every year from 1966 to 2008. It can be downloaded by running:

ssc install did_multiplegt_stat

net get did_multiplegt_stat

use gazoline_did_multiplegt_stat.dta, clear

Example 1: Estimating the effect of gasoline taxes (tau) on log gasoline price (lngpinc)

did_multiplegt_stat lngpinc id year tau, or(1) estimator(as was) placebo(3) as_vs_was

Example 2: Estimating the effect of gasoline taxes (tau) on log gasoline consumption (lngca)

did_multiplegt_stat lngca id year tau, or(1) estimator(as was) placebo(3) as_vs_was

References

de Chaisemartin, C, D'Haultfoeuille, X, Pasquier, F, Vazquez‐Bare, G (2022)
Difference-in-Differences for Continuous Treatments and Instruments with Stayers.

de Chaisemartin, C, D'Haultfoeuille, X (2020)
Two-Way Fixed Effects Estimators with Heterogeneous Treatment Effects.

de Chaisemartin, C, D'Haultfoeuille, X (2021)
Two-way Fixed Effects and Differences-in-Differences Estimators with Several Treatments.

Li, S, Linn, J, Muehlegger, E (2014)
Gasoline Taxes and Consumer Behavior.

Authors

Clément de Chaisemartin, Economics Department, Sciences Po, France.

Diego Ciccia, Sciences Po, France.

Xavier D'Haultfoeuille, CREST-ENSAE, France.

Felix Knau, Sciences Po, France.

Felix Pasquier, CREST-ENSAE, France.

Doulo Sow, Sciences Po, France.

Gonzalo Vazquez-Bare, UCSB, USA.

Contact

chaisemartin.packages@gmail.com

Stored results

Scalars

e(N) The number of observations.

Macros

e(depvar) The dependent variable's name.

Matrices

Aggregated point estimates

e(b) The point estimates of the aggregated versions of the estimators.

e(V) The variance matrix.

Effects' estimation

e(AS) The results for AS.

e(WAS) The results for WAS.

e(IWAS) The results for IVWAS.

Placebos' estimation

e(PlaceboAS) The results for AS.

e(PlaceboWAS) The results for WAS.

e(PlaceboIWAS) The results for IVWAS.

If the program is by'd, for each level ℓ of varlist:

e(AS_ℓ) The results for AS.

e(WAS_ℓ) The results for WAS.

e(IWAS_ℓ) The results for IVWAS.

e(PlaceboAS_ℓ) The results for AS.

e(PlaceboWAS_ℓ) The results for WAS.

e(PlaceboIWAS_ℓ) The results for IVWAS.

If the program is by'd, and the option by_fd(#) or by_baseline(#) is specified, for each level ℓ of varlist, and for each level k of quantile:

e(AS_ℓ_k) The results for AS.

e(WAS_ℓ_k) The results for WAS.

e(IWAS_ℓ_k) The results for IVWAS.

e(PlaceboAS_ℓ_k) The results for AS.

e(PlaceboWAS_ℓ_k) The results for WAS.

e(PlaceboIWAS_ℓ_k) The results for IVWAS.