微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R中的综合控制方法:“ dataprep.out $ X1 NULL”

如何解决R中的综合控制方法:“ dataprep.out $ X1 NULL”

我目前正在研究2017年《可再生能源法》(Erneuerbare-Energien-Gesetz)对德国采用综合控制方法的可再生能源生产的影响。

library(Synth)
data("EuEnergy")
dim(EuEnergy) #840*14
EuEnergy[28:32,1:6]

dataprep.out <-
  EuEnergy <- as.data.frame(EuEnergy)
  dataprep(foo = EuEnergy,predictors = c("coal","oil","gas","nuc"),predictors.op = c("mean"),# the operator
           dependent = c("renew"),#dv
           unit.variable = c("countrynumber"),#identifying unit numbers
           time.variable = c("year"),#time-periods
           special.predictors = list(
             list("renew",2000:2016,c("mean")),list("feconsum",seq(2001,2016,2),list("netimp",list("capacity",list("fenpercap",list("coemiss",list("gdp",c("mean"))
                  ),treatment.identifier = 5,#the treated case/ Germany
           controls.identifier = c(1:4,6:28),#the control cases; all EU countries except Germany
           time.predictors.prior = c(2001:2016),#the entire time frame from start to end
           time.optimize.ssr = c(2000:2016),#the time-period over which to optimize
           unit.names.variable = c("countryname"),#identifying unit names
           time.plot = c(1990:2018) #the entire time period before/after the treatment
                  )
  dataprep.out$X1

运行代码时,我得到 dataprep.out $ X1 NULL ,它不是用于进一步计算的X1矩阵。

如果您有任何提示要做什么,请帮助我。

解决方法

在上面的代码中,您将dataprep.out分配为data.frame(EuEnergy),然后对dataprep()的调用仅打印到控制台(即未分配任何内容)。没有数据,我无法测试它,但我认为这会起作用:

library(Synth)
data("EuEnergy")
dim(EuEnergy) #840*14
EuEnergy[28:32,1:6]

EuEnergy <- as.data.frame(EuEnergy)
dataprep.out <- dataprep(foo = EuEnergy,predictors = c("coal","oil","gas","nuc"),predictors.op = c("mean"),# the operator
         dependent = c("renew"),#dv
         unit.variable = c("countrynumber"),#identifying unit numbers
         time.variable = c("year"),#time-periods
         special.predictors = list(
           list("renew",2000:2016,c("mean")),list("feconsum",seq(2001,2016,2),list("netimp",list("capacity",list("fenpercap",list("coemiss",list("gdp",c("mean"))
         ),treatment.identifier = 5,#the treated case/ Germany
         controls.identifier = c(1:4,6:28),#the control cases; all EU countries except Germany
         time.predictors.prior = c(2001:2016),#the entire time frame from start to end
         time.optimize.ssr = c(2000:2016),#the time-period over which to optimize
         unit.names.variable = c("countryname"),#identifying unit names
         time.plot = c(1990:2018) #the entire time period before/after the treatment
)
dataprep.out$X1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。