-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscpi_illustration-multi.R
103 lines (75 loc) · 3.71 KB
/
scpi_illustration-multi.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
################################################################################
## SCPI R Package
## R-file for Empirical Illustration - Multiple Treated Units
## Authors: Matias D. Cattaneo, Yingjie Feng, Filippo Palomba, and Rocio Titiunik
################################################################################
### Clear R environment
rm(list = ls(all = TRUE))
### Install R library
#install.packages("scpi")
### Load SCPI package
library(scpi)
set.seed(8894)
###############################################################################
# MULTIPLE TREATED UNITS
###############################################################################
### Load data
data <- scpi_germany
# Create a second placebo treated unit
data$treatment <- 0
data[(data$country == "West Germany" & data$year >= 1991), "treatment"] <- 1
data[(data$country == "Italy" & data$year >= 1992), "treatment"] <- 1
######################################################
# unit-time treatment effect (\tau_{ik})
######################################################
df <- scdataMulti(data, id.var = "country", outcome.var = "gdp",
treatment.var = "treatment", time.var = "year", constant = TRUE,
cointegrated.data = TRUE, features = list(c("gdp", "trade")),
cov.adj = list(c("constant", "trend")))
res <- scest(df, w.constr = list("name" = "simplex"))
scplotMulti(res)
ggsave("germany_est_multi_1.png", height=6, width=9, dpi="retina")
respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50,
e.method = "gaussian")
# plot series
scplotMulti(respi, type = "series")
ggsave("germany_est_multi_2.png", height=6, width=9, dpi="retina")
# plot treatment
scplotMulti(respi, type = "series", joint = TRUE)
ggsave("germany_est_multi_3.png", height=6, width=9, dpi="retina")
######################################################
# average unit treatment effect (\tau_{i.})
######################################################
df <- scdataMulti(data, id.var = "country", outcome.var = "gdp",
treatment.var = "treatment", time.var = "year", constant = TRUE,
cointegrated.data = TRUE, features = list(c("gdp", "trade")),
cov.adj = list(c("constant", "trend")), effect = "unit")
res <- scest(df, w.constr = list("name" = "simplex"))
scplotMulti(res)
ggsave("germany_est_multi_4.png", height=6, width=9, dpi="retina")
respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50,
e.method = "gaussian")
# plot series
scplotMulti(respi, type = "series")
ggsave("germany_est_multi_5.png", height=6, width=9, dpi="retina")
# plot treatment
scplotMulti(respi, type = "series", joint = TRUE)
ggsave("germany_est_multi_6.png", height=6, width=9, dpi="retina")
######################################################
# average treatment effect on the treated (\tau_{.k})
######################################################
df <- scdataMulti(data, id.var = "country", outcome.var = "gdp",
treatment.var = "treatment", time.var = "year", constant = TRUE,
cointegrated.data = TRUE, features = list(c("gdp", "trade")),
cov.adj = list(c("constant", "trend")), effect = "time")
res <- scest(df, w.constr = list("name" = "simplex"))
scplotMulti(res)
ggsave("germany_est_multi_7.png", height=6, width=9, dpi="retina")
respi <- scpi(df, w.constr = list("name" = "simplex"), cores = 1, sims = 50,
e.method = "gaussian")
# plot series
scplotMulti(respi, type = "series")
ggsave("germany_est_multi_8.png", height=6, width=9, dpi="retina")
# plot treatment
scplotMulti(respi, type = "series", joint = TRUE)
ggsave("germany_est_multi_9.png", height=6, width=9, dpi="retina")