I am using the Synth() package (see ftp://cran.r-project.org/pub/R/web/packages/Synth/Synth.pdf) in R.
This is an example of my dataset:
structure(list(city = c(110001L, 110001L, 110001L, 110001L,
110001L, 110001L, 110001L, 110001L, 110001L, 110001L), month = c(1L,
6L, 7L, 9L, 11L, 1L, 2L, 6L, 7L, 8L), year = c(2005L, 2005L, 2005L,
2005L, 2005L, 2006L, 2006L, 2006L, 2006L, 2006L), pop_total = c(25915L,
25915L, 25915L, 25915L, 25915L, 25706L, 25706L, 25706L, 25706L,
25706L), pop_man = c(13513L, 13513L, 13513L, 13513L, 13513L,
13394L, 13394L, 13394L, 13394L, 13394L), pop_young_total = c(7312L,
7312L, 7312L, 7312L, 7312L, 7263L, 7263L, 7263L, 7263L, 7263L
), pop_young_man = c(3700L, 3700L, 3700L, 3700L, 3700L, 3684L,
3684L, 3684L, 3684L, 3684L), tax = c(12934L,
12934L, 12934L, 12934L, 12934L, 13669L, 13669L, 13669L, 13669L,
13669L), pib= c(167127L, 167127L, 167127L, 167127L,
167127L, 168805L, 168805L, 168805L, 168805L, 168805L), pib_per_capta = c(5837.69,
5837.69, 5837.69, 5837.69, 5837.69, 5819.86, 5819.86, 5819.86,
5819.86, 5819.86), ativ = c("", "", "", "", "",
"", "", "", "", ""), students = c(320, 1350,
250, 350, 234234, 242, 43543,
43534, 34534, 2423), index_gini = c(0.5893,
0.5893, 0.5893, 0.5893, 0.5893, 0.5893, 0.5893, 0.5893, 0.5893,
0.5893), ocupados.escolar.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), ocupados.escolar.2 = c(95L, 95L, 95L, 95L, 95L, 144L,
144L, 144L, 144L, 144L), ocupados.escolar.3 = c(649L, 649L, 649L,
649L, 649L, 748L, 748L, 748L, 748L, 748L), ocupados.escolar.4 = c(361L,
361L, 361L, 361L, 361L, 402L, 402L, 402L, 402L, 402L), ocupados.escolar.5 = c(604L,
604L, 604L, 604L, 604L, 649L, 649L, 649L, 649L, 649L), ocupados.negro = c(NA,
NA, NA, NA, NA, 447L, 447L, 447L, 447L, 447L), workers = c(1709L,
1709L, 1709L, 1709L, 1709L, 1943L, 1943L, 1943L, 1943L, 1943L
), deaths = c(2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L), treatment = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),date = structure(c(12784,
12935, 12965, 13027, 13088, 13149, 13180, 13300, 13330, 13361
), class = "Date")), name_city = c("Alta Floresta D'Oeste",
"Alta Floresta D'Oeste", "Alta Floresta D'Oeste", "Alta Floresta D'Oeste",
"Alta Floresta D'Oeste", "Alta Floresta D'Oeste", "Alta Floresta D'Oeste",
"Alta Floresta D'Oeste", "Alta Floresta D'Oeste", "Alta Floresta D'Oeste"
)), class = c("data.table", "data.frame"), row.names = c(NA,
-10L), .internal.selfref = <pointer: 0x5634f2620520>)
In dataprep()
I need to put treatment.identifier
and time.variable
.
But how can I use Month and Year in my time.variable
, since my treatment time was from 08/2019 to 12/2019?
And how can I use more than one treatment identifier? Because I use 5 cities (520870,150080,320130,261070,412550)
What I have been trying:
dataprep.out <-
dataprep(foo = base_efetiva,
predictors = c( "pop_total", "pop_man",
"pop_young_total", "pop_young_man",
"tax",
"pib", "pib_per_capta",
"ativ", "students",
"index_gini",
"ocupados.escolar.1", "ocupados.escolar.2",
"ocupados.escolar.3", "ocupados.escolar.4" ,
"ocupados.escolar.5" ,
"ocupados.negro", "workers"
),
predictors.op = "mean" ,
time.predictors.prior = 2019,
# special.predictors = list(
# list("gdpcap" , 1960:1969 , "mean"),
# list("sec.agriculture" , seq(1961,1969,2), "mean"),
# list("sec.energy" , seq(1961,1969,2), "mean"),
# list("sec.industry" , seq(1961,1969,2), "mean"),
# list("sec.construction" , seq(1961,1969,2), "mean"),
# list("sec.services.venta" , seq(1961,1969,2), "mean"),
# list("sec.services.nonventa" ,seq(1961,1969,2), "mean"),
# list("popdens", 1969, "mean")
# ),
dependent = "death",
unit.variable = "city",
unit.names.variable = "name_city",
time.variable = "date",
treatment.identifier = c(520870,150080,320130,261070,412550), #Goiânia (GO), Ananindeua (PA), Cariacica (ES), Paulista (PE) e São José dos Pinhais (PR) (coloquei o código porque existem duas cidades chamadas Paulista)
controls.identifier != c(520870,150080,320130,261070,412550),
c = c(as.Date("2019-08-01"):as.Date("2019-12-01"))
time.plot = 2005:2019
)
And R returns:
Error in dataprep(foo = base_efetiva, predictors = c("pop_total", "pop_man", : please specify a single treated unit