help for causalrep did

Title

causalrep did -- Quantifying the internal validity and representativeness of the
TWFE estimand

Syntax

causalrep did
groupvar
timevar
[if] [in],
treatment(varname) [options]

Required
treatment(varname) specify a treatment variable coded 0 for untreated observations
and 1 for treated observations

Optional
outcome(varname) specify an outcome variable; if omitted, no outcome regression
is estimated

cate(varname) specify a variable that stores the values of the conditional
(group-time) average treatment effect (CATE) function; cate() requires outcome() to be specified

noisily display the outcome-regression results when outcome() is specified

vce(vcetype) specify the variance estimator for the TWFE outcome regression; vcetype
may be ols, robust, cluster clustvar, bootstrap, jackknife,
hc2, or hc3; vce() is relevant only when outcome() is specified; default
is cluster groupvar

Description

causalrep did estimates the measure of internal validity (MIV) and the measure of
representativeness (MR) of the TWFE estimand, as proposed by Poirier and Słoczyński (2026). Under
the parallel trends assumption, this estimand can be written as a weighted average of conditional
(group-time) average treatment effects.

When the CATE function is unrestricted and the weights are nonnegative, the MIV equals the
inverse maximum weight. It is the largest possible share of the treated subpopulation for
which the TWFE estimand can be represented as an average treatment effect. By contrast, the MR
is the largest possible share of the entire population for which such a representation is
possible. It is equal to the product of the MIV and the proportion of treated units.

When negative estimated weights are detected, the value reported as MIV when the CATE function
is unrestricted is the inverse maximum weight. If any population weights are negative, the
unrestricted-CATE MIV and MR are zero. See Poirier and Słoczyński (2026) for details.

If outcome() is omitted, the command estimates the MIV and MR using only the treatment,
group, and time variables. If outcome() is specified, the command also estimates the
TWFE coefficient and posts its coefficient vector and variance–covariance matrix.

If cate() is specified, the command additionally estimates the MIV and MR given the
supplied CATE function. The supplied CATE values are treated as fixed, and their estimation
uncertainty is not incorporated. They are required to be nonmissing for every treated
observation in the estimation sample.

outcome() is required when cate() is specified because the CATE-based calculation
compares the supplied CATE values with the estimated TWFE coefficient.

If the TWFE estimate lies outside the range of the supplied CATE values, the CATE-based MIV is
zero. If the TWFE estimate equals the mean of the supplied CATE values for the treated units,
the CATE-based MIV is one. The CATE-based MIV can be positive even when the unrestricted-CATE
measure is zero.

causalrep did requires the time variable to take integer values and a balanced
group–period structure in the estimation sample. Every group must be observed in the same set
of periods, and, within each group, the number of observations in each group–time cell must be
constant over time. Multiple observations per group–time cell are allowed, and cell sizes may
differ across groups. Treatment must be constant within each group–time cell, no group may be
treated in the first sample period, and once a group becomes treated, it must remain
treated. The command returns an error if missing values or if/in restrictions cause these
conditions to fail.

This is a companion software package for Poirier and Słoczyński (2026). Please cite this paper
if you use causalrep did in your work.

References

Poirier, Alexandre, and Tymon Słoczyński (2026). "Quantifying the Internal Validity
of Weighted Estimands." arXiv preprint arXiv:2404.14603. Available at https://arxiv.org/abs/2404.14603.

Examples

Load data from Goodman-Bacon (2021):

. use http://fmwww.bc.edu/repec/bocode/b/bacon_example.dta, clear

Drop always-treated states and states excluded by Goodman-Bacon (2021):

. drop if stfips==22 | stfips==24 | stfips==37 | stfips==40 | stfips==49 | stfips==50 | stfips==51 | stfips==54

Estimate the MIV of the TWFE estimand:

. causalrep did stfips year, t(post)

In Stata 18 or later, estimate the group–time ATT using xthdidregress twfe:

. xthdidregress twfe (asmrs) (post), group(stfips)

. matrix atets = e(b)

. " + trim(string(year)) + ".year")) if post==1"'

Estimate the MIV of the TWFE estimand, including conditional on the estimated group–time ATT values:

. causalrep did stfips year, t(post) o(asmrs) cate(att)

Display stored estimation results:

. ereturn list

Stored results

causalrep did stores the following in e():

Always stored

e(N) number of observations

e(miv) estimate of the inverse maximum weight; this is the MIV when the CATE function is unrestricted and the weights are nonnegative

e(mr) product of the estimate of the inverse maximum weight and the proportion of treated units; this is the MR when the CATE function is unrestricted and the weights are nonnegative

e(cmdline) command line

e(cmd) causalrep

e(subcmd) did

e(sample) marks estimation sample

Only when outcome() is specified

e(twfe) estimated coefficient on the treatment variable in the TWFE regression

e(depvar) name of dependent (outcome) variable

e(b) estimated coefficient vector, as obtained by regress

e(V) estimated variance–covariance matrix, as obtained by regress

e(df_r) residual degrees of freedom, as obtained by regress

Only when cate() is specified

e(att) estimate of the ATT based on the supplied CATE values

e(miv_cate) estimate of the MIV based on the supplied CATE values

e(mr_cate) estimate of the MR based on the supplied CATE values

License

This package is licensed under the MIT License. See the LICENSE
file included with the distribution.

Authors

Alexandre Poirier, Georgetown University

Email: alexandre.poirier@georgetown.edu

Tymon Słoczyński, Brandeis University

Email: tslocz@brandeis.edu