Implements the generalized synthetic control method based on interactive fixed effect models.
gsynth(formula=NULL, data, Y, D, X = NULL, na.rm = FALSE,
index, weight = NULL, force = "unit", cl = NULL, r = 0,
lambda = NULL, nlambda = 10, CV = TRUE, criterion = "mspe",
k = 5, EM = FALSE, estimator = "ife",
se = FALSE, nboots = 200,
inference = "nonparametric", cov.ar = 1, parallel = TRUE,
cores = NULL, tol = 0.001, seed = NULL, min.T0 = 5,
alpha = 0.05, normalize = FALSE)
an object of class "formula": a symbolic description of the model to be fitted.
a data frame (must be with a dichotomous treatment but balanced is not required).
outcome.
treatment.
time-varying covariates.
a logical flag indicating whether to list-wise delete missing data. The algorithm will report an error if missing data exist.
a two-element string vector specifying the unit (group) and time indicators. Must be of length 2.
a string specifying the weighting variable(if any) to estimate
the weighted average treatment effect. Default is weight = NULL
.
a string indicating whether unit or time fixed effects will be imposed. Must be one of the following, "none", "unit", "time", or "two-way". The default is "unit".
a string indicator the cluster variable. The default value is
NULL
. If cl = NULL
, bootstrap will be blocked at unit level
(only for non-parametric bootstrap).
an integer specifying the number of factors. If CV = TRUE
,
the cross validation procedure will select the optimal number of
factors from r
to 5.
a single or sequence of positive numbers specifying the
hyper-parameter sequence for matrix completion method. If lambda
is a sequence and CV = 1
, cross-validation will be performed.
an integer specifying the length of hyper-parameter sequence
for matrix completion method. Default is nlambda = 10
.
a logical flag indicating whether cross-validation will be
performed to select the optimal number of factors or hyper-parameter
in matrix completion algorithm. If r
is not specified, the procedure
will search through r = 0
to 5
.
a string specifying the criteria used for determining the number
of factors. Choose from c("mspe", "pc")
. "mspe" stands for the mean squared
prediction error obtained through the loocv procedure, and "pc" stands for a kind
of information criterion. If criterion = "pc"
, the number of factors that
minimize "pc" will be selected. Default is criterion = "mspe"
.
a positive integer specifying cross-validation times for matrix
completion algorithm. Default is k = 5
.
a logical flag indicating whether an Expectation Maximization algorithm will be used (Gobillon and Magnac 2016).
a string that controls the estimation method, either "ife" (interactive fixed effects) or "mc" (the matrix completion method).
a logical flag indicating whether uncertainty estimates will be produced.
an integer specifying the number of bootstrap
runs. Ignored if se = FALSE
.
a string specifying which type of inferential method
will be used, either "parametric" or "nonparametric". "parametric" is
recommended when the number of treated units is small. parametric bootstrap
is not valid for matrix completion method. Ignored if estimator = "mc"
.
an integer specifying order of the auto regression process that the residuals follow. Used for parametric bootstrap procedure when data is in the form of unbalanced panel. The default value is 1.
a logical flag indicating whether parallel computing
will be used in bootstrapping and/or cross-validation. Ignored if
se = FALSE
.
an integer indicating the number of cores to be used in parallel computing. If not specified, the algorithm will use the maximum number of logical cores of your computer (warning: this could prevent you from multi-tasking on your computer).
a positive number indicating the tolerance level.
an integer that sets the seed in random number
generation. Ignored if se = FALSE
and r
is specified.
an integer specifying the minimum value of pre-treatment
periods. Treated units with pre-treatment periods less than that will
be removed automatically. This item is important for unbalanced panels.
If users want to perform cross validation procedure to select the optimal
number of factors from (r.min, r.max)
, they should set min.T0
larger than (r.max+1)
if no individual fixed effects or (r.max+2)
otherwise. If there are too few pre-treatment periods among all treated units,
a smaller value of r.max
is recommended.
a positive number in the range of 0 and 1 specifying significant
levels for uncertainty estimates. The default value is alpha = 0.05
.
a logic flag indicating whether to scale outcome and
covariates. Useful for accelerating computing speed when magnitude of
data is large. The default is normalize=FALSE
.
a matrix storing data of the outcome variable.
name of the outcome variable.
name of the treatment variable.
name of the time-varying control variables.
name of the unit and time indicators.
a vector of unit IDs.
a vector of time periods.
a matrix storing status of each unit at each time point.
0
for missing, 1
for control group units, 2
for treat group
units at pre-treatment period, 3
for treat group units at post-treatment
period, and 4
for removed treated group units. Useful for unbalanced panel data.
a vector of IDs for the treatment units.
a vector of IDs for the control units.
a vector of IDs for units that are removed.
a matrix of treatment indicator for the treated unit outcome.
a matrix of observation indicator for the treated unit outcome.
data of the treated unit outcome.
predicted counterfactuals for the treated units.
data of the control unit outcome.
difference between actual outcome and predicted Y(0).
average values of Y.tr, Y.ct, and Y.co over time.
average treatment effect on the treated over time (it is averaged based on the timing of the treatment if it is different for each unit).
average treatment effect on the treated.
user specified force
option.
TRUE if the timing of the treatment is the same.
the number of time periods.
the total number of units.
the number of time-varying observables.
the number of treated units.
the number of control units.
a vector that stores the timing of the treatment for balanced panel data.
a vector indicating treatment status for each unit.
a matrix indicating the pre-treatment/non-treatment status.
a matrix indicating the post-treatment status.
the number of factors included in the model -- either supplied by users or automatically chosen via cross-validation.
the optimal hyper-parameter in matrix completion method chosen via cross-validation.
residuals of the control group units.
coefficients of time-varying observables from the interactive fixed effect model.
the mean squared error of interactive fixed effect model.
the information criterion.
the proposed criterion for determining factor numbers.
result of the interactive fixed effect model based on
the control group data. An interFE
object.
difference between actual outcome and predicted Y(0); rearranged based on the timing of the treatment.
data of the treated unit outcome, rearranged based on the timing of the treatment.
data of the predicted Y(0), rearranged based on the timing of the treatment.
mean squared prediction error of the cross-validated model.
result of the cross-validation procedure.
the number of iterations in the estimation of the interactive fixed effect model.
estimated time-varying factors.
estimated loadings for the control group.
estimated loadings for the treatment group.
estimated weights of each of the control group unit for each of the treatment group unit.
estimated ground mean.
estimated time fixed effects.
estimated unit fixed effects for the treated units.
estimated unit fixed effects for the control units.
a logic value indicating if multicollinearity exists.
a string indicating bootstrap procedure.
inference for att
.
inference for att.avg
.
inference for beta
.
inference for att
of each treated unit.
bootstrap results for att.avg
.
bootstrap results for att
.
bootstrap results for beta
.
gsynth
implements the generalized synthetic control method. It
imputes counterfactuals for each treated unit using control group
information based on a linear interactive fixed effects model that
incorporates unit-specific intercepts interacted with time-varying
coefficients. It generalizes the synthetic control method to the case
of multiple treated units and variable treatment periods, and improves
efficiency and interpretability. It allows the treatment to be
correlated with unobserved unit and time heterogeneities under
reasonable modeling assumptions. With a built-in cross-validation
procedure, it avoids specification searches and thus is easy to
implement. Data must be with a dichotomous treatment.
Laurent Gobillon and Thierry Magnac, 2016. "Regional Policy Evaluation: Interactive Fixed Effects and Synthetic Controls." The Review of Economics and Statistics, July 2016, Vol. 98, No. 3, pp. 535--551.
Yiqing Xu. 2017. "Generalized Synthetic Control Method: Causal Inference with Interactive Fixed Effects Models." Political Analysis, Vol. 25, Iss. 1, January 2017, pp. 57-76.
Athey S, Bayati M, Doudchenko N, et al. Matrix completion methods for causal panel data models[J]. arXiv preprint arXiv:1710.10251, 2017.
For more details, see https://yiqingxu.org/packages/gsynth/gsynth_examples.html.
For more details about the matrix completion method, see https://github.com/susanathey/MCPanel.
# NOT RUN {
library(gsynth)
data(gsynth)
out <- gsynth(Y ~ D + X1 + X2, data = simdata, parallel = FALSE,
index = c("id","time"), force = "two-way",
CV = TRUE, r = c(0, 5), se = FALSE)
print(out)
# }
Run the code above in your browser using DataLab