我使用该Synth软件包来展示吉布提与没有国际干预的吉布提综合模型之间的发展差异。
尽管有几个类似的问题并尝试提供答案,但我仍然在与错误作斗争:
\nunit.variable not found as numeric variable in foo\nRun Code Online (Sandbox Code Playgroud)\n我尝试了几种不同的dataprep()策略,但仍然无法运行代码。
unit.variable not found as numeric variable in foo\nRun Code Online (Sandbox Code Playgroud)\n我正在尝试生成一个综合控制模型,并且一直在使用此代码的不同迭代。尽管我已成功将类更改为数字,但我仍然遇到相同的错误。\n这是我的数据的头部 reprex
head(ddSMI)\n# A tibble: 6 x 8\n Year Cno Country PedYrs LifeYrs \n <dbl> <dbl> <chr> <chr> <chr> \n1 2000 1 Algeria 6.31 69.5999999999999\xe2\x80\xa6\n2 2001 1 Algeria 6.23 69.2 \n3 2002 1 Algeria 6.28 69.5 \n4 2003 1 Algeria 6.32 71.0999999999999\xe2\x80\xa6\n5 2004 1 Algeria 6.36 71.4000000000000\xe2\x80\xa6\n6 2005 1 Algeria 6.39 71.7 \n# \xe2\x80\xa6 with 3 more variables: SchoolMean <chr>,\n# Health Index Total <chr>,\n# Income Index Total <chr>\nRun Code Online (Sandbox Code Playgroud)\n请参阅下面的代码。
\ndataprep.out <- dataprep(foo = ddSMI,\n predictors = c("LifeYrs", "PedYrs", "Health.Index.Total", "Income.Index.Total", "SchoolMean"),\n predictors.op = "mean", # the operator\n time.predictors.prior = 2007:2008, #the entire time frame from the #beginning to the end\n special.predictors = list(\n list("HDI Rank", 2000:2020, "mean"),\n list("LifeYrs", seq(2007,2008,2), "mean"),\n list("PedYrs", seq(2007,2008,2), "mean"),\n list("Health Index Total", seq(2007, 2008, 2), "mean"),\n list("Income Index Total", seq(2007,2008, 2), "mean"),\n list("School Mean", seq(2007, 2008, 2), "mean")),\n dependent = "HDI Rank", #dv\n unit.variable = "Cno", #identifying unit numbers\n unit.names.variable = "Country", #identifying unit names\n time.variable = "Year", #time period\n treatment.identifier = 5,#the treated case\n controls.identifier = c(2:4, 6:15),#the control cases; all others #except number 5\n time.optimize.ssr = 2007:2008,#the time-period over which to optimize\n time.plot = 2000:2020)#the entire time period before/after the treatment\nRun Code Online (Sandbox Code Playgroud)\n这是关于 Synth 包的有用资源,我用它来帮助指导/排除故障:“Synth:比较案例研究中用于综合控制方法的 R 包”
\n我的数据采用相同的格式,但...无法让它运行!如果有人能破解这个,将不胜感激!
\n小智 6
我遇到了类似的错误,尽管它与单位变量是数字无关(它基本上是代码中的第一个错误消息:请参阅此处)。
确保您的对象是一个数据框,并且只是一个数据框。我建议使用包中提供的“synth.data”示例检查数据结构。鉴于您的代码表明您的对象也是一个 tibble (tbl_df),这可能是错误的原因。
is.data.frame(synth.data)
[1] TRUE
class(synth.data)
[1] "data.frame"
Run Code Online (Sandbox Code Playgroud)
is.data.frame(DATA)
[1] TRUE
class(DATA)
[1] "tbl_df" "tbl" "data.frame"
DATA <- as.data.frame(DATA)
class(DATA)
[1] "data.frame"
Run Code Online (Sandbox Code Playgroud)