/
aian_2_history_month_region.Rmd
629 lines (366 loc) · 15.6 KB
/
aian_2_history_month_region.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
623
624
625
626
627
628
629
---
title: "Womens History Month ACS/PUMS Data"
author: "suzanne"
date: "3/2022"
output: html_document
editor_options:
markdown:
wrap: 72
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Notes for Asian American Pacific Islander month
```{r load_libraries}
library(devtools)
library(sf)
library(dplyr)
library(psrccensus)
library(ggplot2)
library(tidycensus)
library(tidyr)
Sys.getenv("CENSUS_API_KEY")
```
```{r}
acs_5_vars<-load_variables(2020, 'acs5', cache=TRUE)
```
B01002D_001 Median Age
B02015 specific origins
B03002 Hispanic
B08105 Mode to Work
B10051 Grandparents
B17001 Poverty
C15002 Education
B16005 English proficiency
RAC1P
RAC2P
RAC3P detailed race in combination
RACASN- alone or in combination
HINCP
HUGCL
HUPAC
### Educational Attainment
compare 2020 and 2019 5 year
```{r}
Asian_df <- get_acs_recs(geography = 'county',
table.names = c('C15002D'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
PI_df <- get_acs_recs(geography = 'county',
table.names = c('C15002E'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
white_df <- get_acs_recs(geography = 'county',
table.names = c('C15002H'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
Asian_PI_df<-merge(Asian_df, PI_df, by='label')
Asian_PI_white_df<-merge(Asian_PI_df, white_df, by='label')
Asian_PI_white_df_formatted<-Asian_PI_white_df %>% select(label,estimate.x, moe.x, estimate.y, moe.y, estimate.y, moe.y, estimate, moe) %>% rename(Asian_Educational_Attainment=estimate.x, Asian_Educational_Attainment_MOE=moe.x, Pacific_Islander_Educational_Attainment=estimate.y, Pacific_Islander_Educational_Attainment_MOE=moe.y, White_Educational_Attainment=estimate, White_Educational_Attainment_MOE=moe)
write.table(Asian_PI_white_df_formatted,"clipboard", sep='\t', row.names=FALSE )
Asian_PI_white_df_formatted
```
```{r}
Asian_df <- get_acs_recs(geography = 'county',
table.names = c('C15002D'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
PI_df <- get_acs_recs(geography = 'county',
table.names = c('C15002E'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_df <- get_acs_recs(geography = 'county',
table.names = c('C15002H'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
Asian_PI_df<-merge(Asian_df, PI_df, by='label')
Asian_PI_white_df<-merge(Asian_PI_df, white_df, by='label')
Asian_PI_white_df_formatted<-Asian_PI_white_df %>% select(label,estimate.x, moe.x, estimate.y, moe.y, estimate.y, moe.y, estimate, moe) %>% rename(Asian_Educational_Attainment=estimate.x, Asian_Educational_Attainment_MOE=moe.x, Pacific_Islander_Educational_Attainment=estimate.y, Pacific_Islander_Educational_Attainment_MOE=moe.y, White_Educational_Attainment=estimate, White_Educational_Attainment_MOE=moe)
write.table(Asian_PI_white_df_formatted,"clipboard", sep='\t', row.names=FALSE )
Asian_PI_white_df_formatted
```
by county
```{r}
Asian_df <- get_acs_recs(geography = 'county',
table.names = c('C15002D'),
years=c(2020),
acs.type = 'acs5')
PI_df <- get_acs_recs(geography = 'county',
table.names = c('C15002E'),
years=c(2020),
acs.type = 'acs5')
white_df <- get_acs_recs(geography = 'county',
table.names = c('C15002H'),
years=c(2020),
acs.type = 'acs5')
Asian_PI_df<-merge(Asian_df, PI_df, by=c('label', 'name'))
Asian_PI_white_df<-merge(Asian_PI_df, white_df, by=c('label', 'name'))
Asian_PI_white_df_formatted<-Asian_PI_white_df %>% select(name,label,estimate.x, moe.x, estimate.y, moe.y, estimate.y, moe.y, estimate, moe) %>% rename(Asian_Educational_Attainment=estimate.x, Asian_Educational_Attainment_MOE=moe.x, Pacific_Islander_Educational_Attainment=estimate.y, Pacific_Islander_Educational_Attainment_MOE=moe.y, White_Educational_Attainment=estimate, White_Educational_Attainment_MOE=moe)
write.table(Asian_PI_white_df_formatted,"clipboard", sep='\t', row.names=FALSE )
Asian_PI_white_df_formatted
### Where were people born?
```
2020
```{r}
nativity_df_Asian<- get_acs_recs(geography = 'county',
table.names = c('B06004D'),
years=c(2020),
acs.type = 'acs5')
nativity_df_Asian_formatted<-nativity_df_Asian
nativity_df_Asian_formatted
write.table(nativity_df_Asian_formatted,"clipboard", sep='\t', row.names=FALSE )
```
2019
```{r}
nativity_df_Asian<- get_acs_recs(geography = 'county',
table.names = c('B06004D'),
years=c(2019),
acs.type = 'acs5')
nativity_df_Asian_formatted<-nativity_df_Asian
nativity_df_Asian_formatted
write.table(nativity_df_Asian_formatted,"clipboard", sep='\t', row.names=FALSE )
```
```{r}
nativity_df_PI<- get_acs_recs(geography = 'county',
table.names = c('B06004E'),
years=c(2020),
acs.type = 'acs5')
nativity_df_PI_formatted<-nativity_df_PI
nativity_df_PI_formatted
write.table(nativity_df_PI_formatted,"clipboard", sep='\t', row.names=FALSE )
```
```{r}
nativity_df_PI<- get_acs_recs(geography = 'county',
table.names = c('B06004E'),
years=c(2019),
acs.type = 'acs5')
nativity_df_PI_formatted<-nativity_df_PI
nativity_df_PI_formatted
write.table(nativity_df_PI_formatted,"clipboard", sep='\t', row.names=FALSE )
```
### Median Income
B19013D
```{r}
Asian_df <- get_acs_recs(geography = 'county',
table.names = c('B19013D'),
years=c(2020),
acs.type = 'acs5')
PI_df <- get_acs_recs(geography = 'county',
table.names = c('B19013E'),
years=c(2020),
acs.type = 'acs5')
white_df <- get_acs_recs(geography = 'county',
table.names = c('B19013H'),
years=c(2020),
acs.type = 'acs5')
Asian_PI_df<-merge(Asian_df, PI_df, by=c('label', 'name'))
Asian_PI_white_df<-merge(Asian_PI_df, white_df, by=c('label', 'name'))
Asian_PI_white_df_formatted<-Asian_PI_white_df %>% select(label,name, estimate.x, moe.x, estimate.y, moe.y, estimate.y, moe.y, estimate, moe) %>% rename(Asian_Educational_Attainment=estimate.x, Asian_Median_Income_MOE=moe.x, Pacific_Islander_Median_Income=estimate.y, Pacific_Islander_Median_Income_MOE=moe.y, White_Median_Income=estimate, White_Median_Income_MOE=moe)
write.table(Asian_PI_white_df_formatted,"clipboard", sep='\t', row.names=FALSE )
Asian_PI_white_df_formatted
```
### Median Income
B19013D
2019
```{r}
Asian_df <- get_acs_recs(geography = 'county',
table.names = c('B19013D'),
years=c(2019),
acs.type = 'acs5')
PI_df <- get_acs_recs(geography = 'county',
table.names = c('B19013E'),
years=c(2019),
acs.type = 'acs5')
white_df <- get_acs_recs(geography = 'county',
table.names = c('B19013H'),
years=c(2019),
acs.type = 'acs5')
Asian_PI_df<-merge(Asian_df, PI_df, by=c('label', 'name'))
Asian_PI_white_df<-merge(Asian_PI_df, white_df, by=c('label', 'name'))
Asian_PI_white_df_formatted<-Asian_PI_white_df %>% select(label,name, estimate.x, moe.x, estimate.y, moe.y, estimate.y, moe.y, estimate, moe) %>% rename(Asian_Educational_Attainment=estimate.x, Asian_Median_Income_MOE=moe.x, Pacific_Islander_Median_Income=estimate.y, Pacific_Islander_Median_Income_MOE=moe.y, White_Median_Income=estimate, White_Median_Income_MOE=moe)
write.table(Asian_PI_white_df_formatted,"clipboard", sep='\t', row.names=FALSE )
Asian_PI_white_df_formatted
```
## Homeownership
```{r}
homeownership_black<-get_acs_recs(geography = 'county',
table.names = c('B25003B'),
years=c(2019),
acs.type = 'acs1')
homeownership_white<-get_acs_recs(geography = 'county',
table.names = c('B25003H'),
years=c(2019),
acs.type = 'acs1')
homeownership_df_black_white<- merge(homeownership_black, homeownership_white, by=c('label','name'))
write.table(homeownership_df_black_white,"clipboard", sep='\t', row.names=FALSE )
homeownership_df_black_white
```
### Median Age by Black and All
```{r}
Black_age_df<-get_acs_recs(geography = 'county',
table.names = c('B01002B'),
years=c(2019),
acs.type = 'acs5')
white_age_df <- get_acs_recs(geography = 'county',
table.names = c('B01002H'),
years=c(2019),
acs.type = 'acs5')
white_Black_df<-merge(Black_age_df, white_age_df, by=c('name','label'))%>% filter(label=='Estimate!!Median age --!!Total:')%>%
select(name,estimate.x, estimate.y, )%>% rename('County'='name', 'Black population' ='estimate.x', 'White Population'='estimate.y')
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )
white_Black_df
```
### Poverty Rates
```{r}
poverty_df_Black<- get_acs_recs(geography = 'county',
table.names = c('B17020B'),
years=c(2019),
acs.type = 'acs5')
poverty_df_white <- get_acs_recs(geography = 'county',
table.names = c('B17020H'),
years=c(2019),
acs.type = 'acs5')
poverty_df_white<- poverty_df_white %>% filter(label=='Estimate!!Total:' | label=='Estimate!!Total:!!Income in the past 12 months below poverty level:')%>%select(name, estimate,moe,label)%>%tidyr::pivot_wider(names_from=label,values_from=c(estimate,moe) )
poverty_df_black<- poverty_df_Black %>% filter(label=='Estimate!!Total:' | label=='Estimate!!Total:!!Income in the past 12 months below poverty level:')%>%select(name, estimate,moe,label)%>%tidyr::pivot_wider(names_from=label,values_from=c(estimate,moe) )
poverty_df_black_white<- merge(poverty_df_black, poverty_df_white, by='name')
write.table(poverty_df_black_white,"clipboard", sep='\t', row.names=FALSE )
```
### Means of Transportation to Work
```{r}
white_transport_df <- get_acs_recs(geography = 'county',
table.names = c('B08105H'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
asian_transport_df <- get_acs_recs(geography = 'county',
table.names = c('B08105D'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
white_asian_df<-merge(asian_transport_df, white_transport_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_asian_df,"clipboard", sep='\t', row.names=FALSE )
white_asian_df
```
### Means of Transportation to Work
```{r}
white_transport_df <- get_acs_recs(geography = 'county',
table.names = c('B08105A'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
pi_transport_df <- get_acs_recs(geography = 'county',
table.names = c('B08105E'),
years=c(2020),
acs.type = 'acs5')%>%filter(name=='Region')
white_pi_df<-merge(pi_transport_df, white_transport_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_pi_df,"clipboard", sep='\t', row.names=FALSE )
white_pi_df
```
### B25014, Occupants per room
```{r}
white_df <- get_acs_recs(geography = 'county',
table.names = c('B25014H'),
years=c(2019),
acs.type = 'acs5')
Black_df <- get_acs_recs(geography = 'county',
table.names = c('B25014B'),
years=c(2019),
acs.type = 'acs5')
```
```{r}
white_Black_df<-merge(Black_df, white_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )
white_Black_df
```
```{r}
white_df <- get_acs_recs(geography = 'county',
table.names = c('B25032H'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
Black_df <- get_acs_recs(geography = 'county',
table.names = c('B25032B'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_Black_df<-merge(Black_df, white_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )%>%filter(name=='Region')
```
# Computers at home
```{r}
Black_df <- get_acs_recs(geography = 'county',
table.names = c('B28009B'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_df <- get_acs_recs(geography = 'county',
table.names = c('B28009H'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_Black_df<-merge(Black_df, white_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )%>%filter(name=='Region')
```
# Job sector
```{r}
Black_df <- get_acs_recs(geography = 'county',
table.names = c('C24010B'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_df <- get_acs_recs(geography = 'county',
table.names = c('C24010H'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_Black_df<-merge(Black_df, white_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )
white_Black_df
```
# Health Insurance
```{r}
Black_df <- get_acs_recs(geography = 'county',
table.names = c('C27001B'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_df <- get_acs_recs(geography = 'county',
table.names = c('C27001H'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')
white_Black_df<-merge(Black_df, white_df, by='label')%>%
select(estimate.x, moe.x, label, estimate.y, moe.y)
white_Black_df
write.table(white_Black_df,"clipboard", sep='\t', row.names=FALSE )
```
```{r}
foreign_born<-get_acs_recs(geography = 'tract',
table.names = 'B05006',
years = 2019,
acs.type = 'acs5')
foreign_born_Africa <- foreign_born %>% filter(label=='Estimate!!Total:!!Africa:')
gdb.nm <- paste0("MSSQL:server=",
"AWS-PROD-SQL\\Sockeye",
";database=",
"ElmerGeo",
";trusted_connection=yes")
spn <- 2285
wgs84=4326
tract_layer_name <- "dbo.tract2010_nowater"
tract.lyr <- st_read(gdb.nm, tract_layer_name, crs = spn)
m<-psrccensus::create_tract_map(tract.tbl=foreign_born_Africa, tract.lyr=tract.lyr,
legend.title='African Foreign Born Population', legend.subtitle='by Census Tract')
Map of difference in median income men vs women
### Median Earnings Tract
```{r}
earnings_df_tract <- get_acs_recs(geography = 'tract',
table.names = c('B20017'),
years=c(2019),
acs.type = 'acs5')%>%filter(label=="Estimate!!Median earnings in the past 12 months (in 2019 inflation-adjusted dollars) --!!Total (dollars):!!Male --!!Total (dollars)!!Worked full-time, year-round in the past 12 months (dollars)" | label=='Estimate!!Median earnings in the past 12 months (in 2019 inflation-adjusted dollars) --!!Total (dollars):!!Female --!!Total (dollars)!!Worked full-time, year-round in the past 12 months (dollars)')
```
``
###Educational attainment
```{r}
edu_df <- get_acs_recs(geography = 'county',
table.names = c('B15002'),
years=c(2019),
acs.type = 'acs5')%>%filter(name=='Region')%>% arrange(label, name)%>%select(name, label, estimate, moe)
edu_df
write.table(edu_df,"clipboard-16384", sep='\t', row.names=FALSE )
```