Plot Function
with.overlay <- function(est, s) { attr(est,'overlay') = s; est }
estimators <- function(sdid,sc,s) {
estimator.list = list(with.overlay(sdid, s), sc)
names(estimator.list)=c('SDID', 'SC')
estimator.list
}
plot.estimators <- function(ests, alpha.multiplier) {
p = synthdid_plot(ests, se.method='none',
alpha.multiplier=alpha.multiplier, facet=rep(1,length(ests)),
trajectory.linetype = 1, effect.curvature=-.4,
trajectory.alpha=1, effect.alpha=.5, diagram.alpha=1)
suppressMessages(p + scale_alpha(range=c(0,1), guide='none'))
}
x.br<-seq.Date(as.Date("2000-01-01"),as.Date("2014-01-01"),by="3 year")
x.lb<-format(x.br,"%Y-%m")
Import Dataset
WageCNTY <- read_csv("Average Weekly Wage (Excl 7 LA Counties).csv")
## Rows: 190723 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): time, State, CountyName
## dbl (20): Year, Qtr, Total.Covered.Total..all.industries, Federal.Government...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
WageCNTY<- WageCNTY%>%
mutate(Date = case_when(Qtr == 1 ~ paste0(Year, "-01-01"),
Qtr == 2 ~ paste0(Year, "-04-01"),
Qtr == 3 ~ paste0(Year, "-07-01"),
Qtr == 4 ~ paste0(Year, "-10-01"),
TRUE ~ "NA"))%>%
mutate(Date=as.Date(Date),
treat = ifelse(State == "Louisiana" & #Makes Louisiana as treated State
Date >= as.Date("2005-07-01"), 1, 0))
wgc<-WageCNTY%>%filter(Date<="2015-01-01",Date>="2000-01-01")
## Ballance Dataset
# Makes Ballance Dataset Prepare Date
s.t<-seq.Date(from = as.Date("2000-01-01"),
to = as.Date("2014-01-01"),
by="quarter")
unique(wgc$CountyName)%>%length() #Check number of unique msa
## [1] 3190
## Ballance Dataset
ccnty<-data.frame(Date=rep(s.t,3190))
ccnty<-arrange(ccnty,Date)
ccnty$CountyName<-rep(unique(wgc$CountyName),57)
#Joining
wgc<-left_join(ccnty,wgc,by=c("Date","CountyName"))
wgcm<-data.frame(wgc)
Total Employement
wgcm$lg<-log(wgcm$Total.Covered.Total..all.industries)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Total.Covered.Total..all.industries)))%>%
filter(!any(Total.Covered.Total..all.industries==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName",
time = "Date",
outcome = "lg",
treatment = "treat")
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.0 <- p4 + plot.theme +
labs(title = "",
y = "Total Employment", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.0

Good Producing
wgcm$lg<-log(wgcm$Private.Goods.producing)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Goods.producing)))%>%
filter(!any(Private.Goods.producing==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.1 <- p4 + plot.theme +
labs(title = "",
y = "Good Producing", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.1

Natural Resources and Mining
wgcm$lg<-log(wgcm$Private.Natural.resources.and.mining)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Natural.resources.and.mining)))%>%
filter(!any(Private.Natural.resources.and.mining==0))%>% # REMOVE 0, since we log it become inf
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.2 <- p4 + plot.theme +
labs(title = "",
y = "Natural Resources and Mining", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.2

Construction
wgcm$lg<-log(wgcm$Private.Construction)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Construction)))%>%
filter(!any(Private.Construction==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.3 <- p4 + plot.theme +
labs(title = "",
y = "Construction", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.3

Manufacturing
wgcm$lg<-log(wgcm$Private.Manufacturing)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Manufacturing)))%>%
filter(!any(Private.Manufacturing==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.4 <- p4 + plot.theme +
labs(title = "",
y = "Manufacturing", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.4

Service providing
wgcm$lg<-log(wgcm$Private.Service.providing)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Service.providing)))%>%
filter(!any(Private.Service.providing==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.5 <- p4 + plot.theme +
labs(title = "",
y = "Service providing", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.5

Trade transportation and utilities
wgcm$lg<-log(wgcm$Private.Trade..transportation..and.utilities)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Trade..transportation..and.utilities)))%>%
filter(!any(Private.Trade..transportation..and.utilities==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.6 <- p4 + plot.theme +
labs(title = "",
y = "Trade transportation and utilities", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.6

Financial activities
wgcm$lg<-log(wgcm$Private.Financial.activities)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Financial.activities)))%>%
filter(!any(Private.Financial.activities==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.7 <- p4 + plot.theme +
labs(title = "",
y = "Financial activities", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.7

Professional and business services
wgcm$lg<-log(wgcm$Private.Professional.and.business.services)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Professional.and.business.services)))%>%
filter(!any(Private.Professional.and.business.services==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.8 <- p4 + plot.theme +
labs(title = "",
y = "Professional and business services", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.8

Education and health services
wgcm$lg<-log(wgcm$Private.Education.and.health.services)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Education.and.health.services)))%>%
filter(!any(Private.Education.and.health.services==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.9 <- p4 + plot.theme +
labs(title = "",
y = "Education and health services", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.9

Leisure and hospitality
wgcm$lg<-log(wgcm$Private.Leisure.and.hospitality)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Private.Leisure.and.hospitality)))%>%
filter(!any(Private.Leisure.and.hospitality==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9)
)
pl.10 <- p4 + plot.theme +
labs(title = "",
y = "Leisure and hospitality", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.10

Local Government
wgcm$lg<-log(wgcm$Local.Government.Total..all.industries)
#Remove State if Available
wgcmp<-wgcm%>%
group_by(CountyName)%>%
filter(!any(is.na(Local.Government.Total..all.industries)))%>%
filter(!any(Local.Government.Total..all.industries==0))%>%
data.frame()
pnm<-panel.matrices(panel = wgcmp,
unit = "CountyName", #ID Variable
time = "Date", #Time Period
outcome = "lg", #Dependent Variable
treatment = "treat") #Treated Dummy
sdid.x<-synthdid_estimate(pnm$Y,pnm$N0,pnm$T0)
sc.x<-sc_estimate(pnm$Y,pnm$N0,pnm$T0)
p4 <- plot.estimators(estimators(sdid = sdid.x, sc = sc.x, s = 1),
alpha.multiplier = c(1, 1, 1))
plot.theme <- theme(legend.position="bottom",
legend.direction = 'horizontal',
legend.key = element_blank(),
legend.background = element_blank(),
plot.title = element_text(hjust = 0.5, size = 14,face = "bold"),
axis.text = element_text(size = 10),axis.title = element_text(size = 9),
)
pl.11 <- p4 + plot.theme +
labs(title = "",
y = "Local Government", x = "Date")+
geom_vline(xintercept = as.Date("2005-08-01"),linetype=2)+
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))+
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.11
