help allsynth

Title

Beta version 1.0 - Release date: May 6, 2022. Tested on Stata 15.1 and above. Email bug reports to: jcwiltshire@ucdavis.edu

allsynth -- Automates estimation of (i) bias-corrected synthetic control gaps ("treatment effects"); (ii) RMSPE-ranked p-values from
"in-space" treatment permutations; and (iii) "stacked" synthetic controls (with many treated units and potentially staggered treatment timing); and also provides heavily-automated
graphing functionality. See Wiltshire (2022) for a thorough review of allsynth

Syntax

allsynth depvar predictorvars , trunit(#) trperiod(#) [ synth_options
pvalues bcorrect(string) gapfigure(string) transform(string) stacked(string) ]

The data must be declared as a (balanced) panel using tsset (or xtset) panelvar timevar.
The variables specified in depvar and predictorvars must be numeric and must not be abbreviated.

The commands synth, distinct and elasticregress must be installed. The synth command should be understood prior to
implementation of allsynth.

Description

allsynth is a wrapper for the synth command which automates the implementation of several additional features. The primary extensions are:
(1) automated estimation of "bias-corrected" synthetic control gaps to adjust for discrepancies in predictor variable values between a treated
unit and its donor pool, proposed by Abadie and L'Hour (2021) and
Ben-Michael, Feller and Rothstein (2021);
(2) automated estimation RMSPE-ranked p-values based on in-space placebo tests (for "classic" and "bias-corrected" specifications) in which
treatment status is randomly permuted across untreated units (Abadie, Diamond and Hainmueller (2015));
(3) automated estimation of a "stacked" synthetic control estimator with many treated units and potentially staggered treatment timing
(Dube and Zipperer (2015), Wiltshire (2021)),
yielding estimates of the average treatment effects and (if desired) associated RMSPE-ranked p-values for both classic and bias-corrected specifications; and
(4) greatly expanded automated graphing capability. allsynth also provides additional diagnostics and warnings to help practitioners with its usage.

Required Settings

As with the synth command, allsynth requires specification of depvar (the outcome variable),
predictorvars (the list of predictor variables, including if specified only for specific periods),
the option trperiod(#), where # is observed in the panel
time variable specified in tsset timevar and which corresponds to the earliest intervention period, and the
option trunit(#), where # is observed in the panel unit variable specified in
tsset unitvar and which corresponds to the unit which received the intervention. The allsynth options
have further requirements and options, where [...] indicates optional specifications and A|B indicates at least
(sometimes exactly) one of A or B must be specified. Users should not include the symbols [, ], or |.

allsynth Options

Several allsynth options interact with each other, and some are contingent on others being specified.
Informative warnings are returned if the specified options need to be changed.

pvalues automates estimation of in-space placebo gaps across the donor pool units, then calculates RMSPE-ranked p-values
for each post-treatment period.

If the bcorrect() option is also specified, then the bias-corrected placebo gaps and p-values
will also be calculated. pvalues must be specified for the placebo gaps to be plotted (see the entry on the gapfigure()
option, below). Specifying pvalues will greatly extend the run-time of allsynth, and so it is assumed that the results should
be saved. Accordingly, the keep(file) option must be specified if pvalues is specified. The variables RMSPE,
RMSPE_rank, and p (and their bias-corrected equivalents, if bcorrect() is also specified) will be merged into file.

bcorrect(nosave|merge [ ridge|lasso|elastic|posonly figure ]) specifies that the bias-corrected synthetic control estimates should be
calculated alongside the classic synthetic control estimates.

Exactly one of nosave or merge are required. If merge is specified, keep(file) must also be specified.
With merge, the the variables gap and gap_bc containing the classic and bias-corrected gaps, as well as the variables _Y_treated_bc and _Y_synthetic_bc
containing the bias-corrected outcome paths, are merged into file. With nosave, none of the additional elements from the bias-correction
procedure will be saved and keep(file) need not be specified.

Users may also specify additional bcorrect() options:

(1) Exactly one of ridge, lasso, elastic, or posonly may be specified if the bias is to be estimated
using (respectively) ridge regression, lasso regression, elastic net regression, or ordinary least squares (OLS) regression with only those
donor pool units for which the synthetic-control-estimated w weights are strictly positive. The default setting is to use OLS regression
with all donor pool units to estimate the bias. See elasticregress. Values for labmda, alpha, and the number of folds may not be specified.
Note that specifying ridge, lasso, or elastic may greatly increase the run-time.

(2) figure specifies that, analogous to figure in synth_options, a plot should be generated which shows the trajectories
of the bias-corrected values of the outcome variable for the treated unit and its synthetic control. Most practitioners will have an interest
only in the difference rather than in these variables individually; however, visual examination of this plot may be instructive.

gapfigure(classic|bcorrect [ placebos lineback, save(file) [, replace ]) twoway_options ]) can be used to
automatically generate a plot of the trajectories of (at most two of) the estimated gaps, bias-corrected gaps, the set of placebo gaps, or
the set of bias-corrected placebo gaps. The bias-corrected gaps and placebo gaps can only be plotted if the allsynth option bcorrect()
is specified, and the placebo gaps can only be plotted if the allsynth option pvalues is specified. If bcorrect() is specified,
only the bias-corrected gaps and placebo gaps can be plotted.

At least one of classic or bcorrect must be specified, though both may also be specified if the placebos option
(see option (1), below) is not specified. classic plots the classic estimated gaps for the treated units, and bcorrect plots the bias-corrected
estimated gaps for the treated unit.

Users may also specify additional gapfigure() options:

(1) placebos plots the (classic or bias-corrected) estimated placebo gaps from in-space treatment permutations, and may only
be specified if the allsynth option pvalues is also specified. placebos may be specified with either classic or
bcorrect, but not both. If the allsynth option bcorrect() is specified, then placebos may only be specified with bcorrect.

(2) lineback places a vertical dotted line on the plot in the final pre-treatment period. The default setting places a vertical dotted line on the
plot in the treatment period.

(3) save(file) specified that the plot should be saved to the indicated file, which may include a filepath and a filename.
The default file extension is .pdf but another extension may be specified. replace may be specified after a comma if any identically-named
file should be overwritten, as in save(file, replace).

(4) twoway_options may be specified to modify the plot as desired (see twoway_options), but note that titles of any kind must not
be contained in quotations and will not display a comma if one is indicated.

transform(varlist, demean|normalize) can be used to automatically transform specified variables in exactly one of two ways prior to synthetic control estimation:
the variables can be demeaned over the pre-treatment period, or can be normalized to 100 in the final pre-treatment period. Only one transformation
type may be specified.

varlist indicates the variables that will be transformed. At least one variable must be specified. Exactly one of demean or
normalize must be specified. demean will (by unit) demean the specified variables over the entire pre-treatment period. normalize
will (by unit) normalize all specified variables to 100 times the value in a given pre-treatment period t divided by the value in the treated unit
i's final pre-treatment period (note the donor pool units for i will also be normalized to i's final pre-treatment period). Also note
that this necessitates that no variable in varlist have its value in the final pre-treatment period alone be specified as a predictor.

stacked(trunits(varname) trperiods(varname) , clear [ eventtime(numlist) avgweights(varname)
balanced donorcond(string [, string ]) donorcond2(string [, string ]) donorcond3(string [,
string ]) donorcond4(string [, string ]) donorif(string) unique_w sampleavgs(real)
figure(classic|bcorrect [ placebos lineback, save(file) [, replace ]) twoway_options ]) can be used to automatically
estimate the average treatment effect on the treated units using a stacked synthetic control estimating strategy.

Users may specify if the estimates should be calculated in event time or calendar time (where either are possible), may specify whether
estimates should be balanced in the specified time-type periods, may specify unit-specific weights for calculation of the averages, and may specify
whether the averages should include only unit-estimates associated with unique estimated W matrices. Users may also specify conditions for
selecting treated-unit-specific donor pools.

Users may additionally specify the automatic generation of a distribution of sampled average placebo gaps and calculate RMSPE-ranked p-values
from that distribution, and may specify the number of placebo average gaps included in the sample distribution.

Similarly to the gapfigure() option (see above), stacked() allows users to automatically generate a (customizable) plot of the
trajectories of (at most two of) the estimated average gaps, bias-corrected average gaps, the set of placebo average gaps, or the set of
bias-corrected placebo average gaps, all in event time, or in calendar time when units are treated simultaneously.

The allsynth option keep(file) must be specified if stacked() is specified, and the treated-unit-specific results for
each treated unit i will be saved in filename_panelvar_i.dta, while the estimated average gaps by time period will be saved in
filename_ate.dta. If the allsynth option pvalues is specified, then the estimated average gaps, placebo gaps, RMPSE, and
RMSPE-ranked p-values will be saved in filename_ate_distn.dta.

trunits(varname) is required, and varname must identify a dummy variable that, in all periods, identifies the treated units with a 1
and the donor pool units with a 0. trperiods(varname) is required, and varname must identify an integer variable that, in all periods, contains
the timevar period of treatment (assumed to be in calendar time) for every treated unit. If the treatment is simultaneous in timevar for all
treated units i, results will be displayed and saved in timevar periods (assumed to be calendar periods); otherwise, results will be displayed and
saved in event time, with each treatment period converted to event period zero. clear is required and must be specified after a comma. note that
stacked() will clear all files with the file name specified in the allsynth option keep(file) from the specified directory or from the working
directory if no directory is specified in keep(file). Note also that the option keep(file, replace) is required in synth_options
when stacked() is specified.

Users may also specify additional stacked() options:

(1) eventtime(numlist) must specify exactly two integers--one strictly negative, the other strictly positive--
which identify the event-time window over which the final results should be displayed and saved. No other symbols are allowed. Note that
eventtime() will not restrict the period over which the pre-treatment MSPE is minimized (see synth). stacked() will use whichever
event window is smaller out of that specified in eventtime() and what is observed in any treated unit (or in a balanced sample across all
treated units if the balanced option is specified. The default setting is the smaller of eventtime(-5 5) and the (possibly balanced)
window observed over the treated units.

(2) avgweights(varname) specifies a numeric variable that identifies the treated-unit weights to be used to calculated the
(weighted) average treatment effects. For each treated unit i the weights must be non-missing and constant across all timevar periods.

(3) balanced specifies that the estimated average treatment effects (gaps) should be displayed and saved only for those event periods
in which every treated unit is observed. This ensures common interpretability of the estimated average gap across retained event periods (this
is true even if the results are displayed and saved in calendar time).

(4) donorcond(string [, string]), donorcond2(string [, string]), donorcond3(string [, string]),
and donorcond4(string [, string]) permit users to temporarily modify the data while estimating all parameters associated with each
treated unit i. This allows the user to set i-specific restrictions on the data for the purpose of restricting the donor pool for i
to only those untreated units. donorcond(), ..., donorcond4() each permit a comma to separate two unique lines of code, such that up to
eight total commands may be executed to set up the restriction of each of i's donor pool units.

(5) donorif(string) permits users to specify a condition under which the untreated units should be kept in i's donor pool.
donorif(string) imposes keep if... before string entry, so users should not include "keep if..." in string.
donorif() only applies to untreated units, and treated unit i is always retained, so users should not specify
donorif(string) to condition on being an untreated unit.

(6) unique_w specifies that only treated units i with unique estimated W matrices should be included in the estimated
average treatment effect.

(7) sampleavgs(real) specifies an integer >=30 which is the number of placebo average gaps that should be sampled from the
population of possibilities. The default setting is 100.

(8) figure(classic|bcorrect [ placebos lineback, save(file) [, replace ]) twoway_options ])
can be used to automatically generate a plot of the trajectories of (at most two of) the estimated average gaps, average bias-corrected gaps, the
set of placebo average gaps, or the set of average bias-corrected placebo gaps. It will plot these in the time type (calendar time or event time)
of the estimates (see the entry for eventtime(), above). The bias-corrected gaps and placebo gaps can only be plotted if the allsynth
option bcorrect() is specified, and the placebo gaps can only be plotted if the allsynth option pvalues is specified. figure()
uses the same syntax as the allsynth option gapfigure(), but unlike gapfigure() it is possible to specify figure(classic placebos)
even if the allsynth option {cmd:bcorrect() is specified. As with gapfigure(), the plot can also be customized and saved. See the syntax
for gapfigure() for further explanation of the syntax for figure().

Regardless of whether any of the aforementioned additional options available with allsynth are specified,
allsynth analyzes the W weighting matrix for (likely) uniqueness.
Warnings are produced if the W matrix is not sparse (if there is not at least one w-weight equal to zero)
or if the W matrix has more non-zero weights than predictor variables.

Examples

Important note: To use allsynth (and run these examples), the packages synth (type ssc install synth, replace all),
distinct (type ssc install distinct), and elasticregress (type ssc install elasticregress) must be installed with the ancillary data.

Examples 1-10 illustrate the use of allsynth when the stacked() option is not specified, making use of the synth ancillary data
from Abadie, Diamond and Hainmueller (2010).

Examples 11-13 illustrate the use of allsynth when the stacked() option is specified, making use of a subset of the ancillary data
from Wiltshire (2021) and Wiltshire (2022).

Examples 1-10:

Load the example data from Abadie, Diamond and Hainmueller (2010).
This contains panel observations for 39 US states over the years 1970-2000:

use synth_smoking

Declare the dataset as a panel:

tsset state year

Example 1 - Use allsynth exactly as you would use synth to reconstruct the estimate from the synth help file (note: this is not
the exact specification used in Abadie, Diamond, and Hainmueller (2010)):

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989)

This produces the same output as would have been produced if the synth command had been used in place of allsynth, as well as
additional stored results in e(results), e(unique_W), and e(gaps). If keep(file) had been specified,
additional variables would also have been saved to file. allsynth additionally cautions that no bias correction or
p-value calculations have been specified or provided.

Example 2 - Use allsynth exactly as you would use synth:

allsynth cigsale beer retprice cigsale(1980), trunit(3) trperiod(1989)

These results could also have been realized using the synth command in place of allsynth, but the reduction in dimensionality
of the predictor variables (relative to Example 1) has resulted in the synthetic control optimization estimating a estimated W matrix
with more non-zero weights than predictor variables, which is likely not unique. The produced output still includes what would have been produced
if the synth command had been used in place of allsynth, as well as additional stored results in e(results), e(unique_W),
and e(gaps). Unlike synth, however, allsynth cautions that the estimated W matrix is likely not unique and suggests
some ad hoc fixes.

Example 3 - Calculate, display, and save the classic and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome, and plot the
bias-corrected outcome paths of the treated unit and its synthetic control:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcorrect(merge figure) keep(smokingresults) replace

This example reproduces the estimation in Example 1, but as bcorrect() and its own figure option are specified, it also calculates
the classic and the (OLS regression estimated) bias-corrected gaps for each period (for the treated unit, 3, which is California), while plotting the bias-corrected outcome
paths of the treated unit and its synthetic control. The classic results are saved in the working directory as smokingresults.dta as the keep()
command is specified, and because bcorrect(merge) is also specified those results are merged and saved to the same file, and the variables
_Y_treated and _Y_synthetic are replaced in this saved file by their bias-corrected values (meaningful only for calculating the bias-corrected gap).
If bcorrect(merge) had instead been specified, _Y_treated and _Y_synthetic would have been left as their uncorrected values, and the bias-corrected
values would have been saved as _Y_treated_bc and _Y_synthetic_bc. The replace option is specified so smokingresults.dta
can be saved even if the file already exists (it will be overwritten).

Example 4 - Calculate, display, and save the classic and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome,
and additionally plot the paths of the classic and bias-corrected gaps:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcorrect(merge) gapfigure(classic bcorrect) keep(smokingresults) replace

This example reproduces the estimation in Example 3, but as gapfigure() and its own classic and bcorrect options are specified,
it also plots the dynamic paths of the classic and the (OLS regression estimated) bias-corrected gaps against each other.
Note how, in this case, the post-treatment bias-corrected gaps are smaller than those produced by classic synthetic control estimation.

Example 5 - Calculate, display, and save the classic and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome,
and additionally plot the paths of the classic and bias-corrected gaps with the dotted vertical line now indicating the treatment period immediately preceding treatment:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcorrect(merge) gapfigure(classic bcorrect lineback) keep(smokingresults) replace

This example reproduces the estimation in Example 4, but as the gapfigure() option lineback is also specified,
the dotted vertical line which by default indicates the specified treatment period (here, 1989) has now been moved to the period immediately
preceding the specified treatment period. This produces a figure analogous to Figure 3 in Abadie, Diamond and Hainmueller (2010), but with the bias-corrected outcome path also added
(note: this is not the exact specification used in Abadie, Diamond, and Hainmueller (2010), which is why the classic outcome path differs slightly from Figure 3 in that paper).

Example 6 - Calculate, display, and save the classic and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome.
Plot the paths of the classic and bias-corrected gaps with the dotted vertical line now indicating the treatment period immediately preceding treatment.
Estimate the bias using elastic net regression:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcorrect(merge elastic) gapfigure(classic bcorrect lineback) keep(smokingresults) replace

This example reproduces the estimation in Example 5, but as the bcorrect() option elastic is also specified, the bias is estimated using elastic net regression instead of OLS.

Example 7 - Calculate, display, and save the classic RMSPE-ranked p-values from in-space placebo runs, and plot the dynamic paths of
classic gaps for the treated unit and for each of the donor pool units (placebo treated units), with the dotted vertical line indicating the period immediately preceding treatment:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) gapfig(classic placebos lineback) pval keep(smokingresults) rep

This example reproduces the estimation in Example 1, also calculating and displaying, storing, and saving the RMSPE, RMPSE rank, and the
p-values for the classic estimates (and saving the placebo estimates), and additionally plots the dynamic paths of the classic gaps for the treated unit and each donor pool unit,
with the dotted vertical line indicating the period immediately preceding treatment. This produces a figure analogous to Figure 4 in Abadie, Diamond and Hainmueller (2010)
(note: this is not the exact specification used in Abadie, Diamond, and Hainmueller (2010), which is why the classic outcome path differs slightly from Figure 4 in that paper).
Note that pvalues and keep() must be specified if gapfigure(classic placebos) is specified.

Example 8 - Calculate, display, and save the classic RMSPE-ranked p-values from in-space placebo runs, and plot the dynamic paths of
classic gaps for the treated unit and for each of the donor pool units (placebo treated units), with the dotted vertical line indicating the period immediately preceding treatment,
and with the pre-treatment mean of cigsale and retprice for each unit subtracted from those variable values in each period:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) gapfig(classic placebos lineback) pval trans(cigsale retprice, demean) keep(smokingresults) rep

This example reproduces the estimation in Example 7 but with cigsale and retprice demeaned (adjusted given the pre-treatment mean of each variable for each unit) as transform(cigsale retprice, demean) is specified.

Example 9 - Calculate, display, and save and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome, for the
treated unit and also for each donor pool unit (placebo treatments), and calculate the RMSPE-ranked p-values. Plot the dynamic paths of
bias-corrected gaps for the treated unit and for each of the donor pool units (placebo treated units), with the dotted vertical line now
indicating the period immediately preceding treatment:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcor(merge) gapfig(bcorrect placebos lineback) pvalues keep(smokingresults) replace

This example reproduces the estimation in Example 3, but as pvalues is specified, it additionally estimates, saves, and stores the values for each unit in the
donor pool (placebo runs) to calculate the RMSPE p-values. Note that while the classic gaps (the estimated marginal
treatment effects from Abadie, Diamond and Hainmueller (2010)) are all highly statistically significant in all post-treatment periods
(for each post-treatment year the RMSPE is larger than that of all the donor pool units), the bias-corrected gaps are not significant at the 10% level
before 1994, and after that the p-values are only 0.077 (the RMSPEs are ranked third among 39 total runs rather than first). As gapfigure() and its own
bcorrect, placebos, and lineback options are specified along with bcorrect(), it also plots the dynamic paths of the the (bias-corrected)
gaps for the treated unit against those for each donor pool unit against each other in a figure, with the dotted vertical line indicating the period immediately
preceding treatment. Note that all the option abbreviations are used. The resulting plot is the bias-corrected analogue of Figure 4 in Abadie, Diamond and Hainmueller (2010).

Example 10 - Calculate, display, and save and the bias-corrected gaps between the treated unit outcome and the synthetic control outcome, for the
treated unit and also for each donor pool unit (placebo treatments), and calculate the RMSPE-ranked p-values. Plot the bias-corrected gaps for the treated unit and for each of the donor pool units
(placebo treated units) with the title "Ex 10", saving the graph as "ex10.pdf" with replacement:

allsynth cigsale beer(1984(1)1988) lnincome retprice age15to24 cigsale(1988) cigsale(1980) cigsale(1975), trunit(3) trperiod(1989) bcor(merge) gapfig(bcorrect placebos, title(Ex10) save(ex10, replace)) pval keep(smokingresults) rep

This example reproduces the estimation and plot from Example 9, but with the gapfigure() option lineback dropped. Specifying the gapfigure() options title(Ex10)
save(ex10, replace) after the comma adds the title "Ex10" and saves the graph as "ex10.pdf", replacing any existing file with the same name.

Examples 11-13:

Load the example data from Wiltshire (2021) and Wiltshire (2022).
This contains panel observations of 606 U.S. counties where Walmart tried to build a Supercenter over the years 1990-2005 (see Wiltshire (2021) for details):

use allsynth_walmart

Declare the dataset as a panel:

tsset cty_fips year

See Wiltshire (2022) for discussion of the following examples without defining or calling
the macros (which is done to shorten the commands so that Stata's help file language (SMCL) will recognize them as interactive (clickable on a Windows system).

Define the first local macro of predictor variables (to allow the allsynth commands below to work interactively on a Windows system):

local depvar_preds "emps_n10 emps_n10(1990) emps_n10(1991) emps_n10(1992) emps_n10(1990(1)1994) log_emps_n10(1990(1)1994) log_pe_salary_n10(1990(1)1994)"

Define the second local macro of predictor variables:

local depvar_preds "`depvar_preds' log_emps_n44(1990(1)1994) log_pe_salary_n44(1990(1)1994) emps_shr_n44(1990(1)1994) pop_t(1990(1)1994)"

Define a new directory to store the output:

capture mkdir "allsynth_walmart"

Example 11 - Calculate the "stacked" average treatment effects of Supercenter entry on aggregate county employment in Indiana only.
Note that trunit(#) and trperiod(#) need not be defined because the stacked() option already requires variables that define these.

First preserve the data so we can restrict it to only treated counties in Indiana and all donor pool counties, to speed up the run-time:

preserve

Next, restrict the data to only the untreated counties and treated counties in Indiana:

keep if supercenter == 0 | floor(cty_fips/1000) == 18

Estimate, display, and save the classic and bias-corrected average treatment effects (gaps) of Walmart Supercenter entry on employment in treated counties in Indiana, in percentage terms of
the employment in each county's final pre-treatment year:

allsynth `depvar_preds', transform(emps_n10, normalize) bcorrect(merge) keep(allsynth_walmart/employment, replace) stacked(trunits(supercenter) trperiods(super_year), clear figure(classic bcorrect))

As stacked() is specified, this example estimates and plots the classic and bias-corrected average treatment effects of Walmart Supercenter entry on county employment in Indiana.
The supercenter variable identifies with a 1 all the counties in Indiana which got their first Walmart Supercenter over this period, and identifies with a 0 all of the donor pool
counties in the sample where Walmart tried to build a Supercenter during this period but was blocked by local efforts. The super_year variable identifies (in every year) the year
of Supercenter entry into the treated counties. Note that , clear is also specified within stacked(), as it is required (because all existing identically-named files are
erased when stacked() is specified). The estimated average effects are in percentage terms as transform(employment, normalize) was specified, which normalizes
employment in in each treated county and its donor pool counties to the final pre-treatment period for that treated county. The results are displayed, stored, and saved in event time,
as Indiana's counties were treated over several years. The classic and bias-corrected estimated average treatment effects are displayed on the graph, as the stacked() option
figure(classic bcorrect) is specified.

Example 12 - Calculate the stacked average treatment effects of Supercenter entry on aggregate county employment across the U.S. as in Wiltshire (2021), but without p-values.
Note that the run-time for this example is 35 minutes using Stata MP on a Unix server.

First restore the data to include all treated and all donor pool counties:

restore

Next, define a macro with all non-stacked() specifications of allsynth to allow a focus on stacked(), and to allow the example to work interactively on a Windows system:

local allsynth_specifications "`depvar_preds', transform(emps_n10, normalize) bcorrect(merge) keep(allsynth_walmart/employment, replace)"

And define a macro with the donorcond() and donorif() specifications of the stacked() option, to allow the example to work interactively:

local donor_restrict "donorcond(sum czone if supercenter == 1, gen cz = r(mean)) donorif(czone != cz)"

Do as in Example 11, but for all U.S. counties which received their first Supercenter over this period. Weight the estimated effects by 1990 county population, and restrict to those
event years in which all treated counties are observed. Restrict the donor pool for each treated county to those donor pool counties in different commuting zones. Set the x-axis title
to "Event year", and save the graph as "ate.pdf" in the "allsynth_walmart" directory:

allsynth `allsynth_specifications' stacked(trunits(supercenter) trperiods(super_year), clear avgweights(pop_1990) balanced `donor_restrict' figure(classic bcorrect, save(allsynth_walmart/ate, replace) xtitle(Event year)))

This example does as Example 11, but for all treated counties in the U.S. As avgweights(pop_1990) is specified, the estimated average treatment effects will be calculated by
weighting the estimated marginal treatment effects of each treated county by their 1990 populations. As balanced is specified, the displayed, saved, and plotted estimates will be
restricted to those event years in which all treated units are observed (in this case, balanced does nothing as the sample is already balanced over event years e=[-5,5]). As
donorcond(sum czone if supercenter == 1, gen cz = r(mean)) donorif(czone != cz) is specified, the donor pool for each treated unit will be restricted to only those donor pool
counties in other commuting zones. As , save(allsynth_walmart/ate, replace) is specified, the generated plot of classic and bias-corrected estimated average treatment effects will
be saved to allsynth_walmart/ate.pdf and will replace any existing file of the same name. As xtitle(Event year) is specified, the x-axis title will be changed to "Event year".

Example 13 - Do as Example 12, but estimate RMSPE-ranked p-values and generate the plot for the bias-corrected estimated ATE and 1000 sampled placebo average gaps, as in Wiltshire (2021).
Note that this example takes over 24 hours to run using Stata MP on a Unix server.

allsynth `allsynth_specifications' pvalues stacked(trunits(supercenter) trperiods(super_year), clear avgweights(pop_1990) balanced sampleavgs(1000) `donor_restrict' figure(bcorrect placebos, save(allsynth_walmart/ate, replace)))

This example does as Example 12, but also calculated the RMSPE-ranked p-values as pvalues is specified. As sampleavgs(1000) is specified, these will be based on 1000
randomly sampled placebo average gaps. The "Event year" title on the x-axis (from Example 12) is dropped, and as figure(bcorrect placebos) is specified, the generated plot will show the
bias-corrected estimated average treatment effect and the sampled placebo average gaps.

References

Abadie, A., and J. L'Hour, 2021. A Penalized Synthetic Control Estimator for Disaggregated Data. Journal of the American Statistical Association, 116(536): 1817-1834.

Abadie, A., Diamond, A., and J. Hainmueller, 2010. Synthetic Control Methods for Comparative Case Studies: Estimating the Effect of California's Tobacco Control Program.
Journal of the American Statistical Association, 105(490): 493-505.

Abadie, A., Diamond, A. and J. Hainmueller, 2015. Comparative politics and the synthetic control method. American Journal of Political Science, 59(2): 495-510.

Dube, A. and Ben Zipperer, 2015. Pooling multiple case studies using synthetic controls: An application to minimum wage policies. Institute for the Study of Labor (IZA) Discussion Papers 8944.

Ben-Michael, E., Feller, A. and J. Rothstein, 2021. The Augmented Synthetic Control Method. Journal of the American Statistical Association, 116(536): 1789-1803.

Wiltshire, J.C., 2021. Walmart Supercenters and Monopsony Power: How a Large, Low-Wage Employer Impacts Local Labor Markets. Working paper.

Wiltshire, J.C., 2022. allsynth: (Stacked) Synthetic Control Bias-Correction Utilities for Stata. Working paper.

Citation of allsynth

allsynth is user-written command made freely-available to the research community. Please cite the associated paper:

Wiltshire, J.C., 2022.
allsynth: (Stacked) Synthetic Control Bias-Correction Utilities for Stata. Working paper.
https://justinwiltshire.com/s/allsynth_Wiltshire.pdf.

Author

Justin C. Wiltshire, jcwiltshire@ucdavis.edu
University of California, Davis

Acknowledgement: In addition to directly utilizing the synth package, the code for allsynth draws unapologetically on Jens Hainmueller's code from the original synth package. This is an explicit acknowledgement of that fact.