-
Notifications
You must be signed in to change notification settings - Fork 14
/
google_trends_UI_statepolicy.Rmd
622 lines (509 loc) · 27.6 KB
/
google_trends_UI_statepolicy.Rmd
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
---
title: "google_trends_UI_statepolicy"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# if (!require("devtools")) install.packages("devtools")
# devtools::install_github("paulgp/gtrendsR")
#install.packages("RApiDatetime")
library(gtrendsR)
library(tidyverse)
library(ggrepel)
library(RApiDatetime)
library(lubridate)
library(zoo)
library(knitr)
library(kableExtra)
library(readxl)
library(janitor)
library(RColorBrewer)
library(data.table)
library(plm)
library(directlabels)
```
# State Policy Actions
In recent weeks, Governors across the US have issued executive orders requiring that businesses change or limit their in-person operations. In most states, restaurants are only permitted to operate take-out and/or delivery services. While some restaurants have opted to stay open and attempt to weather the storm with reduced operations, others have shut down entirely. This has resulted in mass layoffs in the food service industry across the country, contributing to the skyrocketing UI claims numbers.
Further, in some states, Governors have called for all non-essential businesses to close. Many shops and malls, theaters and museums, gyms and yoga studios, and concert halls and clubs have been ordered to cease operations. While some businesses can scale up their e-commerce operations or survive on take-out orders alone, many are forced to lay off their workers.
The timing of states' closure orders have varied, so we've put together some maps to show the timing.
##Orders Affecting Business Operations and Closures
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###### Liz doing state policy stuff #######
###Make maps of timing of state policies ###
#Set up data
##Import policy data
data_policy_states <- read_xlsx("data/covid_closures_by_state.xlsx") %>%
mutate_at(c("partial", "school", "complete"), funs(ymd))%>%
mutate(complete_week = epiweek(complete), partial_week = epiweek(partial), school_week = epiweek(school)) %>%
mutate(complete_day = day(complete), partial_day = day(partial), school_day = day(school)) %>%
mutate(region = tolower(state)) %>%
rename("location" = "state_abbr")
##Add shape files
states <- map_data("state")
dates_map <- left_join(states, data_policy_states, by = "region")
#Map of complete closure orders
dates_map$complete <- format(dates_map$complete, format = "%m/%d")
complete_map <-
ggplot(dates_map, aes(long, lat, group = group)) +
geom_polygon(aes(fill = factor(complete)), color = "white") +
ggtitle("Non-Essential Business Closure Orders") +
scale_fill_manual(values = colorRampPalette(brewer.pal(15, "BuPu"))(15), name = "Effective Date", na.value = "grey50", guide = "legend", drop = "TRUE") +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
rect = element_blank(),
axis.title.y=element_blank(),
axis.title.x=element_blank(),
plot.title = element_text(hjust = 0.5, size = 18))
#Map of partial closure orders
dates_map$partial <- format(dates_map$partial, format = "%m/%d")
takeout_map <-
ggplot(dates_map, aes(long, lat, group = group)) +
geom_polygon(aes(fill = factor(partial)), color = "white") +
ggtitle("Prohibition on Dining In and Partial Closure Orders") +
scale_fill_manual(values = colorRampPalette(brewer.pal(15, "GnBu"))(15), name = "Effective Date", na.value = "grey50", guide = "legend", drop = "TRUE") +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
rect = element_blank(),
axis.title.y=element_blank(),
axis.title.x=element_blank(),
plot.title = element_text(hjust = 0.5, size = 18))
complete_map
takeout_map
```
We define partial closures as orders that prohibited restaurants from having patrons dine in. In many states, other provisions were included in these orders (e.g., limits on gathering sizes, requirements for bars/clubs to close). We use the switch to take-out only for consistency.
We define complete closures as orders for non-essential businesses to close. States vary in their definitions of essential businesses, and some states also put stay at home or shelter in place orders. For consistency, we hone in specifically on the non-essential business closures.
Both of these definitions are consistent with analyzing policy effects on UI claims and search activity -- as businesses close, layoffs increase.
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###Event Studies###
#Set up data for event studies
##Merge policy data with google search data
policy_event_study <- left_join(data_states_short, data_policy_states, by = "location") %>%
filter(date > as.Date("2020-03-01") ) %>%
mutate(daystopartial = difftime(date, partial , units = c("days"))) %>%
mutate(daystocomplete = difftime(date, complete , units = c("days"))) %>%
group_by(location) %>%
mutate(laghits=dplyr::lag(hits, order_by = location)) %>%
ungroup %>%
pivot_longer(
cols = c(daystopartial, daystocomplete),
names_to = "type",
values_to = "days"
)
##Define event study pre and post length
es_start = -7
es_end = 4
es_length = 11
## This sets the baseline period to t-1, change by making ref = 8 for t0 or ref = 6 for t-2
policy_event_study_releveled <- policy_event_study %>%
filter(days %in% es_start:es_end) %>%
mutate(days_factor = relevel(as.factor(days), ref = 7))
#Event study around partial closure policies
partial_es <- plm(hits ~ as.factor(days_factor),
data = subset(policy_event_study_releveled, type == "daystopartial"),
index = "location",
effect = "individual",
model = "within")
partial_coefs = as.data.frame(summary(partial_es)$coefficients[1:es_length]) %>%
mutate(closuretype = "partial")
colnames(partial_coefs)[1] <- "coeffecients"
partial_coefs$timefromorder <- es_start:(es_end-1)
partial_coefs$timefromorder <- ifelse(partial_coefs$timefromorder >=-1, partial_coefs$timefromorder + 1, partial_coefs$timefromorder)
#Plot the event study
partial_es_plot <- ggplot(data=partial_coefs, aes(x=timefromorder, y=coeffecients))+
geom_line(,color = "darkgray") +
geom_vline(xintercept = 0, color = "mediumpurple2", size = 1.5, alpha = .75) +
labs(y = "Change in Google Search Intensity",
x = "Days from Partial Closure Order",
title="Search Trends in Response to Partial Closures") +
theme_classic(base_size=15) +
scale_x_continuous(breaks = seq(es_start, es_end, by = 1))
#Event study around complete closure policies
complete_es <- plm(hits ~ as.factor(days_factor),
data = subset(policy_event_study_releveled, type == "daystocomplete"),
index = "location",
effect = "individual",
model = "within")
complete_coefs <- as.data.frame(summary(complete_es)$coefficients[1:es_length]) %>%
mutate(closuretype = "complete")
colnames(complete_coefs)[1] <- "coeffecients"
complete_coefs$timefromorder <- es_start:(es_end-1)
complete_coefs$timefromorder <- ifelse(complete_coefs$timefromorder >=-1, complete_coefs$timefromorder + 1, complete_coefs$timefromorder)
#Plot the event study
complete_es_plot <- ggplot(data=complete_coefs, aes(x=timefromorder, y=coeffecients))+
geom_line(,color = "darkgray") +
geom_vline(xintercept = 0, color = "cadetblue3", size = 1.5, alpha = .75) +
labs(y = "Change in Google Search Intensity",
x = "Days from Complete Closure Order",
title="Search Trends in Response to Complete Closures") +
theme_classic(base_size=15) +
scale_x_continuous(breaks = seq(es_start, es_end, by = 1))
#Plot both event studies together
both_es_coefficients <- complete_coefs %>%
rbind(partial_coefs)
labs <- setNames(c(" Partial", " Complete"), c("partial", "complete"))
ggplot(both_es_coefficients, aes(x = timefromorder, y = coeffecients, group = closuretype, color = closuretype)) +
geom_line() +
geom_vline(aes(xintercept = 0), alpha = .3, size = 1.5, color = "black") +
theme_classic(base_size=15) +
labs(y = "Change in Google Search Intensity",
x = "Days from Closure Order",
title = "Search Trends in Response to Closures",
color = "Closure Type") +
scale_color_manual(values = c("cadetblue3", "mediumpurple2"), guide = FALSE) +
scale_x_continuous(breaks = seq(es_start,es_end, by = 1)) +
geom_dl(aes(label=labs[closuretype]), method="last.points") +
coord_cartesian(clip = "off") +
theme(plot.margin = margin(1, 45, 1, 1))
partial_es_plot
complete_es_plot
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###Graph average google search numbers over time (relative to policy enactment day), weighted by state labor force###
#!! Before Paul's 4/6 email
#Set up data
##First pull in state labor force data
labor_force_states = read_xlsx("data/labor_force_state.xlsx")
##Merge with policy data
policy_search_lf <- left_join(policy_event_study, labor_force_states, by = "state") %>%
#Collapse hits for the days around policies, weighted by lf size
group_by(type, days) %>%
summarize_at("hits", list(weighted.mean), weight = "lf_022020") %>%
filter(days %in% -7:7)
#Plot (first individviually, then together)
ggplot(data = policy_search_lf %>% filter(type == "daystopartial")) +
geom_line(aes(x = days, y = hits), color = "black") +
geom_vline(aes(xintercept = 0, show.guide = TRUE), alpha = .5, size = 1.5, color = "mediumpurple2") +
theme_classic(base_size=10) +
labs(x = "Days from Partial Closure",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Partial Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_x_continuous(breaks = seq(-7, 7, by = 1))
ggplot(data = policy_search_lf %>% filter(type == "daystocomplete")) +
geom_line(aes(x = days, y = hits), color = "black") +
geom_vline(aes(xintercept = 0, show.guide = TRUE), alpha = .5, size = 1.5, color = "cadetblue3") +
theme_classic(base_size=10) +
labs(x = "Days from Partial Closure",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Partial Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_x_continuous(breaks = seq(-7, 7, by = 1))
labs <- setNames(c(" Partial", " Complete"), c("daystopartial", "daystocomplete"))
ggplot(policy_search_lf, aes(x = days, y = hits, group = type, color = type)) +
geom_line() +
geom_vline(aes(xintercept = 0), alpha = .3, size = 1.5, color = "black") +
theme_classic(base_size=10) +
labs(x = "Days from Closure Effective Date",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Closures",
subtitle = "Weighted by size of states' labor force in Feb. 2020",
color = "Closure Type") +
scale_color_manual(values = c("cadetblue3", "mediumpurple2"), guide = FALSE) +
scale_x_continuous(breaks = seq(-7, 7, by = 1)) +
geom_dl(aes(label=labs[type]), method="last.points") +
coord_cartesian(clip = "off") +
theme(plot.margin = margin(1, 45, 1, 1))
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###Graph average google search numbers over time (relative to policy enactment day), weighted by state labor force###
#Based on Paul's 4/6 email:
#Partial Treatment States:
data_policy_states %>%
filter(partial <= as.Date("2020-03-16")) %>%
subset(select = state)
#Partial Control States:
data_policy_states %>%
filter(is.na(partial) | partial >= as.Date("2020-03-24")) %>%
subset(select = state)
#Complete Treatment States:
data_policy_states %>%
filter(complete <= as.Date("2020-03-23")) %>%
subset(select = state)
#Complete Control States:
data_policy_states %>%
filter(is.na(complete) | complete >= as.Date("2020-03-31")) %>%
subset(select = state)
##Set up data
policy_search_lf_filtered1 <- data_policy_states %>%
#Filter to treatment and control
mutate(complete_treatment = case_when(
complete <= as.Date("2020-03-23") ~ 1,
complete >= as.Date("2020-03-31") ~ 0,
complete = is.na(complete) ~ 0)) %>%
mutate(partial_treatment = case_when(
partial <= as.Date("2020-03-16") ~ 1,
partial >= as.Date("2020-03-24") ~ 0,
partial = is.na(partial) ~ 0)) %>%
filter(!is.na(partial_treatment) | !is.na(complete_treatment)) %>%
mutate(partial_treatment = as.factor(partial_treatment)) %>%
mutate(complete_treatment = as.factor(complete_treatment)) %>%
#Add in google search data
left_join(data_states_short, by = "location") %>%
#Filter out lots of pre-data
filter(date > as.Date("2020-03-10") ) %>%
#Reshape for graphs later
pivot_longer(
cols = c(complete_treatment, partial_treatment),
names_to = "group",
values_to = "treatment",
names_repair = "minimal") %>%
#Merge in labor force data for weighting
left_join(labor_force_states, by = "state") %>%
#Collapse hits by date by group, weighted by lf size
group_by(date, group, treatment) %>%
summarize_at("hits", list(weighted.mean), weight = "lf_022020") %>%
#Remove lines that aren't treatment or control
filter(!is.na(treatment))
##Plot (separately)
ggplot(data = policy_search_lf_filtered1 %>% filter(group == "partial_treatment")) +
geom_line(aes(x = date, y = hits, group = treatment, color = treatment)) +
annotate("rect", xmin = min(data_policy_states$partial, na.rm = T), xmax = as.Date("2020-03-16"), min = 0, ymax = Inf, alpha = .2, fill = "mediumpurple2") +
theme_classic(base_size=10) +
labs(x = "Date",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Partial Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_color_manual(values = c("black", "mediumpurple2"), guide = FALSE) +
scale_x_date(date_breaks = "2 days",
date_labels = "%m-%d",
limits = as.Date(c("2020-03-10","2020-03-24")))
ggplot(data = policy_search_lf_filtered1 %>% filter(group == "complete_treatment")) +
geom_line(aes(x = date, y = hits, group = treatment, color = treatment)) +
annotate("rect", xmin = min(data_policy_states$complete, na.rm = T), xmax = as.Date("2020-03-23"), ymin = 0, ymax = Inf, alpha = .2, fill = "cadetblue3") +
theme_classic(base_size=10) +
labs(x = "Date",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Complete Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_color_manual(values = c("black", "cadetblue3"), guide = FALSE) +
scale_x_date(date_breaks = "2 days",
date_labels = "%m-%d",
limits = as.Date(c("2020-03-10","2020-03-31")))
#This time, allow 3 treatment groups: 23rd, 24th, and 25th enactors, and control group is states who don't enact by 4/1 and only do for complete
##Set up data
policy_search_lf_filtered2 <- data_policy_states %>%
#Filter to treatment and control
mutate(complete_treatment = case_when(
complete == as.Date("2020-03-23") ~ "23rd",
complete == as.Date("2020-03-24") ~ "24th",
complete == as.Date("2020-03-25") ~ "25th",
complete >= as.Date("2020-04-02") ~ "Control",
complete = is.na(complete) ~ "Control")) %>%
filter(!is.na(complete_treatment)) %>%
#Add in google search data
left_join(data_states_short, by = "location") %>%
#Filter out lots of pre-data
filter(date > as.Date("2020-03-10") ) %>%
#Reshape for graphs later
pivot_longer(
cols = c(complete_treatment),
names_to = "group",
values_to = "treatment",
names_repair = "minimal") %>%
#Merge in labor force data for weighting
left_join(labor_force_states, by = "state") %>%
#Collapse hits by date by group, weighted by lf size
group_by(date, group, treatment) %>%
summarize_at("hits", list(weighted.mean), weight = "lf_022020") %>%
#Remove lines that aren't treatment or control
filter(!is.na(treatment))
##Plot
ggplot(data = policy_search_lf_filtered2) +
geom_line(aes(x = date, y = hits, group = treatment, color = treatment)) +
annotate("rect", xmin = as.Date("2020-03-23 00:00:00"), xmax = as.Date("2020-03-24 00:00:00"), min = 0, ymax = Inf, alpha = .2, fill = "palevioletred") +
annotate("rect", xmin = as.Date("2020-03-24 00:00:00"), xmax = as.Date("2020-03-25 00:00:00"), min = 0, ymax = Inf, alpha = .2, fill = "dodgerblue") +
annotate("rect", xmin = as.Date("2020-03-25 00:00:00"), xmax = as.Date("2020-03-26 00:00:00"), min = 0, ymax = Inf, alpha = .2, fill = "seagreen4") +
theme_classic(base_size=10) +
labs(x = "Date",
y = "Google Search Intensity",
title = "Average Search Intensity Around Time of Complete Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_color_manual(values = c("palevioletred", "dodgerblue", "seagreen4", "black"), labels = c("23rd", "24th", "25th", "Control"), name = "Group") +
scale_x_date(date_breaks = "2 days",
date_labels = "%m-%d",
limits = as.Date(c("2020-03-10","2020-03-31")))
#This time, compare 3/23 complete enactments to states that hadn't enacted a complete closure by 3/31 (within 1 week).
##Set up data
policy_search_lf_filtered3 <- data_policy_states %>%
#Filter to treatment and control
mutate(complete_treatment = case_when(
complete == as.Date("2020-03-23") ~ "Treatment",
complete >= as.Date("2020-03-31") ~ "Control",
complete = is.na(complete) ~ "Control")) %>%
filter(!is.na(complete_treatment)) %>%
#Add in google search data
left_join(data_states_short, by = "location") %>%
#Filter out lots of pre-data
filter(date > as.Date("2020-03-10") ) %>%
#Merge in labor force data for weighting
left_join(labor_force_states, by = "state")
#Collapse hits by date by group, weighted by lf size, for control group
policy_search_lf_filtered3_c <- policy_search_lf_filtered3 %>%
filter(complete_treatment == "Control") %>%
mutate(location = "Control") %>%
group_by(date, location, complete_treatment) %>%
summarize_at("hits", list(weighted.mean), weight = "lf_022020")
#Merge collapsed control group data back in
policy_search_lf_filtered3 <- policy_search_lf_filtered3 %>%
filter(complete_treatment == "Treatment") %>%
subset(select = c("location", "hits", "date", "complete_treatment", "partial", "complete")) %>%
full_join(policy_search_lf_filtered3_c)
##Plot
my_blue = brewer.pal(n = 9, "Blues")[3:9]
ggplot() +
geom_line(data = policy_search_lf_filtered3 %>% filter(location == "Control"),
aes(x = date, y = hits, group = location, color = location), lwd=1.5) +
geom_line(data = policy_search_lf_filtered3,
aes(x = date, y = hits, group = location, color = location)) +
annotate("rect", xmin = as.Date("2020-03-22"), xmax = as.Date("2020-03-24"), min = 0, ymax = Inf, alpha = .1, fill = "black") +
geom_point(data = policy_search_lf_filtered3 %>% filter(date == partial & location != "Control"),
aes(x = partial, y = hits, group = location, color = location)) +
theme_classic(base_size=10) +
labs(x = "Date",
y = "Google Search Intensity",
title = "Search Intensity Around Time of Complete Closure",
subtitle = "Weighted by size of states' labor force in Feb. 2020") +
scale_colour_manual(values=c("black", my_blue), name = "State") +
scale_x_date(date_breaks = "2 days",
date_labels = "%m-%d",
limits = as.Date(c("2020-03-10","2020-03-31"))) +
labs(caption = "Note: Control group includes states that had not enacted a complete closure by 3/30. \nPoint indicates date when state enacted partial closure.") +
theme(plot.caption = element_text(hjust = 0, size = 9))
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###Plot one state with both policies as an example (add daily UI first)###
#Set these to whatever you want! note to liz: make this a function later
plotstate = "CA" #Change this to see another state
cares = as.Date("2020-03-27")
#Merge in daily UI data
policy_event_study_withdailyui <- right_join(daily_UI_Claims, policy_event_study, by = c("location", "date"))
policy_event_study_plotstate <- policy_event_study_withdailyui %>%
filter(location == plotstate)
#Plot daily trends data
dailygoogleplot_plotstate <- ggplot(data = policy_event_study_plotstate, aes(x=date, y=hits)) +
geom_line(,color = "darkgray") +
geom_vline(aes(xintercept = mean(partial), color = "Partial Closure"), show.guide = TRUE, alpha = .75, size = 1.5) +
geom_vline(aes(xintercept = mean(complete), color = "Complete Closure"), show.guide = TRUE, alpha = .75, size = 1.5) +
geom_vline(aes(xintercept = cares, color = "CARES Act"), show.guide = TRUE, alpha = .75, size = 1.5) +
scale_color_manual(name = "Policies", values = c("Partial Closure" = "cadetblue3", "Complete Closure" = "mediumpurple2", "CARES Act" = "palegreen4")) +
theme_classic(base_size=10) +
theme(legend.position = "bottom") +
labs(x = "Time",
y = "Google Search Trends",
title = paste("Google Search Trends Over Time in", plotstate))
#Plot daily UI claims with policies (this is pretty useless right now, because we don't have enough daily data)
dailyuiplot_plotstate <- ggplot(data = policy_event_study_plotstate, aes(x=date, y=ui_claims_daily)) +
geom_line(,color = "darkgray") +
geom_vline(aes(xintercept = mean(partial), color = "Partial Closure"), show.guide = TRUE, alpha = .75, size = 1.5) +
geom_vline(aes(xintercept = mean(complete), color = "Complete Closure"), show.guide = TRUE, alpha = .75, size = 1.5) +
geom_vline(aes(xintercept = cares, color = "CARES Act"), show.guide = TRUE, alpha = .75, size = 1.5) +
scale_color_manual(name = "Policies", values = c("Partial Closure" = "cadetblue3", "Complete Closure" = "mediumpurple2", "CARES Act" = "palegreen4")) +
theme_classic(base_size=10) +
theme(legend.position = "bottom") +
labs(x = "Time",
y = "Daily UI Claims",
title = paste("Daily UI Claims Over Time in", plotstate))
dailygoogleplot_plotstate
dailyuiplot_plotstate
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
###Map pct change in unemployment claims pre-covid to during-covid###
#Set up data
##First bring in weekly claims data prior to COVID
weekly_UI_janthrumarch = as.data.frame(read_xlsx("data/UI_claims_jan1thrumarch21.xlsx")) %>%
rename("state" = "State") %>%
rename("week" = "Filed week ended") %>%
rename("claims" = "Initial Claims") %>%
mutate_at("week", funs(ymd)) %>%
mutate(week = epiweek(week)) %>%
subset(select = c("state", "week", "claims")) %>%
left_join(data_policy_states[, c("state", "location")], by = "state")
##Clean data from week ending March 28 (4/2/20 news release) !! Will need to update weekly with new data pull
week13ui <- subset(UI_Claims_March28_True, select = c("location", "advance_0322")) %>%
mutate(week = 13) %>%
rename("claims" = "advance_0322") %>%
left_join(data_policy_states[, c("state", "location")], by = "location")
##Merge together to get all weekly UI data available
weekly_UI_janthrumarch <- rbind(weekly_UI_janthrumarch, week13ui, by = "location")
##Merge with policy data at week-level
weekly_claims_policy <- left_join(weekly_UI_janthrumarch, data_policy_states[, c("partial_week", "complete_week", "location")], by = "location")
##Filter out data before mid-Feb
weekly_claims_policy <- weekly_claims_policy %>%
group_by(location) %>%
mutate(week = as.numeric(week)) %>%
arrange(location ,week) %>%
mutate(claims = as.numeric(claims)) %>%
filter(week >= 8) %>%
filter(!is.na(location))
##Reshape to wide
weekly_claims_policy_wide <- weekly_claims_policy %>%
spread(week, claims) %>%
rename("week13" = "13") %>%
rename("week12" = "12") %>%
rename("week11" = "11") %>%
rename("week10" = "10") %>%
rename("week9" = "9") %>%
rename("week8" = "8")
#Replace OR data manually (Oregon DOL economist asked me to run this map with updated data, commenting out)
#weekly_claims_policy_wide2[38, "week13"] <- 92700
#weekly_claims_policy_wide2[38, "week12"] <- 76500
#weekly_claims_policy_wide2[38, "week11"] <- 4900
## Generate percent change in claims (3 week moving average)
weekly_claims_policy_wide <- weekly_claims_policy_wide %>%
mutate(claims_postcovid = as.numeric(week11)+as.numeric(week12)+as.numeric(week13)) %>%
mutate(claims_precovid = as.numeric(week10)+as.numeric(week9)+as.numeric(week8)) %>%
mutate(claims_pchg = 100*((claims_postcovid - claims_precovid)/claims_precovid)) %>%
mutate(region = tolower(state))
##Set up shape files
states <- map_data("state")
claims_chg_map_data <- left_join(states, weekly_claims_policy_wide, by = "region")
#Do some stuff to get pattern overlaid on map for complete closures by 3/2
nonessential_closure_states <- data_policy_states %>%
filter(!is.na(complete)) %>%
filter(complete <= "2020-03-28") %>%
mutate(region = tolower(state)) %>%
subset(select = region)
nonessential_closure_states <- as.data.frame(nonessential_closure_states)
source("https://raw.githubusercontent.com/imaddowzimet/drawcrosshatch/master/draw_crosshatch.R")
claims_chg_map_data_completeclose <- claims_chg_map_data %>%
filter(region %in% nonessential_closure_states$region) %>%
group_by(group) %>%
nest()
lines <- map_df(claims_chg_map_data_completeclose$data, draw.crosshatch, width = .3, pattern= "horizontal")
#Make map
ui_pctchg_map <- ggplot(claims_chg_map_data, aes(long, lat, group = group)) +
geom_polygon(aes(fill = claims_pchg), color = "white") +
geom_segment(data=lines, aes(x= x, y = y , xend = xend, yend = yend),
inherit.aes = F, color = "white", alpha = .6) +
labs(title="Percent Change in Initial UI Claims",
subtitle = "Between 2/16-3/7 to 3/8-3/28") +
scale_fill_gradient2(
high = "orangered3", na.value = "gray50",
breaks = c(round(min(claims_chg_map_data$claims_pchg)),
round(max(claims_chg_map_data$claims_pchg)))) +
labs(caption = "Note: States with lines adopted a non-essential business closure order by 3/28.") +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
rect = element_blank(),
axis.title.y=element_blank(),
axis.title.x=element_blank(),
legend.title=element_blank(),
legend.position = "bottom",
plot.title = element_text(hjust = 0.5, size = 18),
plot.subtitle = element_text(hjust = 0.5, size = 14),
plot.caption = element_text(hjust = 0.5, size = 12))
ui_pctchg_map
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
#This all kind of ends up being useless-- should play around with more
#Now look at weekly search trends and UI data by week of policy adoption
#There's really nothing interesting here. A few late-adopting states seem to have big increases in week 13, but I think this is more to do with technology issues (so claims were late).
#ggplot(subset(weekly_claims_policy, complete_week == 13), aes(x = week, y = claims_pchg, color = state)) + geom_path()
#ggplot(subset(weekly_claims_policy, complete_week == 12), aes(x = week, y = claims_pchg, color = state)) + geom_path()
#ggplot(subset(weekly_claims_policy, partial_week == 12), aes(x = week, y = claims_pchg, color = state)) + geom_path()
#ggplot(subset(weekly_claims_policy, partial_week == 13), aes(x = week, y = claims_pchg, color = state)) + geom_path()
#ggplot(weekly_claims_policy, aes(x = week, y = claims_pchg, color = partial_week)) + geom_path()
```