Load packages
# install if your computer has not yet
library(Synth)
## ##
## ## Synth Package: Implements Synthetic Control Methods.
## ## See http://www.mit.edu/~jhainm/software.htm for additional information.
library(devtools)
## Loading required package: usethis
# only run once, uncomment to install
# devtools::install_github("bcastanho/SCtools", force=TRUE)
library(SCtools)
## Loading required package: future
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
Import data
# please modify path to the dataset in your local computer
final_data <- read.csv("Downloads/SS154 Final Dataset - Sheet1.csv")
final_data <- final_data[final_data$Year >= 1990, ]
final_data <- as.data.frame(final_data)
head(final_data)
Treated Unit Summary Statistics
treated <- final_data[final_data$Country == "Australia", ]
stargazer(treated, type='text')
##
## ==============================================================================================
## Statistic N Mean St. Dev. Min Max
## ----------------------------------------------------------------------------------------------
## Id 21 1.000 0.000 1 1
## Treatment 21 1.000 0.000 1 1
## Year 21 2,000.000 6.205 1,990 2,010
## gdp_cap_growth 21 1.894 1.436 -1.645 3.814
## pop15_64 21 12,869,402.000 1,047,805.000 11,415,078 14,844,429
## inflation 21 2.838 1.597 0.225 7.333
## unemployment_rate 21 7.030 2.038 4.230 10.870
## trade 21 38.957 3.702 32.152 45.747
## for_dir_invest 21 2.491 2.092 -3.609 6.985
## gdp 21 537,865,393,006.000 261,866,442,901.000 311,433,628,319 1,148,610,059,015
## ----------------------------------------------------------------------------------------------
Control Units Summary Statistics
control <- final_data[final_data$Country != "Australia", ]
stargazer(control, type='text')
##
## ==============================================================================================
## Statistic N Mean St. Dev. Min Max
## ----------------------------------------------------------------------------------------------
## Id 252 7.500 3.459 2 13
## Treatment 252 0.000 0.000 0 0
## Year 252 2,000.000 6.067 1,990 2,010
## gdp_cap_growth 252 2.093 2.968 -8.765 12.509
## pop15_64 252 11,677,729.000 13,549,742.000 2,187,254 49,062,663
## inflation 252 2.870 3.035 -0.846 26.036
## unemployment_rate 252 6.110 2.984 0.620 17.000
## trade 252 103.188 82.255 43.488 437.327
## for_dir_invest 252 6.508 9.142 -3.812 86.479
## gdp 252 366,120,128,220.000 511,551,873,874.000 11,658,722,591 3,092,821,128,451
## ----------------------------------------------------------------------------------------------
Pre-treatment Summary Statistics Treated
treated_pre <- treated[treated$Year < 2000, ]
stargazer(treated_pre, type='text')
##
## ===========================================================================================
## Statistic N Mean St. Dev. Min Max
## -------------------------------------------------------------------------------------------
## Id 10 1.000 0.000 1 1
## Treatment 10 1.000 0.000 1 1
## Year 10 1,994.500 3.028 1,990 1,999
## gdp_cap_growth 10 2.136 1.822 -1.645 3.814
## pop15_64 10 11,964,060.000 383,189.900 11,415,078 12,568,636
## inflation 10 2.506 2.116 0.225 7.333
## unemployment_rate 10 8.772 1.427 6.870 10.870
## trade 10 36.222 2.892 32.152 39.994
## for_dir_invest 10 1.719 0.898 0.568 3.604
## gdp 10 359,201,664,428.000 45,090,403,063.000 311,433,628,319 435,614,337,142
## -------------------------------------------------------------------------------------------
Control
control_pre <- control[control$Year < 2000, ]
stargazer(control_pre, type='text')
##
## ==============================================================================================
## Statistic N Mean St. Dev. Min Max
## ----------------------------------------------------------------------------------------------
## Id 120 7.500 3.467 2 13
## Treatment 120 0.000 0.000 0 0
## Year 120 1,994.500 2.884 1,990 1,999
## gdp_cap_growth 120 2.342 3.083 -8.765 9.389
## pop15_64 120 11,084,325.000 12,720,434.000 2,187,254 43,388,020
## inflation 120 3.756 3.977 -0.268 26.036
## unemployment_rate 120 6.529 3.418 0.870 17.000
## trade 120 93.036 74.087 43.488 345.459
## for_dir_invest 120 4.467 5.553 -0.182 46.348
## gdp 120 270,730,611,475.000 343,535,556,202.000 33,100,000,000 1,689,289,758,939
## ----------------------------------------------------------------------------------------------
Synthetic Control Method
dataprep.out <- dataprep(
foo = final_data,
predictors = c("pop15_64", "unemployment_rate", "inflation", "trade", "for_dir_invest", "gdp"),
predictors.op = "mean",
time.predictors.prior = 1990:1999,
dependent = "gdp_cap_growth",
unit.variable = "Id",
unit.names.variable = "Country",
time.variable = "Year",
treatment.identifier = 1,
# c(2, 5, 7, 8, 9, 11, 13) - 0.9432
# c(2, 5, 7, 8, 11, 13) - 0.8822
# c(2, 5, 7, 8, 11, 12, 13) - 0.806
# c(2, 5, 11, 12, 13) - 0.9235
# c(2, 7, 8, 11, 12, 13) - 0.563
# c(2, 7, 8, 9, 11, 13) - 0.8036
# c(2, 12, 13) - 0.517
# c(2, 5, 12, 13) - 0.797
# c(2, 3, 5, 8, 11, 12, 13) - 0.504
# c(2, 3, 4, 5, 8, 11, 12, 13) - 0.4968
controls.identifier = c(2, 3, 4, 5, 8, 11, 12, 13),
time.optimize.ssr = 1990:2000,
time.plot = 1990:2010)
synth.out <- synth(
data.prep.obj = dataprep.out,
method = "BFGS"
)
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 0.4968261
##
## solution.v:
## 0.5045495 0.001373683 0.0004889169 0.05815829 0.0006020419 0.4348276
##
## solution.w:
## 0.3904795 5.8903e-05 2.72177e-05 0.08881921 4.74751e-05 1.01028e-05 0.2925258 0.2280318
synth.tables <- synth.tab(
dataprep.res = dataprep.out,
synth.res = synth.out
)
synth.tables$tab.pred
## Treated Synthetic Sample Mean
## pop15_64 1.196406e+07 1.177723e+07 9.042309e+06
## unemployment_rate 8.772000e+00 7.773000e+00 7.326000e+00
## inflation 2.506000e+00 3.653000e+00 2.983000e+00
## trade 3.622200e+01 5.641400e+01 9.681500e+01
## for_dir_invest 1.719000e+00 3.006000e+00 4.298000e+00
## gdp 3.592017e+11 3.670446e+11 3.136259e+11
synth.tables$tab.w
Path Plot
path.plot(synth.res = synth.out,
dataprep.res = dataprep.out,
Ylab = "GDP per capital growth (annual)",
Xlab = "Year",
Legend = c("Australia","synthetic Australia"),
Legend.position = "bottomright")
abline(v = 2000)
Gap Plot
gaps.plot(synth.res = synth.out,
dataprep.res = dataprep.out,
Ylab = c("gap in GDP per capital growth (annual)"),
Xlab = c("year")
)
abline(v = 2000)
Placebo Tests
tdf <- generate.placebos(
dataprep.out,
synth.out,
Sigf.ipop = 5,
strategy = "multicore"
)
## Warning in supportsMulticoreAndRStudio(...): [ONE-TIME WARNING] Forked
## processing ('multicore') is not supported when running R from RStudio
## because it is considered unstable. For more details, how to control forked
## processing or not, and how to silence this warning in future R sessions,
## see ?parallelly::supportsMulticore
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 6.26466
##
## solution.v:
## 0.6009495 0.009107571 0.05508626 0.008137686 2.37088e-05 0.3266953
##
## solution.w:
## 9.997e-07 0.2633867 0.5002156 1.189e-07 0.2355471 0.0008494789 4.15e-08
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 2.542585
##
## solution.v:
## 0.1128873 0.4466841 0.4148069 2.22245e-05 0.0002241347 0.02537539
##
## solution.w:
## 2.3992e-06 8.5419e-06 0.1219927 0.05617398 0.5158002 0.2694145 0.03660777
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 17.79539
##
## solution.v:
## 0.3384872 0.06357575 0.07822239 0.1203712 0.01542934 0.3839141
##
## solution.w:
## 0.4040448 2.6e-09 2e-10 0.595955 1e-10 1.591e-07 1e-10
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 6.539964
##
## solution.v:
## 0.0001784589 0.5438122 0.003633333 0.01740907 0.4342686 0.0006982853
##
## solution.w:
## 0.02146242 1.308e-07 5.91e-08 1.047e-07 5.48e-08 8.48e-08 0.9785371
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 0.4167422
##
## solution.v:
## 0.27863 0.0007524147 0.0001186392 0.02892841 0.6915403 3.02099e-05
##
## solution.w:
## 0.001930878 0.001321635 0.1495692 0.1362222 0.00619321 0.5462717 0.1584912
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 1.659618
##
## solution.v:
## 6.54703e-05 0.8035704 0.0001007131 0.1137203 0.0177856 0.06475748
##
## solution.w:
## 0.3056807 4.88039e-05 1.34074e-05 0.1415947 3.83523e-05 0.4949631 0.05766081
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 6.797972
##
## solution.v:
## 0.06413577 0.1128265 0.2981356 0.1787718 0.3307725 0.01535787
##
## solution.w:
## 1.3202e-06 0.5849031 7.66e-08 2.216e-06 2.0833e-06 3.0811e-06 0.4150881
##
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## searching for synthetic control unit
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 1.648945
##
## solution.v:
## 2.91049e-05 0.5043656 0.03589212 0.1649171 0.2014646 0.09333152
##
## solution.w:
## 5.4e-09 0.1297065 1e-10 0.2481188 0.622174 1.15e-08 6.906e-07
## New names:
## • `w.weight` -> `w.weight...1`
## • `w.weight` -> `w.weight...2`
## • `w.weight` -> `w.weight...3`
## • `w.weight` -> `w.weight...4`
## • `w.weight` -> `w.weight...5`
## • `w.weight` -> `w.weight...6`
## • `w.weight` -> `w.weight...7`
## • `w.weight` -> `w.weight...8`
# set discard.extreme to True to exclude units with high pre-treatment MSPE
p <- plot_placebos(tdf,discard.extreme=TRUE, mspe.limit=10, xlab='Year', ylab='GDP per cap growth (annual)', title = 'Spaghetti plot for placebo testing')
p