## Example with toy data from Synth
library(Synth)
# Load the simulated data
data(synth.data)
# Execute dataprep to produce the necessary matrices for synth
dataprep.out<-
dataprep(
foo = synth.data,
predictors = c("X1"),
predictors.op = "mean",
dependent = "Y",
unit.variable = "unit.num",
time.variable = "year",
special.predictors = list(
list("Y", 1991, "mean")
),
treatment.identifier = 7,
controls.identifier = c(29, 2, 17),
time.predictors.prior = c(1984:1989),
time.optimize.ssr = c(1984:1990),
unit.names.variable = "name",
time.plot = 1984:1996
)
# run the synth command to create the synthetic control
synth.out <- synth(dataprep.out, Sigf.ipop=1)
tdf <- generate.placebos(dataprep.out,synth.out, Sigf.ipop = 1)
## Plot the gaps in outcome values over time of each unit --
## treated and placebos -- to their synthetic controls
p <- plot_placebos(tdf,discard.extreme=TRUE, mspe.limit=10, xlab='Year')
p
## Example with toy data from Synth
library(Synth)
# Load the simulated data
data(synth.data)
# Execute dataprep to produce the necessary matrices for synth
dataprep.out<-
dataprep(
foo = synth.data,
predictors = c("X1"),
predictors.op = "mean",
dependent = "Y",
unit.variable = "unit.num",
time.variable = "year",
special.predictors = list(
list("Y", 1991, "mean")
),
treatment.identifier = 7,
controls.identifier = c(29, 2, 13, 17),
time.predictors.prior = c(1984:1989),
time.optimize.ssr = c(1984:1990),
unit.names.variable = "name",
time.plot = 1984:1996
)
# run the synth command to create the synthetic control
synth.out <- synth(dataprep.out, Sigf.ipop=2)
## run the generate.placebos command to reassign treatment status
## to each unit listed as control, one at a time, and generate their
## synthetic versions. Sigf.ipop = 2 for faster computing time.
## Increase to the default of 5 for better estimates.
tdf <- generate.placebos(dataprep.out,synth.out, Sigf.ipop = 2, strategy='multicore')
## Plot the gaps in outcome values over time of each unit --
## treated and placebos -- to their synthetic controls
p <- plot_placebos(tdf,discard.extreme=TRUE, mspe.limit=10, xlab='Year')
p
Run the code above in your browser using DataLab