Closed ricarnet1 closed 1 year ago
Looks like the issue is probably with your inputs. tidysynth uses quasiquotation (standard tidyverse
rlang
stuff) so you don't need/shouldn't index on the variable as you're doing.
Try:
final %>%
synthetic_control(
outcome =`Violent crime`,
unit = Area, # unit index in the panel data
time = Year, # time index in the panel data
i_unit = "Colorado", # unit where the intervention occurred
i_time = 2013, # time period when the intervention occurred
generate_placebos=TRUE # generate placebo synthetic controls (for inference)
) %>%
# and so on ...
Also, FWIW, you should opt for no spaces in your variable naming conventions. It'll make your life way easier. (e.g. Violent crime
should be Violent_crime
).
I hope that helps!
require(tidysynth) data("final") final %>% dplyr::glimpse() is.data.frame(final)
violent_crimes_out <-
final%>%
initial the synthetic control object
synthetic_control(outcome = final$
Violent crime
, # outcome unit = final$Area, # unit index in the panel data time = final$Year, # time index in the panel data i_unit = "Colorado", # unit where the intervention occurred i_time = 2013, # time period when the intervention occurred generate_placebos=TRUE # generate placebo synthetic controls (for inference) ) %>%Generate the aggregate predictors used to fit the weights
average log income, retail price of cigarettes, and proportion of the
population between 15 and 24 years of age from 1980 - 1988
generate_predictor(time_window = 2013:2019, tx_desemprego = mean(
Taxa de desemprego
, na.rm = T), renda_percapita = mean(Renda per Capita
, na.rm = T), tx_conservadorismo = mean(Conservadorismo, na.rm = T)) %>%Generate the fitted weights for the synthetic control
generate_weights(optimization_window = 2007:2019, # time to use in the optimization task margin_ipop = .02,sigf_ipop = 7,bound_ipop = 6 # optimizer options ) %>%
Generate the synthetic control
generate_control()
Error in
dplyr::mutate()
: ℹ In argument:placebo = ifelse(final$Area != i_unit, 1, 0)
. Caused by error: !placebo
must be size 7 or 1, not 91. Runrlang::last_error()
to see where the error occurred.This error is happening and i've runned out of ideas on how to fix it. Can someone help me, i don't know what else to do.