'Can't replicate R tidysynth results
This is an odd sort of question, but I'm using the exact data and code from this github here: https://github.com/edunford/tidysynth
However, when I get to the code plotting trends, it turns out I'm plotting the trends for a synthetic vs. real Alabama, rather than the synthetic vs. real California, which is what it supposed to be happening -- and what the hithub results show!!
I am running this code in Rstudio on a laptop. How can the results be different? Why would it be showing a synthetic AL rather than synthetic CA?
All my code is below. Can somebody sanity-check me here -- do you get a trend for CA or for AL? I feel like I'm going crazy.
#install.packages("devtools")
#devtools::install_github("edunford/tidysynth")
require(tidysynth)
library(dplyr)
data("smoking")
smoking %>% dplyr::glimpse()
unique(smoking$state)
smoking_out <-
smoking %>%
synthetic_control(outcome = cigsale,
unit = state,
time = year,
i_unit = "California",
i_time = 1988,
generate_placebos=TRUE
) %>%
generate_predictor(time_window = 1980:1988,
ln_income = mean(lnincome, na.rm = T),
ret_price = mean(retprice, na.rm = T),
youth = mean(age15to24, na.rm = T)) %>%
generate_predictor(time_window = 1984:1988,
beer_sales = mean(beer, na.rm = T)) %>%
generate_predictor(time_window = 1975,
cigsale_1975 = cigsale) %>%
generate_predictor(time_window = 1980,
cigsale_1980 = cigsale) %>%
generate_predictor(time_window = 1988,
cigsale_1988 = cigsale) %>%
generate_weights(optimization_window = 1970:1988,
margin_ipop = .02,sigf_ipop = 7,bound_ipop = 6
) %>%
generate_control()
smoking_out %>% plot_trends()
## This is the plot that is CLEARLY labeled as "Difference in synthetic control and observed Alabama"
smoking_out %>% plot_differences()
Oh -- And also, if I change generate_placebos=TRUE to FALSE in the synthetic_control() specifications, it doesn't run. (I was checking to see if it was stalling on another state via the placebo runs.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|