我正在尝试从Synth包中运行dataprep函数,但它会给我以下错误消息:
“您的面板,如unit.variable和time.variable所述,是不平衡的。请平衡并重新运行。”
我已经检查过,每个单元(共27个)具有相同的周期数(48个)。没有缺失的值。
df是这个:
> glimpse(base_sg)
Observations: 1,296
Variables: 13
$ uf <chr> "Acre", "Acre", "Acre", "Ac...
$ data <dttm> 2015-01-01, 2015-02-01, 20...
$ homicidio <dbl> 13, 10, 16, 22, 15, 14, 14,...
$ perc_14_17 <dbl> 12.4, 12.4, 12.4, 12.3, 12....
$ perc_18_24 <dbl> 17.4, 17.4, 17.4, 16.9, 16....
$ perc_ocup_14_24 <dbl> 0.3314286, 0.3314286, 0.331...
$ negra_parda <dbl> 84.4, 84.4, 84.4, 83.6, 83....
$ rend_medio <dbl> 1940, 1940, 1940, 1847, 184...
$ fundamental <dbl> 10.9, 10.9, 10.9, 10.2, 10....
$ medio <dbl> 18.0, 18.0, 18.0, 17.6, 17....
$ popul <dbl> 824612.6, 825695.1, 826777....
$ homic_100k <dbl> 18.91798, 14.53321, 23.2227...
$ cod_uf <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
函数的代码是这样的:
prep<- dataprep(foo = base_sg,
predictors = c("perc_ocup_14_24","negra_parda","rend_medio","perc_14_17","perc_18_24","fundamental", "medio") ,
predictors.op = "mean" ,
time.predictors.prior = 2015-01-01:2018-01-01 ,
dependent = "homic_100k" ,
unit.variable = "cod_uf" ,
unit.names.variable = "uf" ,
time.variable = "data" ,
treatment.identifier = 19 ,
controls.identifier = c(1:18,20:27) ,
time.optimize.ssr = c(2015-01-01:2018-02-01) ,
time.plot = 2015-01-01:2018-12-01)