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+Fixed', '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'))
}
#Xlabel show
x.br<-seq.Date(as.Date("2000-01-01"),as.Date("2015-01-01"),by="5 year")
x.lb<-format(x.br,"%Y-%m")
Import Dataset
Emp<-read.csv("Copy of Employment (State).csv")
## Generate Date from Month Info,
Emp <- Emp%>%
mutate(Date = paste0(Year,
str_pad(string = Month,
width = 2,
side = "left",
pad = 0),
"01"))%>% ## Adding treated State
mutate(Date=as.Date(Date,format="%Y%m%d"),
treat = ifelse(State == "Louisiana " & #Makes Louisiana as treated State
Date >= as.Date("2005-08-01"), 1, 0)) # Set treated period start from August 2005
Ed<-Emp%>%filter(Date<="2015-01-01",Date>="2000-01-01")
Ed<-data.frame(Ed)
Total Employement
Ed$lg<-log(Ed$Total.Covered.Total..all.industries) # makes a log
#Remove State if NA Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Total.Covered.Total..all.industries)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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.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))+ ## Remove E from Hight Number
scale_x_continuous(breaks = x.br,
labels = x.lb)
pl.0

Good Producing
Ed$lg<-log(Ed$Private.Goods.producing)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Goods.producing)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Natural.resources.and.mining)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
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 = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Construction)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Construction)))%>%
filter(!any(Private.Construction==0))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Manufacturing)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Manufacturing)))%>%
filter(!any(Private.Manufacturing==0))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Service.providing)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Service.providing)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Trade..transportation..and.utilities)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Trade..transportation..and.utilities)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Financial.activities)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Financial.activities)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Professional.and.business.services)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Professional.and.business.services)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Education.and.health.services)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Education.and.health.services)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Private.Leisure.and.hospitality)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Private.Leisure.and.hospitality)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
Ed$lg<-log(Ed$Local.Government.Total..all.industries)
#Remove State if Available
Edp<-Ed%>%
group_by(State)%>%
filter(!any(is.na(Local.Government.Total..all.industries)))%>%
data.frame()
pnm<-panel.matrices(panel = Edp,
unit = "State", #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
