Synth
如果没有国际干预,我正在使用该软件包来展示吉布提与吉布提综合模型之间的发展差异。
尽管提供的答案有几个类似的问题和尝试,但我仍然在努力解决这个错误:
unit.variable not found as numeric variable in foo
我尝试了几种不同的dataprep()
策略,但仍然无法运行代码。
ddSMI <- as.data.frame(ddSMI) %>%
mutate(LifeYrs = as.numeric(LifeYrs),
PedYrs = as.numeric(PedYrs),
Health.Index.Total = as.numeric(Health.Index.Total),
Income.Index.Total = as.numeric(Income.Index.Total),
SchoolMean = as.numeric(SchoolMean),
Cno = as.numeric(Cno))
我正在尝试生成一个合成控制模型,并且一直在使用此代码的不同迭代。虽然我已经成功地将类更改为数字,但我仍然得到同样的错误。这是我的数据的负责人 reprex
head(ddSMI)
# A tibble: 6 x 8
Year Cno Country PedYrs LifeYrs
<dbl> <dbl> <chr> <chr> <chr>
1 2000 1 Algeria 6.31 69.5999999999999…
2 2001 1 Algeria 6.23 69.2
3 2002 1 Algeria 6.28 69.5
4 2003 1 Algeria 6.32 71.0999999999999…
5 2004 1 Algeria 6.36 71.4000000000000…
6 2005 1 Algeria 6.39 71.7
# … with 3 more variables: SchoolMean <chr>,
# Health Index Total <chr>,
# Income Index Total <chr>
请看下面的代码。
dataprep.out <- dataprep(foo = ddSMI,
predictors = c("LifeYrs", "PedYrs", "Health.Index.Total", "Income.Index.Total", "SchoolMean"),
predictors.op = "mean", # the operator
time.predictors.prior = 2007:2008, #the entire time frame from the #beginning to the end
special.predictors = list(
list("HDI Rank", 2000:2020, "mean"),
list("LifeYrs", seq(2007,2008,2), "mean"),
list("PedYrs", seq(2007,2008,2), "mean"),
list("Health Index Total", seq(2007, 2008, 2), "mean"),
list("Income Index Total", seq(2007,2008, 2), "mean"),
list("School Mean", seq(2007, 2008, 2), "mean")),
dependent = "HDI Rank", #dv
unit.variable = "Cno", #identifying unit numbers
unit.names.variable = "Country", #identifying unit names
time.variable = "Year", #time period
treatment.identifier = 5,#the treated case
controls.identifier = c(2:4, 6:15),#the control cases; all others #except number 5
time.optimize.ssr = 2007:2008,#the time-period over which to optimize
time.plot = 2000:2020)#the entire time period before/after the treatment
这是我用来帮助指导/排除故障的 Synth 包的有用资源:“Synth:比较案例研究中用于合成控制方法的 R 包”
我的数据格式相同,但...无法运行!如果有人能破解这个,将不胜感激!