# \donttest{
library(data.table)
# 1. Create dummy data with ALL required predictors
# The function explicitly selects: EconCycle, PopDensity, Epidemics, Climate, War, t_norm
DT <- data.table(
year = 2000:2029,
I = rpois(30, lambda = 10),
C = rpois(30, lambda = 8),
# Predictors required by run_synth_bsts internal selection
EconCycle = rnorm(30),
PopDensity = rnorm(30),
Epidemics = rnorm(30),
Climate = rnorm(30),
War = rnorm(30),
t_norm = seq(-1, 1, length.out = 30)
)
# 2. Define global paths using tempdir() (Fixes CRAN policy)
# run_synth_bsts writes output to 'dir_csv'
tmp_dir <- tempdir()
dir_csv <- file.path(tmp_dir, "csv")
if (!dir.exists(dir_csv)) dir.create(dir_csv, recursive = TRUE)
# 3. Run the function
# We use "War" as the control variable to define the treatment period
res_I <- run_synth_bsts(DT, outcome = "I", control_var = "War", seed = 123)
# Inspect results if successful (might return NULL if fit fails or not enough data)
if (!is.null(res_I)) {
print(res_I$summary)
}
# }
Run the code above in your browser using DataLab