我正在为我的综合控制设计做一个跨国安慰剂。由于我有17个捐助国,所以我开发了一个循环程序,可以帮助我节省很多时间。但是,我需要存储一些值以便以后生成如下图:
当前代码就是这个(我要在其中存储值的gaps_birth_i):
birthprep <- rep(NA,16)
i <- 3
for(i in 2:17) {
Synthetic control preparation
birthprep_i <- dataprep(foo = main_donors,
predictors = c("gdp","population","labor_women",
"labor_men","enrollment","productivity",
"fertility","marriage","divorce","life",
"gross_income","unemployment"),
dependent = "birthrate",
unit.variable = "code",
time.variable = "year",
treatment.identifier = i, # Select country i as the treated country
controls.identifier = unique(main_donors$code)[unique(main_donors$code)!=i], time.predictors.prior = c(1992:2001),
time.optimize.ssr = c(1992:2001),
unit.names.variable = "id",
time.plot = 1992:2016)
birthsynth_i <- synth(birthprep_i)
gaps_birth_i <- birthprep_i$Y1plot-(
birthprep_i$Y0plot%*%birthsynth_i$solution.w )
}
如果有人可以帮助我,我将非常感激!
谢谢。