*! Help file for scset.ado version 1.2 4Jun2024

Title

scset -- "Rotates" a Stata dataset from "horizontal"to "vertical" for DIY synthetic control analysis

Syntax

scset
outcome_variable
[predictor_variables]
[using filename]
[if] [in]
,
treated(string)
[
optional_options
]

Options

Required -option-
treated(unitname) The unit that is treated or has received the intervention.

Optional -options-
using(filename) Name and location of input data file,
if it is not in memory. Must have been previously tsset with panelvar
identifying the treated and donor units.

unit(varname) The name of the panelvar variable as previously set
in the tsset data. Must be an integer-valued variable with a value label.
Identifies the treatment and donor units.
This option can be used to confirm the existence in the data of the correct -unit- variable.

time(varname) The name of the timevar variable as previously set
in the tsset data. Must be an integer variable.

rank Supplement the rotated data with the variable rank
as an aid to analyzing the degree of support for the treated unit
among the donor units. Requires the community contributed package egenmore.

std Standardize the outcome and predictor variables before restructuring the data.

float Recast type -double- analytical variables
to type -float-. Reduces the size of the data file risking a possible loss
of precision. Use with caution.

double Recast type -float- analytical variables
to type -double-. Increases the size of the data file with the possible
advantage of improved precision.

savewide(filename, sub_opts) Save the intermediate reshaped
wide file with this name. Subopts include: replace, orphans.
See save.

saving(filename, sub_opts) Save the "vertical" or "rotated" data
file that has been restructured for synthetic control style regressions.
Subopts include: replace, orphans.
See save.

verbose Display intermediate results.

outcome_variable is required. The predictor_variables are optional.
Factor variables and time-series variables
are not currently supported.

Description

scset reshapes and then stacks the input data to a structure
which is amenable to Do-It-Yourself (DIY) Synthetic Control methods.

Data in memory must have Stata's long structure defined by both a panel variable and a time variable,
which have been declared by xtset or tsset. As usual the timevar variable must be an integer. Let T be the number of time periods.
The panelvar variable in the input data defines the units of analysis, including both the treatment unit and the donor units.
Let M+1 be the number of units of analysis, with one treatment unit and M donor units.
The analysis variables include 1 outcome variable and K independent covariates.
Thus the input data contains (M+1) x T rows, each of which contains the values of the K+1 analysis variables.

The SC structure created by scset will have M+3 Stata variables or columns, of which M represent the donor units,
one the treatment unit, one the time variable and the M+3rd is a newly created variable named "analvars".
The new variable "analvars" is a categorical variable with value labels defined by the names of the K+1 analytical input variables.
The created SC dataset is tsset with the same timevar variable defining the input data and "analvars" as its new panel variable.
The new data set has T x (K+1) rows (i.e. Stata observations) and M+3 columns (i.e. Stata variables).

scset is not useful for running the community contributed synthetic control
estimation packages of which I am aware.
Like scset, the synthetic control estimation packages
//fmwww.bc.edu/repec/bocode/s")"':synth,
//raw.githubusercontent.com/daniel-pailanir/sdid/master")"':sdid and
//fmwww.bc.edu/repec/bocode/s")"':scul
start with a dataset that has been tsset to conform to Stata's long
structure (as defined by reshape). After internally rotating the data,
they then estimate the donor and predictor weights and construct the synthetic control.

Since the synthetic control process consists of discrete steps,
some may find useful a set of routines, which can be executed sequentially,
with one or more for each step, which can together compute a synthetic control.
The first step in synthetic control is to "rotate" or restructure the data
from Stata's "horizontal" arrangement to SC's "vertical" arrangement.
scset performs this function. The companion program wtsreg
uses transparent, if inefficient, Stata commands to estimate
the regularized regressions which SC practitioneers recommend for constructing
a synthetic control.

Remarks

In Stata's conventional data structure, columns contain variables
and rows contain observations. Setting the data for time-series analysis
with tsset defines one of the variables as the "time" variable
and one as the "panel" variable. The panel variable identifies
the cross section units. A single column or Stata "variable" thus contains
the values of a single analytical variable (e.g. GDP) across both time (e.g. years)
and space (e.g. countries). By default, Stata's regression and other
esimation commands assume that rows of the data (that is,
specific timevar_x_panelvar observations) are statistically independent.
This assumption conforms to the i.i.d. disturbances
assumption underlying ordinary-least-squares regression analysis.
Of course, individual Stata estimation commands relax this assumption
by allowing more general variance-covariance structures for the disturbances
within and/or across equations.

In contrast to this "horizontal" approach to data analysis, Synthetic Control
adopts a "vertical" approach. (This terminology is used in Athey et al. (2018,2022).)
In the vertical approach to analysis, the roles of the panel variable and
the analytical variables are switched. In {cmd:scset| data, instead of representing distinct
analytical variables (e.g. GDP, inflation, labor, capital, etc.),
Stata columns/variables represent distinct values of the cross-section
or panel variable (e.g. France, Philippines, Mexico, ...). Stacked within
each Stata column variable are the distinct analytical variables and time units.
Thus a row of the SC compatible Stata matrix consists of values of all different
levels of the the panel variable (e.g. all the countries) for a single
specific time-period_x_analytical variable pair. By default, disturbances
are assumed i.i.d. across the rows of the scset data structure (that is,
across time-period_x_analytical variable pairs).

The command scset takes as input a standard Stata time-series data structure
that has been tsset and iteratively applies Stata's reshape and stack
commands to produce a restructured (or "rotated") data set for "vertical" analysis.
This restructuring is useful for experimenting with do-it-yourself
approaches to synthetic control as demonstrated in the examples.

Examples

UNDER CONSTRUCTION

Returned results

scset returns macros that charactrize both the original and the scset data. In addition,
scset returns several macros that the user might find convenient as prototypes or templates for programming subsequent
estimates of the synthetic control coefficients. Returned local macros synreg and syninvlgt
contain fragments of the nl command syntax for estimating a linear regression with unconstrained parameters
and a linear regression with parameters constrained to be within the open unit interval. The macro syninvto1
constrains the parameters within the open unit interval and also constrains them to sum to 1.0.

The returned macros testreg and testinvlgt are potentially useful to test the hypothesis that the
sum of parameters is equal to 1.0 using lincom or nlcom respectively. The macro testreg
can also be a shortcut to coding the sum-to-one constraint for e.g. cnsreg.

The following list of returned results shows their contents after scset has
processed the data on West Germany's reunification originally analyzed by Abadie et al. (2015).

scalars:
r(Ndonors) = 16
r(Nanalvars) = 2

macros:
r(unitlist) : "West_Germany Australia Austria Belgium Denmark France Greece Italy Japan Netherlands New_Z.."
r(treated) : "West_Germany"
r(donorlist) : "Australia Austria Belgium Denmark France Greece Italy Japan Netherlands New_Zealand Norway.."
r(outcome) : "gdp"
r(indepvars) : "trade"
r(synreg) : "{coef_Australia}*Australia + {coef_Austria}*Austria + {coef_Belgium}*Belgium + {coef.."
r(syninvlgt) : "invlogit({coef_Australia})*Australia + invlogit({coef_Austria})*Austria + invlogit({co.."
r(syninvto1) : "invlogit({coef_Australia})*Australia + invlogit({coef_Austria})*Austria + invlogit({co.."
r(testreg) : "Australia + Austria + Belgium + Denmark + France + Greece + Italy + Japan +.."
r(testinvlgt) : "invlogit(_b[coef_Australia:_cons]) + invlogit(_b[coef_Austria:_cons]) + invlogit(_b[co.."

matrices:
r(equalstartvalues) : 1 x 16

References

Author

Mead Over, Senior Fellow, Center for Global Development

Email: MOver@CGDev.Org if you observe any problems.