-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_analysis.R
576 lines (506 loc) · 31.2 KB
/
02_analysis.R
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
#### BRIEF 1 ####
### TOTAL POP & GROUP QUARTERS ###
## old data
hhGq_parish_old <- read_csv("inputs/census2020briefs_data_HHsize_GQ - parish.csv")
stJ_hhGc_10Raw <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = c("P042001","P042002","P042003","P042004","P042005","P042006","P042007","P042008","P042009","P042010"),
year = 2010)
stJ_hhGc_10 <- stJ_hhGc_10Raw %>%
select(variable, value) %>%
pivot_wider(names_from = variable, values_from = value)%>%
rename(`Total group quarters population` =P042001,
`Total institutional`= P042002,
`Adult correctional\nfacilties`=P042003,
`Juvenile \nfacilities`= P042004,
`Nursing \nfacilities`= P042005,
`Other institutional`= P042006,
`Total noninstitutional` = P042007,
`College/\nuniversity student housing` = P042008,
`Military\nquarters`=P042009,
`Other noninstitutional` = P042010)
stJ_hhGq_10PO <- pl_parish_2010 %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, P0010001, H0010002, contains("P005")) %>%
rename(Population = P0010001,
`Occupied \nunits` = H0010002) %>%
# mutate_all(as.character) %>%
mutate(Year = 2010) %>%
filter(Parish == "St. James")
stJ_hhGq_10All <- bind_cols(stJ_hhGq_10PO, stJ_hhGc_10) %>%
mutate(`Average household size` = round(((Population - `Total group quarters population`) / `Occupied \nunits`),
digits = 2))
hhGq_metro2010 <- hhGq_parish_old %>%
filter(Year == 2010,
Parish != "New Orleans Metro Total") %>%
mutate_at(c(3:15), as.numeric)%>%
bind_rows(stJ_hhGq_10All %>% mutate_at(c(3:16), as.numeric)) %>%
summarise(Parish = "New Orleans Metro Total",
Population= sum(Population, na.rm = TRUE),
`Occupied \nunits` = sum(`Occupied \nunits`, na.rm = TRUE),
`Total group quarters population` = sum(`Total group quarters population`, na.rm = TRUE),
`Total institutional` = sum(`Total institutional`, na.rm = TRUE),
`Adult correctional\nfacilties` = sum(`Adult correctional\nfacilties`, na.rm = TRUE),
`Juvenile \nfacilities` = sum(`Juvenile \nfacilities`, na.rm = TRUE),
`Nursing \nfacilities` = sum(`Nursing \nfacilities`, na.rm = TRUE),
`Other institutional` = sum(`Other institutional`, na.rm = TRUE),
`Total noninstitutional` = sum(`Total noninstitutional`, na.rm = TRUE),
`College/\nuniversity student housing` = sum(`College/\nuniversity student housing`, na.rm = TRUE),
`Military\nquarters` = sum(`Military\nquarters`, na.rm = TRUE),
`Other noninstitutional` = sum(`Other noninstitutional`, na.rm = TRUE))%>%
mutate(Year = 2010,
`Average household size` = round(((Population - `Total group quarters population`) / `Occupied \nunits`),
digits = 2))
### tab1_parish
hhGq_parish2020 <- pl_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, P0010001, H0010002, contains("P005")) %>%
rename(Population = P0010001,
`Occupied \nunits` = H0010002,
`Total group quarters population` =P0050001,
`Total institutional`= P0050002,
`Adult correctional\nfacilties`=P0050003,
`Juvenile \nfacilities`= P0050004,
`Nursing \nfacilities`= P0050005,
`Other institutional`= P0050006,
`Total noninstitutional` = P0050007,
`College/\nuniversity student housing` = P0050008,
`Military\nquarters`=P0050009,
`Other noninstitutional` = P0050010) %>%
# mutate_all(as.character) %>%
mutate(Year = 2020,
`Average household size` = round(((Population - `Total group quarters population`) / `Occupied \nunits`),
digits = 2))
hhGq_metro2020 <- hhGq_parish2020 %>%
summarise(Parish = "New Orleans Metro Total",
Population= sum(Population),
`Occupied \nunits` = sum(`Occupied \nunits`),
`Total group quarters population` = sum(`Total group quarters population`),
`Total institutional` = sum(`Total institutional`),
`Adult correctional\nfacilties` = sum(`Adult correctional\nfacilties`),
`Juvenile \nfacilities` = sum(`Juvenile \nfacilities`),
`Nursing \nfacilities` = sum(`Nursing \nfacilities`),
`Other institutional` = sum(`Other institutional`),
`Total noninstitutional` = sum(`Total noninstitutional`),
`College/\nuniversity student housing` = sum(`College/\nuniversity student housing`),
`Military\nquarters` = sum(`Military\nquarters`),
`Other noninstitutional` = sum(`Other noninstitutional`))%>%
mutate(Year = 2020,
`Average household size` = round(((Population - `Total group quarters population`) / `Occupied \nunits`),
digits = 2))
hhGq_parish_updated <- bind_rows((mutate_all(hhGq_parish_old, as.character) %>% filter(Parish != "New Orleans Metro Total")),
mutate_all(stJ_hhGq_10All, as.character),
mutate_all(hhGq_metro2010, as.character),
mutate_all(hhGq_parish2020, as.character),
mutate_all(hhGq_metro2020, as.character)) %>%
select(-GEOID) %>%
filter(Year %in% c("2010", "2020"))
# write_csv(hhGq_parish_updated,"outputs/hhGq_parish_updated.csv")
### tab2_nbhd
hhGq_nbhd2020 <- pl_tract %>%
filter(COUNTY == "071") %>%
right_join(NOLAcrosswalk2020, by = c("TRACT" = "tract")) %>%
select(geo, P0010001, H0010002, contains("P005")) %>%
rename(Neighborhood = geo,
Population = P0010001,
`Occupied \nunits` = H0010002,
`Total group quarters population` =P0050001,
`Total institutional`= P0050002,
`Adult correctional\nfacilties`=P0050003,
`Juvenile \nfacilities`= P0050004,
`Nursing \nfacilities`= P0050005,
`Other institutional`= P0050006,
`Total noninstitutional` = P0050007,
`College/\nuniversity student housing` = P0050008,
`Military\nquarters`=P0050009,
`Other noninstitutional` = P0050010) %>%
group_by(Neighborhood) %>%
summarise(Population= sum(Population),
`Occupied \nunits` = sum(`Occupied \nunits`),
`Total group quarters population` = sum(`Total group quarters population`),
`Total institutional` = sum(`Total institutional`),
`Adult correctional\nfacilties` = sum(`Adult correctional\nfacilties`),
`Juvenile \nfacilities` = sum(`Juvenile \nfacilities`),
`Nursing \nfacilities` = sum(`Nursing \nfacilities`),
`Other institutional` = sum(`Other institutional`),
`Total noninstitutional` = sum(`Total noninstitutional`),
`College/\nuniversity student housing` = sum(`College/\nuniversity student housing`),
`Military\nquarters` = sum(`Military\nquarters`),
`Other noninstitutional` = sum(`Other noninstitutional`)) %>%
mutate(`Average household size` = round(((Population - `Total group quarters population`) / `Occupied \nunits`),
digits = 2)) %>%
adorn_totals("row")
# write_csv(hhGq_nbhd2020,"outputs/hhGq_nbhd_updated.csv")
hhGq_bg <- pl_bg %>%
filter(COUNTY == "071") %>%
select(GEOID, P0010001, H0010002, contains("P005")) %>%
rename(Population = P0010001,
`Occupied \nunits` = H0010002,
`Total group quarters population` =P0050001,
`Total institutional`= P0050002,
`Adult correctional\nfacilties`=P0050003,
`Juvenile \nfacilities`= P0050004,
`Nursing \nfacilities`= P0050005,
`Other institutional`= P0050006,
`Total noninstitutional` = P0050007,
`College/\nuniversity student housing` = P0050008,
`Military\nquarters`=P0050009,
`Other noninstitutional` = P0050010)
#### BRIEF 2 ###
## children in neighborhoods ##
### old data
nbhdChildren_pop_old <- read_csv("inputs/census2020briefs_nbhdChildren - population.csv") %>%
mutate(Neighborhood = gsub(pattern = "[*]", replacement = "", x = Neighborhood))%>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood))
nbhdChildren_chil_old <- read_csv("inputs/census2020briefs_nbhdChildren - children.csv") %>%
mutate(Neighborhood = gsub(pattern = "[*]", replacement = "", x = Neighborhood))%>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood))
nbhdChildren_adu_old <- read_csv("inputs/census2020briefs_nbhdChildren - adults.csv") %>%
mutate(Neighborhood = gsub(pattern = "[*]", replacement = "", x = Neighborhood))%>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood))
### tab 1 - population
nbhdChildren_pop2020 <- pl_tract %>%
filter(COUNTY == "071") %>%
right_join(NOLAcrosswalk2020, by = c("TRACT" = "tract")) %>%
select(Neighborhood = geo, P0010001, AREALAND) %>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood)) %>%
group_by(Neighborhood) %>%
summarise(`Population, 2020` = sum(P0010001), areaTot = sum(AREALAND)/ 2589988) %>%
mutate(popTot = sum(`Population, 2020`),
`Share of total, 2020` = percent(`Population, 2020`/popTot, accuracy = .01)) %>%
adorn_totals("row")%>%
mutate(`Density per sq mi of developed land, 2020` =
round(`Population, 2020`/areaTot, digits = 0)) %>%
select(-areaTot, -popTot)
nbhdChildren_pop_updated <- inner_join(nbhdChildren_pop_old, nbhdChildren_pop2020) %>%
mutate(`Total change, 2010-20` = `Population, 2020` - `Population, 2010`,
`Percent change, 2010-20` = (`Population, 2020` - `Population, 2010`)/`Population, 2010`)
pop2020 <- nbhdChildren_pop_updated %>% select(`Population, 2020`)
# write_csv(nbhdChildren_pop_updated,"outputs/nbhdChildren_pop_updated.csv")
### tab 3 - adults
nbhdChildren_adu2020 <- pl_tract %>%
filter(COUNTY == "071") %>%
right_join(NOLAcrosswalk2020, by = c("TRACT" = "tract")) %>%
select(Neighborhood = geo, P0030001, AREALAND)%>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood)) %>%
group_by(Neighborhood) %>%
summarise(`Adults, 2020` = sum(P0030001), areaTot = sum(AREALAND)/ 2589988) %>%
mutate(popTot = sum(`Adults, 2020`),
`Share of total, 2020` = percent(`Adults, 2020`/popTot, accuracy = .01)) %>%
adorn_totals("row")%>%
mutate(`Density per sq mi of developed land, 2020` =
round(`Adults, 2020`/areaTot, digits = 0)) %>%
select(-areaTot, -popTot)
nbhdChildren_adu_updated <- full_join(nbhdChildren_adu_old, nbhdChildren_adu2020) %>%
mutate(`Total change, 2010-20` = `Adults, 2020` - `Adults, 2010`,
`Percent change, 2010-20` = percent((`Adults, 2020` - `Adults, 2010`)/`Adults, 2010`),
`Percent Adults, 2020` = percent(`Adults, 2020`/ pop2020$`Population, 2020`))
# write_csv(nbhdChildren_adu_updated,"outputs/nbhdChildren_adu_updated.csv")
### tab 2 - children
nbhdChildren_adu2020.inclAreaTot <-pl_tract %>%
filter(COUNTY == "071") %>%
right_join(NOLAcrosswalk2020, by = c("TRACT" = "tract")) %>%
select(Neighborhood = geo, P0030001, AREALAND)%>%
mutate(Neighborhood = ifelse(grepl("Cath", Neighborhood), "Lake Catherine/Village de L'est", Neighborhood),
Neighborhood = ifelse(grepl("Lakesh", Neighborhood), "Lakeshore/Lake Vista", Neighborhood),
Neighborhood = ifelse(grepl("Marl", Neighborhood), "Marlyville/Fontainebleau", Neighborhood),
Neighborhood = ifelse(grepl("New A", Neighborhood), "New Aurora/English Turn", Neighborhood),
Neighborhood = ifelse(grepl("Tall", Neighborhood), "Tall Timbers/Brechtel", Neighborhood),
Neighborhood = ifelse(grepl("Viav", Neighborhood), "Viavant/Venetian Isles", Neighborhood)) %>%
group_by(Neighborhood) %>%
summarise(`Adults, 2020` = sum(P0030001), areaTot = sum(AREALAND)/ 2589988) %>%
mutate(popTot = sum(`Adults, 2020`),
`Share of total, 2020` = percent(`Adults, 2020`/popTot, accuracy = .01)) %>%
adorn_totals("row")%>%
mutate(`Density per sq mi of developed land, 2020` =
round(`Adults, 2020`/areaTot, digits = 0))
nbhdChildren_chil2020 <- left_join(nbhdChildren_pop2020, nbhdChildren_adu2020.inclAreaTot, by = "Neighborhood") %>%
transmute(Neighborhood = Neighborhood,
`Children, 2020` = `Population, 2020` - `Adults, 2020`,
areaTot = areaTot) %>%
mutate(`Density per sq mi of developed land, 2020` = round(`Children, 2020`/areaTot, digits = 0),
popTot = sum(`Children, 2020`)) %>%
mutate(`Share of total, 2020` = percent(`Children, 2020`/popTot, accuracy = .01)) %>%
select(-areaTot, -popTot)
nbhdChildren_chil_updated <- left_join(nbhdChildren_chil_old, nbhdChildren_chil2020) %>%
mutate(`Total change, 2010-20` = `Children, 2020` - `Children, 2010`,
`Percent change, 2010-20` = percent((`Children, 2020` - `Children, 2010`)/`Children, 2010`),
`Percent Children, 2020` = percent(`Children, 2020`/ pop2020$`Population, 2020`))
# write_csv(nbhdChildren_chil_updated,"outputs/nbhdChildren_chil_updated.csv")
### BRIEF 3 ###
## population & race
metro_pop_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - pop.csv")
metro_black_nh_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - black_nh.csv")%>%
rename(Parish = Parishes)
metro_white_nh_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - white_nh.csv")%>%
rename(Parish = Parishes)
metro_other_nh_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - other_nh.csv")%>%
rename(Parish = Parishes)
metro_api_nh_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - api_nh.csv")%>%
rename(Parish = Parishes)
metro_hisp_old <- read_csv("inputs/census2020briefs_popHousRaceMetro - hisp.csv")%>%
rename(Parish = Parishes)
metro_pop <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, pop)%>%
adorn_totals()%>%
mutate(Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
###pop
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = "P001001",
year = 2010)
metro_pop_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, Population = pop) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_pop_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_pop_updated <- bind_rows(mutate_all(metro_pop_old, as.character),
mutate_all(metro_pop_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_Population` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_Population`)) %>%
mutate(tot = totRace$Population) %>%
mutate(`2020_Share of total` = as.numeric(`2020_Population`)/tot,
`2020_Total change from previous decade` = as.numeric(`2020_Population`) - as.numeric(`2010_Population`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Population`)) %>%
select(-tot) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_pop_updated, "outputs/metro_pop_updated.csv")
###black
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = "P005004",
year = 2010)
metro_black_nh_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, `Black or African American Alone, Not Hispanic` = pop_black) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_black_nh_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_black_nh_updated <- bind_rows(mutate_all(metro_black_nh_old, as.character),
mutate_all(metro_black_nh_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_Black or African American Alone, Not Hispanic` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_Black or African American Alone, Not Hispanic`)) %>%
mutate(tot = totRace$`Black or African American Alone, Not Hispanic`) %>%
left_join(metro_pop, by = "Parish") %>%
mutate(`2020_Share of total` = as.numeric(`2020_Black or African American Alone, Not Hispanic`)/tot,
`2020_Percent Black or African American Alone, Not Hispanic` = as.numeric(`2020_Black or African American Alone, Not Hispanic`)/pop,
`2020_Total change from previous decade` = as.numeric(`2020_Black or African American Alone, Not Hispanic`) - as.numeric(`2010_Black or African American Alone, Not Hispanic`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Black or African American Alone, Not Hispanic`)) %>%
select(-tot, -pop, -GEOID) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6, )) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_black_nh_updated, "outputs/metro_black_nh_updated.csv")
###white
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = "P005003")
metro_white_nh_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, `White Alone, Not Hispanic` = pop_white) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_white_nh_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_white_nh_updated <- bind_rows(mutate_all(metro_white_nh_old, as.character),
mutate_all(metro_white_nh_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_White Alone, Not Hispanic` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_White Alone, Not Hispanic`)) %>%
mutate(tot = totRace$`White Alone, Not Hispanic`) %>%
left_join(metro_pop, by = "Parish") %>%
mutate(`2020_Share of total` = as.numeric(`2020_White Alone, Not Hispanic`)/tot,
`2020_Percent White Alone, Not Hispanic` = as.numeric(`2020_White Alone, Not Hispanic`)/pop,
`2020_Total change from previous decade` = as.numeric(`2020_White Alone, Not Hispanic`) - as.numeric(`2010_White Alone, Not Hispanic`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_White Alone, Not Hispanic`)) %>%
select(-tot, -pop, -GEOID) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_white_nh_updated, "outputs/metro_white_nh_updated.csv")
###api
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = c("P005006", "P005007")) %>%
summarise(value = sum(value))
metro_api_nh_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, pop_nhpi, pop_asian) %>%
mutate(`Asian or Pacific Islander, Not Hispanic` = pop_nhpi + pop_asian) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_api_nh_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_api_nh_updated <- bind_rows(mutate_all(metro_api_nh_old, as.character),
mutate_all(metro_api_nh_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_Asian or Pacific Islander, Not Hispanic` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_Asian or Pacific Islander, Not Hispanic`)) %>%
mutate(tot = totRace$`Asian or Pacific Islander, Not Hispanic`) %>%
left_join(metro_pop, by = "Parish") %>%
mutate(`2020_Share of total` = as.numeric(`2020_Asian or Pacific Islander, Not Hispanic`)/tot,
`2020_Percent Asian or Pacific Islander, Not Hispanic` = as.numeric(`2020_Asian or Pacific Islander, Not Hispanic`)/pop,
`2020_Total change from previous decade` = as.numeric(`2020_Asian or Pacific Islander, Not Hispanic`) - as.numeric(`2010_Asian or Pacific Islander, Not Hispanic`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Asian or Pacific Islander, Not Hispanic`)) %>%
select(-tot, -pop, -GEOID) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_api_nh_updated, "outputs/metro_api_nh_updated.csv")
###other
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = c("P005005", "P005008", "P005009")) %>%
summarise(value = sum(value))
metro_other_nh_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, pop_other, pop_aian, pop_two) %>%
mutate(`Other, Not Hispanic` = pop_other + pop_aian + pop_two) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_other_nh_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_other_nh_updated <- bind_rows(mutate_all(metro_other_nh_old, as.character),
mutate_all(metro_other_nh_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_Other, Not Hispanic` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_Other, Not Hispanic`)) %>%
mutate(tot = totRace$`Other, Not Hispanic`) %>%
left_join(metro_pop, by = "Parish") %>%
mutate(`2020_Share of total` = as.numeric(`2020_Other, Not Hispanic`)/tot,
`2020_Percent Other, Not Hispanic` = as.numeric(`2020_Other, Not Hispanic`)/pop,
`2020_Total change from previous decade` = as.numeric(`2020_Other, Not Hispanic`) - as.numeric(`2010_Other, Not Hispanic`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Other, Not Hispanic`)) %>%
select(-tot, -pop, -GEOID) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_other_nh_updated, "outputs/metro_other_nh_updated.csv")
###hisp
stJ_racePop <- get_decennial(geography = "county",
state = "LA",
county = "093",
variables = "P004003")
metro_hisp_2020 <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(GEOID, Parish, `Hispanic (Any Race)` = pop_hisp) %>%
adorn_totals() %>%
select(-GEOID) %>%
mutate(Year = "2020",
Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish))
totRace <- metro_hisp_2020 %>%
filter(Parish == "New Orleans Metro Total")
metro_hisp_updated <- bind_rows(mutate_all(metro_hisp_old, as.character),
mutate_all(metro_hisp_2020, as.character)) %>%
pivot_longer(!c(Parish, Year), names_to = "vars", values_to = "vals") %>%
pivot_wider(names_from = c(Year, vars), values_from = vals) %>%
mutate(`2010_Hispanic (Any Race)` = ifelse(Parish == "St. James", stJ_racePop$value, `2010_Hispanic (Any Race)`)) %>%
mutate(tot = totRace$`Hispanic (Any Race)`) %>%
left_join(metro_pop, by = "Parish") %>%
mutate(`2020_Share of total` = as.numeric(`2020_Hispanic (Any Race)`)/tot,
`2020_Percent Hispanic (Any Race)` = as.numeric(`2020_Hispanic (Any Race)`)/pop,
`2020_Total change from previous decade` = as.numeric(`2020_Hispanic (Any Race)`) - as.numeric(`2010_Hispanic (Any Race)`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Hispanic (Any Race)`)) %>%
select(-tot, -pop, -GEOID) %>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(metro_hisp_updated, "outputs/metro_hisp_updated.csv")
###two or more
pop2010 <- metro_pop_updated %>%
filter(Year == 2010) %>%
select(Parish, Population)
two_nh_2010_raw <- get_decennial(geography = "county",
state = "LA",
county = c("051", "071", "075", "087", "089", "093", "095", "103") ,
variables = "P005009") %>%
transmute(Parish = str_sub(NAME, 1, -19),
`2010_Two or More Races, Not Hispanic` = value) %>%
adorn_totals() %>%
mutate(Parish = ifelse(Parish =="Total", "New Orleans Metro Total", Parish))
totRace <- two_nh_2010_raw %>%
filter(Parish == "New Orleans Metro Total")
two_nh_2010 <- two_nh_2010_raw %>%
left_join(pop2010, by = "Parish") %>%
mutate(tot = totRace$`2010_Two or More Races, Not Hispanic`) %>%
mutate(Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish),
`2010_Share of total` = as.numeric(`2010_Two or More Races, Not Hispanic`)/tot,
`2010_Percent Two or More Races, Not Hispanic` = as.numeric(`2010_Two or More Races, Not Hispanic`)/as.numeric(Population)) %>%
select(-tot)
two_nh_2020_raw <- pl_std_parish %>%
right_join(parish_xwalk, by = "GEOID") %>%
select(Parish, `2020_Two or More Races, Not Hispanic` = pop_two) %>%
adorn_totals() %>%
mutate(Parish = ifelse(Parish =="Total", "New Orleans Metro Total", Parish))
totRace <- two_nh_2020_raw %>%
filter(Parish == "New Orleans Metro Total")
two_nh_2020 <- two_nh_2020_raw %>%
mutate(tot = totRace$`2020_Two or More Races, Not Hispanic`) %>%
mutate(Parish = ifelse(Parish =="-", "New Orleans Metro Total", Parish),
`2020_Share of total` = as.numeric(`2020_Two or More Races, Not Hispanic`)/tot,
`2020_Percent Two or More Races, Not Hispanic` = as.numeric(`2020_Two or More Races, Not Hispanic`)/metro_pop$pop) %>%
select(-tot)
two_nh_updated <- left_join(two_nh_2010, two_nh_2020, by = "Parish") %>%
select(-Population) %>%
mutate(`2020_Total change from previous decade` = as.numeric(`2020_Two or More Races, Not Hispanic`) - as.numeric(`2010_Two or More Races, Not Hispanic`),
`2020_Percent change from previous decade` = `2020_Total change from previous decade`/as.numeric(`2010_Two or More Races, Not Hispanic`))%>%
mutate_all(as.character) %>%
pivot_longer(!c(Parish), names_to = "vars", values_to = "vals") %>%
mutate(Year = str_sub(vars,1,4), vars = str_sub(vars, 6,)) %>%
pivot_wider(names_from = vars, values_from = vals)
# write_csv(two_nh_updated, "outputs/metro_two_nh_2020.csv")