print(paste("Started at", Sys.time()))
## [1] "Started at 2020-07-18 12:17:49"
date_min <- as.Date("2019-10-01")

dt_fsurv <- readRDS(paste0(dir_exp,"firm_survival.rds"))
dt_fsurv[,weekd2:=weekd]
dt_fsurv[year==2018, weekd2:=weekd2-2+as.integer(as.Date("2020-01-19")-as.Date("2018-01-19"))]
dt_fsurv[year==2019, weekd2:=weekd2-1+as.integer(as.Date("2020-01-19")-as.Date("2019-01-19"))]
lstype <- factor(c(1:2))
levels(lstype) <- c("Panel A: Active","Panel B: Surviving")
dt_fsurvl2 <- copy(dt_fsurv)[,c("year","weekd2","sfsurvival")][, stype:=lstype[2]]
dt_fsurvl1 <- copy(dt_fsurv)[,c("year","weekd2","sfactive")][,stype:=lstype[1]]
setnames(dt_fsurvl2,"sfsurvival","sf")
setnames(dt_fsurvl1,"sfactive","sf")
dt_fsurvl <- rbind(dt_fsurvl1,dt_fsurvl2)

ggplot(dt_fsurvl, aes(x=weekd2,y=sf,color=factor(year),shape=factor(year))) + ggtheme +
  geom_line(size=1.2) +
  geom_point(size=2) +
  scale_color_brewer(palette = "Set1") +
  coord_cartesian(ylim=c(0.5,1)) +
  facet_wrap(facets=vars(stype)) +
  labs(x="Week",y="Share of Firms",color="Year",shape="Year") +
  theme(strip.text.x = element_text(size = 20))

ggsave(paste0(dir_ofig,"PA_firm_surv_sfsurv_sfact.png"), scale=1, width = 9, height = 4.5, dpi = 300, units = "in")
fwrite(dt_fsurvl, paste0(dir_ofigd,"PA_firm_surv_sfsurv_sfact.csv"))
print(paste("Ended at", Sys.time()))
## [1] "Ended at 2020-07-18 12:17:52"
# End of R script