Event Study Analysis of Bed

In this analysis we try to do event study analysis, to do event study analysis we need to create time dummy for all time period, time dummy is dummy variable for indicate that an event happens in a period, For example A has observation in 2000, so time is d.2000 and the value will be 1 for A since A has observation in year 2000.

We log all response variable (y), and regress with treatment and dummy period, treatment condition is fo State equal to LA assign value 1, and 0 for non-LA. and next we set index base on RegionID and date, we repeat all the process for all 5 bed categories.

To make it easy to understand, we will plot the coefficient and its confident interval, since it has heteroscedasticity effect we will use heteroscedasticity standart error.

Import

Since each bed type has NA foe every RegionID, we need to eliminate the NA base on RegionID and bed type, for all 5 bed type.

library(readxl)
library(ggplot2)
library(readr)
library(dplyr)
library(stringr)
library(plm)
library(lmtest)

bed<-read_xlsx("Ballance 5df-Long.xlsx")
sum(is.na(bed))
## [1] 2006990
bed<-bed%>%select(-StateName,-RegionType)


bed<-bed%>%  ## Subeset Before Feb 2010,
  filter(date<"2010-02-01")

## Clean
bed<-bed%>%
  group_by(RegionName)%>%
  filter(!any(is.na(RegionID)))

bed<-data.frame(bed)
bed$date<-as.Date(bed$date)
bed$treat<-ifelse(bed$State=="LA",1,0)


## Makes Date Dummy
dloop<-data.frame(DATE=unique(bed$date))
dloop<-dloop%>%
  mutate(year=format(DATE,"%Y"),
         month=str_pad(string = format(DATE,"%m"),width = 2,side = "left",pad = 0))

## YEAR DUMMY
for (i in 1:nrow(dloop)) {
  bed[paste0("d.", dloop$year[i],".",dloop$month[i])] <- as.numeric(bed$date == unique(bed$date)[i])
}

Bed 1

b1<-bed%>%  # REMOVE METRO that bed_1 = NA
  group_by(RegionID)%>%
  filter(!any(is.na(bed_1)))

mb1<-plm(
  log(bed_1)~treat:(d.2000.01+d.2000.02+d.2000.03+d.2000.04+d.2000.05+d.2000.06+d.2000.07+d.2000.08+d.2000.09+d.2000.10+d.2000.11+d.2000.12+
           d.2001.01+d.2001.02+d.2001.03+d.2001.04+d.2001.05+d.2001.06+d.2001.07+d.2001.08+d.2001.09+d.2001.10+d.2001.11+d.2001.12+
           d.2002.01+d.2002.02+d.2002.03+d.2002.04+d.2002.05+d.2002.06+d.2002.07+d.2002.08+d.2002.09+d.2002.10+d.2002.11+d.2002.12+
           d.2003.01+d.2003.02+d.2003.03+d.2003.04+d.2003.05+d.2003.06+d.2003.07+d.2003.08+d.2003.09+d.2003.10+d.2003.11+d.2003.12+
           d.2004.01+d.2004.02+d.2004.03+d.2004.04+d.2004.05+d.2004.06+d.2004.07+d.2004.08+d.2004.09+d.2004.10+d.2004.11+d.2004.12+
           d.2005.01+d.2005.02+d.2005.03+d.2005.04+d.2005.05+d.2005.06+d.2005.07+d.2005.08+d.2005.10+d.2005.11+d.2005.12+
           d.2006.01+d.2006.02+d.2006.03+d.2006.04+d.2006.05+d.2006.06+d.2006.07+d.2006.08+d.2006.09+d.2006.10+d.2006.11+d.2006.12+
           d.2007.01+d.2007.02+d.2007.03+d.2007.04+d.2007.05+d.2007.06+d.2007.07+d.2007.08+d.2007.09+d.2007.10+d.2007.11+d.2007.12+
           d.2008.01+d.2008.02+d.2008.03+d.2008.04+d.2008.05+d.2008.06+d.2008.07+d.2008.08+d.2008.09+d.2008.10+d.2008.11+d.2008.12+
           d.2009.01+d.2009.02+d.2009.03+d.2009.04+d.2009.05+d.2009.06+d.2009.07+d.2009.08+d.2009.09+d.2009.10+d.2009.11+d.2009.12+
           d.2010.01),data = b1, model = "within", index=c("RegionID", "date"),cluster="RegionID")

coef_df <- coeftest(mb1,vcov. = vcovHC(mb1,type = "HC1"))

coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df$date<-as.Date(paste0(coef_df$variables,".01"),format="treat:d.%Y.%m.%d")

event_df<-data.frame(date=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by = "month"))
event_df<-left_join(event_df,coef_df[,c(1,2,6)])
event_df[is.na(event_df)]<-0

colnames(event_df)<-c("time","coef","se")

event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
head(event_df,3)
##         time       coef           se   ci_upper   ci_lower
## 1 2000-01-01 -0.4743633 1.191617e-14 -0.4743633 -0.4743633
## 2 2000-02-01 -0.4811336 1.282395e-14 -0.4811336 -0.4811336
## 3 2000-03-01 -0.4797070 1.455398e-14 -0.4797070 -0.4797070

as we see from tables of coefficient above we have, small value for standard error (se), it will cause effect to small confident interval we build.

dates<-seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by='month')
# Define start and end dates for plot
start_date <- as.Date("2004-08-01")
end_date <- as.Date("2010-01-01")

# Create sequence of dates for x-axis
dates_seq <- seq.Date(from = start_date, to = end_date, by = "month")

# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]

pl<-ggplot(event_df, aes(x = dates, y = coef)) +
  geom_point() +
  geom_line()+
  #geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
  geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2005-08-01"), linetype = "dashed", color = "blue") +
  scale_x_date(date_labels = "%b %Y", limits = c(start_date, end_date), breaks = "1 year") +
  labs(x = "Date", y = "Coefficient", title = "") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()

pl

png("Bed1.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png 
##   2

We see from graph above, because of effect small Standard error, we dont have visible confident interval in our graph

Bed 2

b2<-bed%>%  # REMOVE METRO that bed_1 = NA
  group_by(RegionID)%>%
  filter(!any(is.na(bed_2)))

mb2<-plm(
  log(bed_2)~treat:(
           d.2000.01+d.2000.02+d.2000.03+d.2000.04+d.2000.05+d.2000.06+d.2000.07+d.2000.08+d.2000.09+d.2000.10+d.2000.11+d.2000.12+
           d.2001.01+d.2001.02+d.2001.03+d.2001.04+d.2001.05+d.2001.06+d.2001.07+d.2001.08+d.2001.09+d.2001.10+d.2001.11+d.2001.12+
           d.2002.01+d.2002.02+d.2002.03+d.2002.04+d.2002.05+d.2002.06+d.2002.07+d.2002.08+d.2002.09+d.2002.10+d.2002.11+d.2002.12+
           d.2003.01+d.2003.02+d.2003.03+d.2003.04+d.2003.05+d.2003.06+d.2003.07+d.2003.08+d.2003.09+d.2003.10+d.2003.11+d.2003.12+
           d.2004.01+d.2004.02+d.2004.03+d.2004.04+d.2004.05+d.2004.06+d.2004.07+d.2004.08+d.2004.09+d.2004.10+d.2004.11+d.2004.12+
           d.2005.01+d.2005.02+d.2005.03+d.2005.04+d.2005.05+d.2005.06+d.2005.07+d.2005.08+d.2005.10+d.2005.11+d.2005.12+
           d.2006.01+d.2006.02+d.2006.03+d.2006.04+d.2006.05+d.2006.06+d.2006.07+d.2006.08+d.2006.09+d.2006.10+d.2006.11+d.2006.12+
           d.2007.01+d.2007.02+d.2007.03+d.2007.04+d.2007.05+d.2007.06+d.2007.07+d.2007.08+d.2007.09+d.2007.10+d.2007.11+d.2007.12+
           d.2008.01+d.2008.02+d.2008.03+d.2008.04+d.2008.05+d.2008.06+d.2008.07+d.2008.08+d.2008.09+d.2008.10+d.2008.11+d.2008.12+
           d.2009.01+d.2009.02+d.2009.03+d.2009.04+d.2009.05+d.2009.06+d.2009.07+d.2009.08+d.2009.09+d.2009.10+d.2009.11+d.2009.12+
           d.2010.01),data = b2, model = "within", index=c("RegionID", "date"),cluster="RegionID")

coef_df <- coeftest(mb2,vcov. = vcovHC(mb2,type = "HC1"))

coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df$date<-as.Date(paste0(coef_df$variables,".01"),format="treat:d.%Y.%m.%d")

event_df<-data.frame(date=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by = "month"))
event_df<-left_join(event_df,coef_df[,c(1,2,6)])
event_df[is.na(event_df)]<-0

colnames(event_df)<-c("time","coef","se")

event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
head(event_df,3)
##         time       coef         se   ci_upper   ci_lower
## 1 2000-01-01 -0.3251241 0.07114395 -0.1856819 -0.4645662
## 2 2000-02-01 -0.3270033 0.07131824 -0.1872195 -0.4667870
## 3 2000-03-01 -0.3269850 0.07111979 -0.1875902 -0.4663798
dates<-seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by='month')
# Define start and end dates for plot
start_date <- as.Date("2004-08-01")
end_date <- as.Date("2010-01-01")

# Create sequence of dates for x-axis
dates_seq <- seq.Date(from = start_date, to = end_date, by = "month")

# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]

pl<-ggplot(event_df, aes(x = dates, y = coef)) +
  geom_point() +
  geom_line()+
  #geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
  geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2005-08-01"), linetype = "dashed", color = "blue") +
  scale_x_date(date_labels = "%b %Y", limits = c(start_date, end_date), breaks = "1 year") +
  labs(x = "Date", y = "Coefficient", title = "") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()

pl

png("Bed2.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png 
##   2

Bed 3

b3<-bed%>%  # REMOVE METRO that bed_1 = NA
  group_by(RegionID)%>%
  filter(!any(is.na(bed_3)))

mb3<-plm(
  log(bed_3)~treat:(
           d.2000.01+d.2000.02+d.2000.03+d.2000.04+d.2000.05+d.2000.06+d.2000.07+d.2000.08+d.2000.09+d.2000.10+d.2000.11+d.2000.12+
           d.2001.01+d.2001.02+d.2001.03+d.2001.04+d.2001.05+d.2001.06+d.2001.07+d.2001.08+d.2001.09+d.2001.10+d.2001.11+d.2001.12+
           d.2002.01+d.2002.02+d.2002.03+d.2002.04+d.2002.05+d.2002.06+d.2002.07+d.2002.08+d.2002.09+d.2002.10+d.2002.11+d.2002.12+
           d.2003.01+d.2003.02+d.2003.03+d.2003.04+d.2003.05+d.2003.06+d.2003.07+d.2003.08+d.2003.09+d.2003.10+d.2003.11+d.2003.12+
           d.2004.01+d.2004.02+d.2004.03+d.2004.04+d.2004.05+d.2004.06+d.2004.07+d.2004.08+d.2004.09+d.2004.10+d.2004.11+d.2004.12+
           d.2005.01+d.2005.02+d.2005.03+d.2005.04+d.2005.05+d.2005.06+d.2005.07+d.2005.08+d.2005.10+d.2005.11+d.2005.12+
           d.2006.01+d.2006.02+d.2006.03+d.2006.04+d.2006.05+d.2006.06+d.2006.07+d.2006.08+d.2006.09+d.2006.10+d.2006.11+d.2006.12+
           d.2007.01+d.2007.02+d.2007.03+d.2007.04+d.2007.05+d.2007.06+d.2007.07+d.2007.08+d.2007.09+d.2007.10+d.2007.11+d.2007.12+
           d.2008.01+d.2008.02+d.2008.03+d.2008.04+d.2008.05+d.2008.06+d.2008.07+d.2008.08+d.2008.09+d.2008.10+d.2008.11+d.2008.12+
           d.2009.01+d.2009.02+d.2009.03+d.2009.04+d.2009.05+d.2009.06+d.2009.07+d.2009.08+d.2009.09+d.2009.10+d.2009.11+d.2009.12+
           d.2010.01),data = b3, model = "within", index=c("RegionID", "date"),cluster="RegionID")

coef_df <- coeftest(mb3,vcov. = vcovHC(mb3,type = "HC1"))

coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df$date<-as.Date(paste0(coef_df$variables,".01"),format="treat:d.%Y.%m.%d")

event_df<-data.frame(date=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by = "month"))
event_df<-left_join(event_df,coef_df[,c(1,2,6)])
event_df[is.na(event_df)]<-0

colnames(event_df)<-c("time","coef","se")

event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
head(event_df,3)
##         time       coef         se   ci_upper   ci_lower
## 1 2000-01-01 -0.2935417 0.03368056 -0.2275278 -0.3595556
## 2 2000-02-01 -0.2918290 0.03238396 -0.2283565 -0.3553016
## 3 2000-03-01 -0.2905869 0.03183960 -0.2281813 -0.3529925
dates<-seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by='month')
# Define start and end dates for plot
start_date <- as.Date("2004-08-01")
end_date <- as.Date("2010-01-01")

# Create sequence of dates for x-axis
dates_seq <- seq.Date(from = start_date, to = end_date, by = "month")

# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]

pl<-ggplot(event_df, aes(x = dates, y = coef)) +
  geom_point() +
  geom_line()+
  #geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
  geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2005-08-01"), linetype = "dashed", color = "blue") +
  scale_x_date(date_labels = "%b %Y", limits = c(start_date, end_date), breaks = "1 year") +
  labs(x = "Date", y = "Coefficient", title = "") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()

pl

png("Bed3.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png 
##   2

Bed 4

b4<-bed%>%  # REMOVE METRO that bed_1 = NA
  group_by(RegionID)%>%
  filter(!any(is.na(bed_4)))

mb4<-plm(
  log(bed_4)~treat:(
           d.2000.01+d.2000.02+d.2000.03+d.2000.04+d.2000.05+d.2000.06+d.2000.07+d.2000.08+d.2000.09+d.2000.10+d.2000.11+d.2000.12+
           d.2001.01+d.2001.02+d.2001.03+d.2001.04+d.2001.05+d.2001.06+d.2001.07+d.2001.08+d.2001.09+d.2001.10+d.2001.11+d.2001.12+
           d.2002.01+d.2002.02+d.2002.03+d.2002.04+d.2002.05+d.2002.06+d.2002.07+d.2002.08+d.2002.09+d.2002.10+d.2002.11+d.2002.12+
           d.2003.01+d.2003.02+d.2003.03+d.2003.04+d.2003.05+d.2003.06+d.2003.07+d.2003.08+d.2003.09+d.2003.10+d.2003.11+d.2003.12+
           d.2004.01+d.2004.02+d.2004.03+d.2004.04+d.2004.05+d.2004.06+d.2004.07+d.2004.08+d.2004.09+d.2004.10+d.2004.11+d.2004.12+
           d.2005.01+d.2005.02+d.2005.03+d.2005.04+d.2005.05+d.2005.06+d.2005.07+d.2005.08+d.2005.10+d.2005.11+d.2005.12+
           d.2006.01+d.2006.02+d.2006.03+d.2006.04+d.2006.05+d.2006.06+d.2006.07+d.2006.08+d.2006.09+d.2006.10+d.2006.11+d.2006.12+
           d.2007.01+d.2007.02+d.2007.03+d.2007.04+d.2007.05+d.2007.06+d.2007.07+d.2007.08+d.2007.09+d.2007.10+d.2007.11+d.2007.12+
           d.2008.01+d.2008.02+d.2008.03+d.2008.04+d.2008.05+d.2008.06+d.2008.07+d.2008.08+d.2008.09+d.2008.10+d.2008.11+d.2008.12+
           d.2009.01+d.2009.02+d.2009.03+d.2009.04+d.2009.05+d.2009.06+d.2009.07+d.2009.08+d.2009.09+d.2009.10+d.2009.11+d.2009.12+
           d.2010.01),data = b4, model = "within", index=c("RegionID", "date"),cluster="RegionID")

coef_df <- coeftest(mb4,vcov. = vcovHC(mb4,type = "HC1"))

coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df$date<-as.Date(paste0(coef_df$variables,".01"),format="treat:d.%Y.%m.%d")

event_df<-data.frame(date=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by = "month"))
event_df<-left_join(event_df,coef_df[,c(1,2,6)])
event_df[is.na(event_df)]<-0

colnames(event_df)<-c("time","coef","se")

event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
head(event_df,3)
##         time       coef         se   ci_upper   ci_lower
## 1 2000-01-01 -0.2587252 0.02740489 -0.2050116 -0.3124388
## 2 2000-02-01 -0.2576188 0.02809012 -0.2025621 -0.3126754
## 3 2000-03-01 -0.2574508 0.02888244 -0.2008412 -0.3140604
dates<-seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by='month')
# Define start and end dates for plot
start_date <- as.Date("2004-08-01")
end_date <- as.Date("2010-01-01")

# Create sequence of dates for x-axis
dates_seq <- seq.Date(from = start_date, to = end_date, by = "month")

# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]

pl<-ggplot(event_df, aes(x = dates, y = coef)) +
  geom_point() +
  geom_line()+
  #geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
  geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2005-08-01"), linetype = "dashed", color = "blue") +
  scale_x_date(date_labels = "%b %Y", limits = c(start_date, end_date), breaks = "1 year") +
  labs(x = "Date", y = "Coefficient", title = "") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()

pl

png("Bed4.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png 
##   2

Bed 5

b5<-bed%>%  # REMOVE METRO that bed_1 = NA
  group_by(RegionID)%>%
  filter(!any(is.na(bed_5)))

mb5<-plm(
  log(bed_5)~treat:(
           d.2000.01+d.2000.02+d.2000.03+d.2000.04+d.2000.05+d.2000.06+d.2000.07+d.2000.08+d.2000.09+d.2000.10+d.2000.11+d.2000.12+
           d.2001.01+d.2001.02+d.2001.03+d.2001.04+d.2001.05+d.2001.06+d.2001.07+d.2001.08+d.2001.09+d.2001.10+d.2001.11+d.2001.12+
           d.2002.01+d.2002.02+d.2002.03+d.2002.04+d.2002.05+d.2002.06+d.2002.07+d.2002.08+d.2002.09+d.2002.10+d.2002.11+d.2002.12+
           d.2003.01+d.2003.02+d.2003.03+d.2003.04+d.2003.05+d.2003.06+d.2003.07+d.2003.08+d.2003.09+d.2003.10+d.2003.11+d.2003.12+
           d.2004.01+d.2004.02+d.2004.03+d.2004.04+d.2004.05+d.2004.06+d.2004.07+d.2004.08+d.2004.09+d.2004.10+d.2004.11+d.2004.12+
           d.2005.01+d.2005.02+d.2005.03+d.2005.04+d.2005.05+d.2005.06+d.2005.07+d.2005.08+d.2005.10+d.2005.11+d.2005.12+
           d.2006.01+d.2006.02+d.2006.03+d.2006.04+d.2006.05+d.2006.06+d.2006.07+d.2006.08+d.2006.09+d.2006.10+d.2006.11+d.2006.12+
           d.2007.01+d.2007.02+d.2007.03+d.2007.04+d.2007.05+d.2007.06+d.2007.07+d.2007.08+d.2007.09+d.2007.10+d.2007.11+d.2007.12+
           d.2008.01+d.2008.02+d.2008.03+d.2008.04+d.2008.05+d.2008.06+d.2008.07+d.2008.08+d.2008.09+d.2008.10+d.2008.11+d.2008.12+
           d.2009.01+d.2009.02+d.2009.03+d.2009.04+d.2009.05+d.2009.06+d.2009.07+d.2009.08+d.2009.09+d.2009.10+d.2009.11+d.2009.12+
           d.2010.01),data = b5, model = "within", index=c("RegionID", "date"),cluster="RegionID")

coef_df <- coeftest(mb5,vcov. = vcovHC(mb5,type = "HC1"))

coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df$date<-as.Date(paste0(coef_df$variables,".01"),format="treat:d.%Y.%m.%d")

event_df<-data.frame(date=seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by = "month"))
event_df<-left_join(event_df,coef_df[,c(1,2,6)])
event_df[is.na(event_df)]<-0

colnames(event_df)<-c("time","coef","se")

event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
head(event_df,3)
##         time       coef         se   ci_upper   ci_lower
## 1 2000-01-01 -0.3273658 0.03764264 -0.2535863 -0.4011454
## 2 2000-02-01 -0.3262116 0.03595776 -0.2557344 -0.3966888
## 3 2000-03-01 -0.3286631 0.03411860 -0.2617906 -0.3955355
dates<-seq.Date(as.Date("2000-01-01"),as.Date("2010-01-01"),by='month')
# Define start and end dates for plot
start_date <- as.Date("2004-08-01")
end_date <- as.Date("2010-01-01")

# Create sequence of dates for x-axis
dates_seq <- seq.Date(from = start_date, to = end_date, by = "month")

# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]

pl<-ggplot(event_df, aes(x = dates, y = coef)) +
  geom_point() +
  geom_line()+
  #geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
  geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2005-08-01"), linetype = "dashed", color = "blue") +
  scale_x_date(date_labels = "%b %Y", limits = c(start_date, end_date), breaks = "1 year") +
  labs(x = "Date", y = "Coefficient", title = "") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()

pl

png("Bed5.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png 
##   2