-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04_analysis_Original.R
1970 lines (1727 loc) · 120 KB
/
04_analysis_Original.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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
############################################
# # ACS # #
############################################
order <- c("Orleans", "Jefferson", "New Orleans Metro Area", "United States")
orderHisp <- c("Orleans", "Jefferson", "New Orleans Metro Area", "United States")
load("inputs/totalpop_metro.RData")
load("inputs/hispanRaw.RData")
load("inputs/RacepopestRaw.RData")
hispanRaw[hispanRaw == -555555555] <- 0
#Hispanic Origin
hispan <- hispanRaw %>%
filter(placename %in% c("Orleans", "New Orleans Metro Area", "United States")) %>%
#slice(match(orderHisp, place)) %>%
mutate(Cubanpct = TotCuba / TotalHisporLat,
Dominicanpct = TotDomin / TotalHisporLat,
Mexicanpct = TotMex / TotalHisporLat,
PuertoRicanpct = TotPR / TotalHisporLat,
Honduranpct = TotHond / TotalHisporLat,
Guatemalanpct = TotGuat / TotalHisporLat,
Nicaraguanpct = TotNicarag / TotalHisporLat,
Salvadoranpct = TotSalva / TotalHisporLat,
OtherCApct = TotOtherCA / TotalHisporLat,
SouthAmericanpct =TotSA / TotalHisporLat,
Otherpct = TotOtherHisporLat / TotalHisporLat,
# for US/other geo sig testing
CubanUS = rep(Cubanpct[3], 3),
DominicanUS = rep(Dominicanpct[3],3),
MexicanUS = rep(Mexicanpct[3],3),
PuertoRicanUS = rep(PuertoRicanpct[3],3),
HonduranUS = rep(Honduranpct[3],3),
GuatemalanUS = rep(Guatemalanpct[3],3),
NicaraguanUS = rep(Nicaraguanpct[3],3),
SalvadoranUS = rep(Salvadoranpct[3],3),
OtherCAUS = rep(OtherCApct[3],3),
SouthAmericanUS = rep(SouthAmericanpct[3],3),
OtherUS = rep(Otherpct[3],3),
CubanMoeProp = moeprop(y = TotalHisporLat, moex = TotCubaMOE, moey = TotalHisporLatMOE, p = Cubanpct),
DominicanMoeProp = moeprop(y = TotalHisporLat, moex = TotDominMOE, moey = TotalHisporLatMOE, p = Dominicanpct),
MexicanMoeProp = moeprop(y = TotalHisporLat, moex = TotMexMOE, moey = TotalHisporLatMOE, p = Mexicanpct),
PuertoRicanMoeProp =moeprop(y = TotalHisporLat, moex = TotPRMOE, moey = TotalHisporLatMOE, p = PuertoRicanpct),
HonduranMoeProp = moeprop(y = TotalHisporLat, moex = TotHondMOE, moey = TotalHisporLatMOE, p = Honduranpct),
GuatemalanMoeProp = moeprop(y = TotalHisporLat, moex = TotGuatMOE, moey = TotalHisporLatMOE, p = Guatemalanpct),
NicaraguanMoeProp = moeprop(y = TotalHisporLat, moex = TotNicaragMOE, moey = TotalHisporLatMOE, p = Nicaraguanpct),
SalvadoranMoeProp = moeprop(y = TotalHisporLat, moex = TotSalvaMOE, moey = TotalHisporLatMOE, p = Salvadoranpct),
OtherCAMoeProp = moeprop(y = TotalHisporLat, moex = TotOtherCAMOE, moey = TotalHisporLatMOE, p = OtherCApct),
SouthAmericanMoeProp = moeprop(y = TotalHisporLat, moex = TotSAMOE, moey = TotalHisporLatMOE, p = SouthAmericanpct),
OtherMoeProp= moeprop(y = TotalHisporLat, moex = TotOtherHisporLatMOE, moey = TotalHisporLatMOE, p = Otherpct),
###adding US MOEs to the stat test###
CubanUSMOE = rep(CubanMoeProp[3], 3),
DominicanUSMOE = rep(DominicanMoeProp[3],3),
MexicanUSMOE = rep(MexicanMoeProp[3],3),
PuertoRicanUSMOE = rep(PuertoRicanMoeProp[3],3),
HonduranUSMOE = rep(HonduranMoeProp[3],3),
GuatemalanUSMOE = rep(GuatemalanMoeProp[3],3),
NicaraguanUSMOE = rep(NicaraguanMoeProp[3],3),
SalvadoranUSMOE = rep(SalvadoranMoeProp[3],3),
OtherCAUSMOE = rep(OtherCAMoeProp[3],3),
SouthAmericanUSMOE = rep(SouthAmericanMoeProp[3],3),
OtherUSMOE = rep(OtherMoeProp[3],3),
######
CubanSIG = stattest(x=CubanUS, moex = CubanUSMOE, y=Cubanpct, moey = CubanMoeProp),
DominicanSIG = stattest(x=DominicanUS, moex = DominicanUSMOE, y=Dominicanpct, moey = DominicanMoeProp),
MexicanSIG =stattest(x=MexicanUS, moex = MexicanUSMOE, y=Mexicanpct, moey = MexicanMoeProp),
PuertoRicanSIG = stattest(x=PuertoRicanUS, moex = PuertoRicanUSMOE, y=PuertoRicanpct, moey=PuertoRicanMoeProp),
HonduranSIG = stattest(x=HonduranUS, moex = HonduranUSMOE, y=Honduranpct, moey = PuertoRicanMoeProp),
GuatemalanSIG = stattest( x=GuatemalanUS, moex = GuatemalanUSMOE, y=Guatemalanpct, moey = GuatemalanMoeProp),
NicaraguanSIG = stattest(x=NicaraguanUS, moex = NicaraguanUSMOE, y = Nicaraguanpct, moey = NicaraguanMoeProp),
SalvadoranSIG = stattest(x=SalvadoranUS, moex = SalvadoranUSMOE, y = Salvadoranpct, moey = SalvadoranMoeProp),
OtherCASIG = stattest(x=OtherCAUS, moex = OtherCAUSMOE, y = OtherCApct, moey = OtherCAMoeProp),
SouthAmericanSIG= stattest(x=SouthAmericanUS, moex = SouthAmericanUSMOE, y=SouthAmericanpct, moey = SouthAmericanMoeProp),
OtherSIG = stattest(x=OtherUS, moex = OtherUSMOE, y=Otherpct, moey = OtherMoeProp))
hispanCSV <- hispan %>%
select(place, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "Hispanic origin", values_to = "Value") %>%
pivot_wider(id_cols = c("Hispanic origin"), names_from = "place", values_from = "Value")
write.csv(hispanCSV, "outputs/spreadsheets/hispan.csv")
storage_write_csv(hispanCSV, cont_proj, "who_lives/2024/outputs/hispan.csv")
#Households with own children under 18
load("inputs/hwcRaw.RData")
load("inputs/hwc2000Raw.RData")
hwc <- hwcRaw %>%
left_join(hwc2000Raw, by = "place") %>%
mutate(census2000 = c(0.3007,0.3251,0.397,0.3353,0.3339),
census2000SE = c(0.00259888,0.002743002, 0.004572234,0.001643334,9.24E-05),
tothwc = Married + MaleHH + FemaleHH,
pcthwc = tothwc/TotalHH,
moeagg = moeagg(cbind(MarriedMOE, MaleHHMOE, FemaleHHMOE)),
# moeagg2000 = moeagg(cbind(Married2000MOE, MaleHH2000MOE, FemaleHH2000MOE)),
moeprop = moeprop(y = TotalHH, moex = moeagg, moey = TotalHHMOE, p = pcthwc),
#moeprop2000 = moeprop(y = TotalHH2000, moex = moeagg2000, moey = TotalHHMOE2000, p = pcthwc2000),
significant = stattest(x=census2000,moex = census2000SE*1.645, y=pcthwc,moey = moeprop))
hwcCSV <- hwc %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "hwc", values_to = "Value") %>%
mutate(name = paste( place, hwc, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(hwcCSV, "outputs/spreadsheets/hwc.csv")
storage_write_csv(hwcCSV, cont_proj, "who_lives/2024/outputs/hwc.csv")
#One-person households
load("inputs/singRaw.RData")
sing <- singRaw %>%
mutate(census2000 = c(0.331,0.2665,0.1968,0.2707,0.2578),
census2000SE = c(0.002666846, 0.00258897, 0.003715052, 0.001549686, 8.57E-05),
pctsing = SingleHH/TotalHH,
moeprop = moeprop(y = TotalHH, moex = SingleHHMOE, moey = TotalMOE, p = pctsing),
significant = stattest(x=census2000, moex = census2000SE *1.645, y=pctsing,moey = moeprop))
singCSV <- sing %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "sing", values_to = "Value") %>%
mutate(name = paste( place, sing, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(singCSV, "outputs/spreadsheets/sing.csv")
storage_write_csv(singCSV, cont_proj, "who_lives/2024/outputs/sing.csv")
#Less than a high school degree, adults 25 and older
load("inputs/hsRaw.RData")
hs <- hsRaw %>%
mutate(census2000=c(0.2531,0.2073,0.1613,0.1536,0.196),
census2000SE = c(0.002128079, 0.001990165, 0.002814633, 0.001219893, 6.58E-05),
totless = Male9 + Male9to12 + Female9 + Female9to12,
pctless = totless/Total,
moeagg = moeagg(cbind(Male9MOE, Male9to12MOE, Female9MOE, Female9to12MOE)),
moeprop = moeprop(y = Total, moex = moeagg, moey = TotalMOE, p = pctless),
significant = stattest(x=census2000, moex = census2000SE*1.645, y=pctless,moey=moeprop))
hsCSV <- hs %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "hs", values_to = "Value") %>%
mutate(name = paste( place, hs, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(hsCSV, "outputs/spreadsheets/hs.csv")
storage_write_csv(hsCSV, cont_proj, "who_lives/2024/outputs/hs.csv")
#Bachelor's degree or higher, adults 25 and older
load("inputs/bachRaw.RData")
bach <- bachRaw %>%
mutate(census2000=c(0.2575,0.2149,0.2832,0.2256,0.244), #are we sure about MSA number
census2000SE = c(0.002140185, 0.002016578, 0.003447718,0.001228988, 7.11E-05),
totbach = MaleBach + MaleGradProf + FemaleBach + FemaleGradProf,
pctbach = totbach / Total,
moeagg = moeagg(cbind(MaleBachMOE, MaleGradProfMOE, FemaleBachMOE, FemaleGradProfMOE)),
moeprop = moeprop(y = Total, moex = moeagg, moey = TotalMOE, p = pctbach),
significant = stattest(x=census2000, moex = census2000SE*1.645, y=pctbach,moey = moeprop))
bachCSV <- bach %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "bach", values_to = "Value") %>%
mutate(name = paste( place, bach, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(bachCSV, "outputs/spreadsheets/bach.csv")
storage_write_csv(bachCSV, cont_proj, "who_lives/2024/outputs/bach.csv")
#Median household income, 201* inflation-adjusted dollars
#***************NEED MOE FOR 2000 DATA**********************
census2000 <- data.frame(#census2000 = cpi99*c(27133,38435,47883,35317,41994)) #old numbers
census2000 = cpi99 * c(27129, 38239, 47453, 35183, 41851),
census2000MOE = cpi99 * c(679.63, 770.33, 585.37, 801.32, 902.83))
load("inputs/medhhRaw.RData")
medhh <- medhhRaw %>%
bind_cols(.,census2000) %>%
mutate(significant = stattest(x=census2000,moex = census2000MOE, y=MedianHHIncome,moey=MedianHHIncomeMOE))
medhhCSV <- medhh %>%
select(place, census2000, MedianHHIncome) %>%
pivot_longer(-c("place"), names_to = "medhh", values_to = "Value") %>%
mutate(name = paste( place, medhh, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(medhhCSV, "outputs/spreadsheets/medhh.csv")
storage_write_csv(medhhCSV, cont_proj, "who_lives/2024/outputs/medhh.csv")
#Internet access
load("inputs/intaRaw.RData")
inta <- intaRaw %>%
mutate(cellonlypct = CellOnly / Total,
cellmoeprop = moeprop(y = Total, moex = CellOnlyMOE, moey = TotalMOE, p = cellonlypct),
nosubpct = NoSubscript / Total,
nosubmoeprop = moeprop(y = Total, moex = NoSubscriptMOE, moey = TotalMOE, p = nosubpct),
noaccpct = NoAccess / Total,
noaccmoeprop = moeprop(y = Total, moex = NoAccessMOE, moey = TotalMOE, p = noaccpct),
broadband = Total-(CellOnly +NoSubscript+NoAccess),
broadbandMOE = moeagg(cbind(TotalMOE, CellOnlyMOE, NoSubscriptMOE, NoAccessMOE)),
broadbandpct = broadband / Total,
broadbandmoeprop = moeprop(y= Total, moex = broadbandMOE, moey = TotalMOE, p = broadbandpct),
cellonlyUS = rep(cellonlypct[5],5),
nosubUS = rep(nosubpct[5],5),
noaccUS = rep(noaccpct[5],5),
broadbandUS = rep(broadbandpct[5],5),
cellonlyUSMOE = rep(cellmoeprop[5],5),
nosubUSMOE = rep(nosubmoeprop[5],5),
noaccUSMOE = rep(noaccmoeprop[5],5),
broadbandUSMOE = rep(broadbandmoeprop[5],5),
cellonlySIG = stattest(x=cellonlyUS, moex = cellonlyUSMOE, y = cellonlypct, moey = cellmoeprop),
nosubSIG = stattest(x = nosubUS, moex = nosubUSMOE,y = nosubpct, moey = nosubmoeprop),
noaccSIG = stattest(x = noaccUS, moex = noaccUSMOE, y = noaccpct, moey = noaccmoeprop),
broadbandSIG = stattest(x = broadbandUS, moex = broadbandUSMOE, y = broadbandpct, moey = broadbandmoeprop))
intaCSV <- inta %>%
select(place, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "inta", values_to = "Value") %>%
pivot_wider(id_cols = c("inta"), names_from = "place", values_from = "Value")
write.csv(intaCSV, "outputs/spreadsheets/inta.csv")
storage_write_csv(intaCSV, cont_proj, "who_lives/2024/outputs/inta.csv")
#Poverty rate, population for whom poverty has been determined
load("inputs/povRaw.RData")
pov <- povRaw %>%
mutate(sf1999=c(0.2794,0.1365,0.0972,0.1838,0.1238),
sf1999SE = c(0.002198943, 0.001714384, 0.002287413, 0.001142575,5.78E-05),
pctpov = BelowPov / Total,
moeprop = moeprop(y = Total, moex = BelowPovMOE, moey = TotalMOE, p = pctpov),
significant = stattest(x=sf1999, moex = sf1999SE*1.645, y=pctpov,moey=moeprop))
povCSV <- pov %>%
select(place, sf1999, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "pov", values_to = "Value") %>%
mutate(name = paste( place, pov, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(povCSV, "outputs/spreadsheets/pov.csv")
storage_write_csv(povCSV, cont_proj, "who_lives/2024/outputs/pov.csv")
#Children in poverty, population for whom poverty has been determined
load("inputs/childpovRaw.RData")
childpov <- childpovRaw %>%
mutate(sf1999=c(0.4053,0.2034,0.123,0.2623,0.1656),
sf1999SE = c(0.004610543, 0.00401331, 0.004760158, 0.002505787, 1.28E-04),
TotChildPov = BelowPovFemaleChild + BelowPovMaleChild + AbovePovFemaleChild + AbovePovMaleChild,
moeaggtot = moeagg(cbind(BelowPovFemaleChildMOE, BelowPovMaleChildMOE, AbovePovFemaleChildMOE, AbovePovMaleChildMOE)),
TotBelowChildPov = BelowPovFemaleChild + BelowPovMaleChild,
moeaggbelow = moeagg(cbind(BelowPovFemaleChildMOE, BelowPovMaleChildMOE)),
pctBelowChildPov = TotBelowChildPov / TotChildPov,
moeprop = moeprop(y=TotChildPov, moex = moeaggbelow, moey = moeaggtot, p=pctBelowChildPov),
significant = stattest(x=sf1999, moex = sf1999SE*1.645, y=pctBelowChildPov,moey=moeprop))
childpovCSV <- childpov %>%
select(place, sf1999, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "childpov", values_to = "Value") %>%
mutate(name = paste( place, childpov, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(childpovCSV, "outputs/spreadsheets/childpov.csv")
storage_write_csv(childpovCSV, cont_proj, "who_lives/2024/outputs/childpov.csv")
#Households without access to a vehicle
load("inputs/vehRaw.RData")
veh <- vehRaw %>%
mutate(census2000=c(0.2732,0.0930,0.0442,0.1532,0.1030),
census2000SE = c(0.002755866, 0.001856238, 0.002095766, 0.001371385, 6.62E-05),
vehpct = NoVehAvail / Total,
moeprop = moeprop(y = Total, moex = NoVehAvailMOE, moey = TotalMOE, p = vehpct),
significant = stattest(x=census2000, moex= census2000SE*1.645,y=vehpct,moey = moeprop))
vehCSV <- veh %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "veh", values_to = "Value") %>%
mutate(name = paste( place, veh, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(vehCSV, "outputs/spreadsheets/veh.csv")
storage_write_csv(vehCSV, cont_proj, "who_lives/2024/outputs/veh.csv")
#Population not U.S. citizens at birth
load("inputs/forborRaw.RData")
forbor <- forborRaw %>%
mutate(TotalPopMOE = ifelse(TotalPopMOE < 0, 0, TotalPopMOE)) %>%
mutate(census2000=c(0.0425,0.0748,0.0237,0.048,0.1105),
census2000SE =c(0.001036254, 0.001394458, 0.001243694, 0.000671199, 5.85E-05),
forborpct = (TotForeign00to09 + TotForeign90to99 + TotForeignPre90 + TotForeign10on) / TotalPop,
forbormoeagg = moeagg(cbind(TotForeign00to09MOE, TotForeign90to99MOE, TotForeignPre90MOE, TotForeign10onMOE)),
forbormoeprop = moeprop(y=TotalPop, moex = forbormoeagg, moey = TotalPopMOE, p=forborpct),
significant = stattest(x=census2000,moex = census2000SE*1.645, y=forborpct,moey=forbormoeprop))
forborCSV <- forbor %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "forbor", values_to = "Value") %>%
mutate(name = paste( place, forbor, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(forborCSV, "outputs/spreadsheets/forbor.csv")
storage_write_csv(forborCSV, cont_proj, "who_lives/2024/outputs/forbor.csv")
#Population who moved in the past year
load("inputs/mobRaw.RData")
mob <- mobRaw %>%
mutate(sf2004mobabroad =c(0.0013,0.0044,0.00,0.00,0.006), #zeroes previously filled in for both metro and St. Tammany 2004 because of missing data, HT is filling in 2004 Metro.
sf2004mobabroadMOE = c(0.0013025893, 0.0033903959, 0, 0, 0.0002322461),
sf2004states=c(0.0206,0.02,0.00,0.00,0.0235),
sf2004statesMOE = c(0.0085199087, 0.0115190278, 0, 0, 0.0006242538),
sf2004difparish=c(0.0085,0.03,0.00,0.00,0.0302),
sf2004difparishMOE = c(0.0037592895, 0.0119890315, 0, 0, 0.0005295007),
sf2004withinparish=c(0.1131,0.0958,0.00,0.00,0.0973),
sf2004withinparishMOE = c(0.023344033, 0.022923510, 0, 0, 0.001341028),
sf2004samehouse=c(0.8565,0.8498,0.00,0.00,0.8430),
sf2004samehouseMOE = c(0.026188401, 0.028107571, 0, 0, 0.001767759),
mobabroadpct = TotMovedfromAbroad / Total,
mobStatespct = TotMovedbtwnStates / Total,
difparishpct = TotMovedinState / Total,
withinparishpct = TotMovedinCty / Total,
samehousepct = TotSameHouse / Total,
mobabroadmoeprop = moeprop(y=Total,moex = TotMovedfromAbroadMOE,moey = TotalMOE,p=mobabroadpct),
mobStatesmoeprop = moeprop(y=Total,moex = TotMovedbtwnStatesMOE,moey = TotalMOE,p=mobStatespct),
difparishmoeprop = moeprop(y=Total,moex = TotMovedinStateMOE,moey = TotalMOE,p=difparishpct),
withinparishmoeprop = moeprop(y=Total,moex = TotMovedinCtyMOE,moey = TotalMOE,p=withinparishpct),
samehousemoeprop = moeprop(y=Total, moex = TotSameHouseMOE,moey = TotalMOE,p=samehousepct),
abroadSIG = stattest (x=sf2004mobabroad, moex = sf2004mobabroadMOE, y=mobabroadpct, moey = mobabroadmoeprop),
statesSIG = stattest (x=sf2004states, moex = sf2004statesMOE, y=mobStatespct,moey = mobStatesmoeprop),
difparishSIG = stattest (x=sf2004difparish, moex = sf2004difparishMOE, y =difparishpct, moey = difparishmoeprop),
withinparishSIG = stattest (x=sf2004withinparish, moex = sf2004withinparishMOE, y=withinparishpct, moey = withinparishmoeprop),
samhouseSIG = stattest (x=sf2004samehouse, moex = sf2004samehouseMOE, y=samehousepct, moey = samehousemoeprop))
mobCSV <- mob %>%
select(place, (contains("sf2004") & !contains("MOE")), (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "mob", values_to = "Value") %>%
mutate(year = ifelse(grepl("2004", mob), "2004", "2022"),
header = paste(place, year, sep = "-"),
mobfinal = ifelse(grepl("abroad", mob), "abroad", mob),
mobfinal = ifelse(grepl("tates", mob), "tates", mobfinal),
mobfinal = ifelse(grepl("difparish", mob), "difparish", mobfinal),
mobfinal = ifelse(grepl("withinparish", mob), "withinparish", mobfinal),
mobfinal = ifelse(grepl("samehouse", mob), "samehouse", mobfinal),
mobfinal = factor(mobfinal, levels = c("samehouse", "withinparish", "difparish", "tates", "abroad"))) %>%
arrange(mobfinal) %>%
pivot_wider(id_cols = c("mobfinal"), names_from = "header", values_from = "Value")
write.csv(mobCSV, "outputs/spreadsheets/mob.csv")
storage_write_csv(mobCSV, cont_proj, "who_lives/2024/outputs/mob.csv")
## mobility sig testing for written analysis
OPmoeagg <- moeagg(cbind(mob$TotMovedinStateMOE[1],mob$TotMovedbtwnStatesMOE[1],mob$TotMovedfromAbroadMOE[1]))
OPpct <- (mob$TotMovedinState[1]+mob$TotMovedbtwnStates[1]+mob$TotMovedfromAbroad[1])/mob$Total[1]
OPmoeprop <- moeprop(y=mob$Total[1], moex = OPmoeagg, moey = mob$TotalMOE[1], p= OPpct)
OPsig <- stattest(x = (mob$sf2004mobabroad[1]+mob$sf2004states[1]+mob$sf2004difparish[1]), y=OPpct, moey=OPmoeprop)
jeffmoeagg <- moeagg(cbind(mob$TotMovedinStateMOE[2],mob$TotMovedbtwnStatesMOE[2],mob$TotMovedfromAbroadMOE[2]))
jeffpct <- (mob$TotMovedinState[2]+mob$TotMovedbtwnStates[2]+mob$TotMovedfromAbroad[2])/mob$Total[2]
jeffmoeprop <- moeprop(y=mob$Total[2], moex = jeffmoeagg, moey = mob$TotalMOE[2], p= jeffpct)
jeffsig <- stattest(x = (mob$sf2004mobabroad[2]+mob$sf2004states[2]+mob$sf2004difparish[2]), y=jeffpct, moey=jeffmoeprop)
#Homeownership rates
load("inputs/hoRaw.RData")
load("inputs/hoRaw2000.RData")
ho <- hoRaw %>% left_join(hoRaw2000, by = "placename") %>%
mutate(#census2000=c(0.465,0.6385,0.8048,0.6183,0.6619), #got this from SF1 for no SEs
# census2000SE = c(0.00282756, 0.002814847, 0.0037049, 0.001695053, 1.03E-04), #using SF1 to be consistent and no MOEs
Ownerpct = Owner / Total,
Ownerpct2000 = Owner2000 / Total2000,
Ownermoeprop = moeprop(y=Total,moex = OwnerMOE,moey = TotalMOE,p=Ownerpct),
significant = stattest(x=Ownerpct2000 ,y=Ownerpct,moey = Ownermoeprop))
hoCSV <- ho %>%
select(place, (contains("pct"))) %>% select(place, Ownerpct2000, Ownerpct) %>%
pivot_longer(-c("place"), names_to = "ho", values_to = "Value") %>%
mutate(name = paste( place, ho, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(hoCSV, "outputs/spreadsheets/ho.csv")
storage_write_csv(hoCSV, cont_proj, "who_lives/2024/outputs/ho.csv")
#Homeowners without a mortgage
load("inputs/honomoRaw.RData")
honomo <- honomoRaw %>%
mutate(census2000 = c(0.3298,0.3458,0.2967,0.3476,0.3259),
census2000SE = c(0.004263821, 0.003804423, 0.005191947, 0.00230056781162641, 1.25E-04),
honomopct = NoMortgage / Total,
moeprop = moeprop(y=Total,moex =NoMortgageMOE,moey = TotalMOE,p=honomopct),
significant = stattest(x=census2000, moex = census2000SE*1.645, y=honomopct,moey=moeprop))
honomoCSV <- honomo %>%
select(place, census2000, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "honomo", values_to = "Value") %>%
mutate(name = paste( place, honomo, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(honomoCSV, "outputs/spreadsheets/honomo.csv")
storage_write_csv(honomoCSV, cont_proj, "who_lives/2024/outputs/honomo.csv")
#Renters with severe housing cost burdens
load("inputs/rentburRaw.RData")
rentbur <- rentburRaw %>%
mutate(#sf2004=c(0.2432,0.2167,0,0.2161,0.2384),#0 for St. tammany missing value ### ****HT commenting out old values, adding ones I pulled from 2004 ACS
#order is "Orleans", "Jefferson", "St. Tammany", "New Orleans Metro Area", "United States"
sf2004 = c(0.2304765, 0.2019471, 0, 0, 0.2196190),
sf2004MOE = c(0.044544178, 0.052252324,0, 0, 0.003006082),
rentburpct = `50orMore`/ (Total - NotComputed),
moeagg = moeagg(cbind(TotalMOE, NotComputedMOE)),
moeprop = moeprop(y=(Total - NotComputed),moex=`50orMoreMOE`,moey = moeagg, p = rentburpct),
significant = stattest(x=sf2004, moex = sf2004MOE, y=rentburpct, moey=moeprop))
rentburCSV <- rentbur %>%
select(place, (contains("2004")) & (!contains("MOE")), (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "rentbur", values_to = "Value") %>%
mutate(name = paste( place, rentbur, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(rentburCSV, "outputs/spreadsheets/rentbur.csv")
storage_write_csv(rentburCSV, cont_proj, "who_lives/2024/outputs/rentbur.csv")
#Homeowners with severe housing cost burdens
load("inputs/hoburRaw.RData")
hobur <- hoburRaw %>%
mutate(#sf2004=c(0.1620,0.0891,0,0.1134,0.0988), #0 for St. tammany missing value, ### ****HT commenting out old values, adding ones I pulled from 2004 ACS
#order is "Orleans", "Jefferson", "St. Tammany", "New Orleans Metro Area", "United States"
sf2004 = c(0.13226868, 0.06815970, 0, 0, 0.07895178),
sf2004MOE = c(0.030880769, 0.025995416, 0, 0, 0.000911579), #getting these numbers from line 154 of data-pull.R
hoburpct = (`50orMoreMortgage`+`50orMoreNoMortgage`)/(Total - NotComputedMortgage - NotComputedNoMortgage),
moexagg = moeagg(cbind(`50orMoreMortgageMOE`,`50orMoreNoMortgageMOE`)),
moeyagg = moeagg(cbind(TotalMOE, NotComputedMortgageMOE, NotComputedNoMortgageMOE)),
moeprop = moeprop(y=Total,moex=moexagg,moey=moeyagg,p=hoburpct),
significant = stattest(x=sf2004,moex = sf2004MOE, y=hoburpct, moey=moeprop))
hoburCSV <- hobur %>%
select(place, (contains("2004")) & (!contains("MOE")), (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "hobur", values_to = "Value") %>%
mutate(name = paste( place, hobur, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(hoburCSV, "outputs/spreadsheets/hobur.csv")
storage_write_csv(hoburCSV, cont_proj, "who_lives/2024/outputs/hobur.csv")
#Median gross rent, 201* inflation-adjusted dollars
load("inputs/medrentRaw.RData")
#sf2004 <- data.frame(sf2004 = cpi04*c(566,654,0,616,694))### ****HT commenting out old values, adding ones I pulled from 2004 ACS
#order is "Orleans", "Jefferson", "St. Tammany", "New Orleans Metro Area", "United States"
sf2004 <- data.frame(sf2004 = cpi04 * c(566, 654, 0, 0, 694), # note that these are the exact same as what we already had, just adjusting to 2022 dollars and noting that I have the same estimates for med rent, but not the rent/hoburden percentages.)
sf2004MOE = cpi04 * c(29, 48, 0, 0, 2)) #also noting that I am inflation adjusting the MOES the same way
medrent <- medrentRaw %>%
bind_cols(.,sf2004) %>%
mutate(significant = stattest(x=sf2004, moex = sf2004MOE, y=Rent,moey=RentMOE))
medrentCSV <- medrent %>%
select(place, sf2004, Rent) %>%
pivot_longer(-c("place"), names_to = "medrent", values_to = "Value") %>%
mutate(name = paste( place, medrent, sep = "-"),
year = 2022) %>%
select(-place) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value")
write.csv(medrentCSV, "outputs/spreadsheets/medrent.csv")
storage_write_csv(medrentCSV, cont_proj, "who_lives/2024/outputs/medrent.csv")
#Year structure built, 201* housing units
load("inputs/yrbuiltRaw.RData")
yrbuilt <- yrbuiltRaw %>%
mutate(orLater1990pct = (`1990to1999` + `2000to2009` + `2010to2013` + `2014`)/Total,
mid1950to1989pct = (`1950to1959`+`1960to1969`+`1970to1979`+`1980to1989`)/Total,
orbefore1949pct = (`1940to1949`+`1939`)/Total,
orlater1990moeagg = moeagg(cbind(`1990to1999MOE`,`2000to2009MOE`, `2010to2013MOE`,`2014MOE`)),
mid1950to1989moeagg =moeagg(cbind(`1950to1959MOE`,`1960to1969MOE`,`1970to1979MOE`,`1980to1989MOE`)),
orbefore1949moeagg = moeagg(cbind(`1940to1949MOE`,`1939MOE`)),
orlater1990moeprop = moeprop(y=Total,moex = orlater1990moeagg, moey = TotalMOE,p=orLater1990pct),
mid1950to1989moeprop = moeprop(y=Total,moex = mid1950to1989moeagg, moey = TotalMOE,p=mid1950to1989pct),
orbefore1949moeprop = moeprop(y=Total,moex = orbefore1949moeagg, moey = TotalMOE,p=orbefore1949pct),
orLater1990US = rep(orLater1990pct[5],5),
mid1950to1989US = rep(mid1950to1989pct[5],5),
orbefore1949US = rep(orbefore1949pct[5],5),
orLater1990SIG = stattest(x=orLater1990US, y= orLater1990pct, moey = orlater1990moeprop),
mid1950to1989SIG = stattest(x= mid1950to1989US, y= mid1950to1989pct , moey = mid1950to1989moeprop),
orbefore1949SIG = stattest(x=orbefore1949US, y= orbefore1949pct, moey = orbefore1949moeprop))
yrbuiltCSV <- yrbuilt %>%
select(place, (contains("pct"))) %>%
pivot_longer(-c("place"), names_to = "yrbuilt", values_to = "Value") %>%
pivot_wider(id_cols = c("yrbuilt"), names_from = "place", values_from = "Value")
write.csv(yrbuiltCSV, "outputs/spreadsheets/yrbuilt.csv")
storage_write_csv(yrbuiltCSV, cont_proj, "who_lives/2024/outputs/yrbuilt.csv")
#Means of transportation to work,
load("inputs/commuteRaw.RData")
load("inputs/commuteRaw2000.RData")
commute <- commuteRaw %>% left_join(commuteRaw2000, by = "placename") %>%
filter(placename %in% c("Orleans", "Jefferson", "New Orleans Metro Area", "United States")) %>%
mutate(census2000drive=c(0.6028,0.7855,0.7301,0.7570),
census2000carpool=c(0.1614,0.1372,0.1465,0.1219),
census2000publictransit=c(0.1322,0.0023,0.0530,0.0457),
census2000bike=c(0.0116,0.0032,0.0059,0.0038),
census2000walk=c(0.0521,0.0174,0.0272,0.0293),
census2000workhome=c(0.0266,0.0368,0.0241,0.0326),
census2000other=c(0.0133,0.0143,0.0133,0.0097),
Drivepct = DroveAlone / Total,
Carpoolpct= Carpool / Total,
PublicTransitpct = PublicTransit / Total,
bikepct = Bike / Total,
Walkpct = Walk / Total,
Workhomepct = Workhome / Total,
Otherpct = Other / Total,
Drivepct2000 = DroveAlone2000 / Total2000,
Carpoolpct2000= Carpool2000 / Total2000,
PublicTransitpct2000 = PublicTransit2000 / Total2000,
bikepct2000 = Bike2000 / Total2000,
Walkpct2000 = Walk2000 / Total2000,
Workhomepct2000 = Workhome2000 / Total2000,
Otherpct2000 = Other2000 / Total2000,
Drivemoeprop = moeprop(y=Total, moex=DroveAloneMOE, moey=TotalMOE, p=Drivepct),
carpoolmoeprop = moeprop(y=Total, moex=CarpoolMOE, moey=TotalMOE, p=Carpoolpct),
PublicTransitmoeprop = moeprop(y=Total, moex=PublicTransitMOE, moey=TotalMOE, p=PublicTransitpct),
bikemoeprop = moeprop(y=Total, moex=BikeMOE, moey=TotalMOE, p=bikepct),
Walkmoeprop = moeprop(y=Total, moex=WalkMOE, moey=TotalMOE, p=Walkpct),
workhomemoeprop = moeprop(y=Total, moex=WorkhomeMOE, moey=TotalMOE, p=Workhomepct),
othermoeprop = moeprop(y=Total, moex=OtherMOE, moey=TotalMOE, p=Otherpct),
Drivemoeprop2000 = moeprop(y=Total2000, moex=DroveAloneMOE2000, moey=TotalMOE2000, p=Drivepct2000),
carpoolmoeprop2000 = moeprop(y=Total2000, moex=CarpoolMOE2000, moey=TotalMOE2000, p=Carpoolpct2000),
PublicTransitmoeprop2000 = moeprop(y=Total2000, moex=PublicTransitMOE2000, moey=TotalMOE2000, p=PublicTransitpct2000),
bikemoeprop2000 = moeprop(y=Total2000, moex=BikeMOE2000, moey=TotalMOE2000, p=bikepct2000),
Walkmoeprop2000 = moeprop(y=Total2000, moex=WalkMOE2000, moey=TotalMOE2000, p=Walkpct2000),
workhomemoeprop2000 = moeprop(y=Total2000, moex=WorkhomeMOE2000, moey=TotalMOE2000, p=Workhomepct2000),
othermoeprop2000 = moeprop(y=Total2000, moex=OtherMOE2000, moey=TotalMOE2000, p=Otherpct2000),
DriveSIG = stattest(x=census2000drive, moex = Drivemoeprop2000,y=Drivepct,moey = Drivemoeprop),
carpoolSIG = stattest (x=census2000carpool, moex = carpoolmoeprop2000, y=Carpoolpct, moey = carpoolmoeprop),
PublicTransitSIG = stattest (x=census2000publictransit, moex = , y=PublicTransitpct, moey = PublicTransitmoeprop),
bikeSIG = stattest(x=census2000bike, moex = PublicTransitmoeprop2000, y = bikepct, moey = bikemoeprop),
walkSIG = stattest (x=census2000walk, moex = Walkmoeprop2000, y = Walkpct, moey = Walkmoeprop),
workhomeSIG = stattest ( x=census2000workhome, moex = workhomemoeprop2000, y=Workhomepct, moey = workhomemoeprop),
otherSIG = stattest (x=census2000other, moex = othermoeprop2000, y= Otherpct, moey = othermoeprop))
commuteCSV <- commute %>%
select(placename, (contains("pct"))) %>%
pivot_longer(-c("placename"), names_to = "commute", values_to = "Value") %>%
mutate(year = ifelse(grepl("2000", commute), 2000, 2022),
header = paste(placename, year, sep = "-"),
commutefinal = ifelse(grepl("ive", commute), "DroveAlone", commute),
commutefinal = ifelse(grepl("arpool", commute), "Carpool", commutefinal),
commutefinal = ifelse(grepl("ublic", commute), "PublicTransit", commutefinal),
commutefinal = ifelse(grepl("Motorcycle", commute), "Motorcycle", commutefinal),
commutefinal = ifelse(grepl("ike", commute), "Bike", commutefinal),
commutefinal = ifelse(grepl("alk", commute), "Walk", commutefinal),
commutefinal = ifelse(grepl("home", commute), "Workhome", commutefinal),
commutefinal = ifelse(grepl("ther", commute), "Other", commutefinal)) %>%
pivot_wider(id_cols = c("commutefinal"), names_from = "header", values_from = "Value") %>%
select(commutefinal, `Orleans-2000`, `Orleans-2022`, `Jefferson-2000`, `Jefferson-2022`, `New Orleans Metro Area-2000`, `New Orleans Metro Area-2022`, `United States-2000`, `United States-2022` )
write.csv(commuteCSV, "outputs/spreadsheets/commute.csv")
storage_write_csv(commuteCSV, cont_proj, "who_lives/2024/outputs/commute.csv")
############################################
# # PEP # #
############################################
##############################################
# To analyze, filter to:
# whatever combination of demographics you need: race, age, sex, hisp
# whatever geography you need: place
# whatever year of estimate that you need: date
orderDemo <- c("Orleans Parish", "Jefferson Parish", "Plaquemines Parish", "St. Bernard Parish", "St. Charles Parish",
"St. James Parish", "St. John the Baptist Parish", "St. Tammany Parish", "Metro", "United States")
#allparishesRaw <- load("inputs/allparishesRaw.RData")
#Table 1
load("inputs/allparishesRaw2023.RData")
AAWhiteHispan <- allparishesRaw2023 %>%
filter(place == "Orleans Parish") %>%
filter(date == "7/1/2023 population estimate") %>%
filter(age == "Total" & sex == "Total" & (raceSimple == "Black"|raceSimple == "White" |hisp == "Hispanic" | raceSimple == "Asian" )) %>%
mutate(race.fac = factor(.$raceSimple,levels = c("Black", "White","Hispanic", "Asian")))%>% arrange(race.fac) %>%
mutate(est2000=c(323392, 128871, 14826, 10919)) %>% #check order of races in data frame. Order is bottom up
select(raceSimple, race.fac, population, est2000)
write.csv(AAWhiteHispan, "outputs/spreadsheets/AAWhiteHispan.csv")
storage_write_csv(AAWhiteHispan, cont_proj, "who_lives/2024/outputs/AAWhiteHispan.csv")
#Tables 2
#Remove Louisiana and Us to be able to combine 8 parish estimates for each race/ethnicity to create Metro
#HT : I just switched these around so it would make Metro last... The dataframe is not ordered by the levels of placename factor
#that's the order that the 2000 numbers are going in.
ParishDemo2<- allparishesRaw2023 %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>%
filter(date == "7/1/2023 population estimate") %>%
filter(age == "Total" & sex == "Total") %>%
group_by(raceSimple)%>% unique() %>%
summarise(population=sum(population)) %>% mutate(PlaceName = "Metro") %>% select(PlaceName, population, raceSimple)
ParishDemo3 <- allparishesRaw2023 %>% filter(PlaceName == "United States") %>%
filter(date == "7/1/2023 population estimate") %>%
filter(age == "Total" & sex == "Total") %>%
select(PlaceName, population, raceSimple)
ParishDemo1<- allparishesRaw2023 %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>% arrange((PlaceName)) %>%
filter(date == "7/1/2023 population estimate") %>%
filter(age == "Total" & sex == "Total") %>%
select(PlaceName, population, raceSimple) %>%
bind_rows(.,ParishDemo2, ParishDemo3)
#reshape data from long to wide for easy analysis
ParishDemo <- pivot_wider(ParishDemo1, names_from = raceSimple, values_from = population) %>%
mutate(PlaceName = factor(PlaceName, levels = c("Orleans", "Jefferson", "Plaquemines",
"St. Bernard","St. Charles", "St. James",
"St. John the Baptist", "St. Tammany", "Metro", "United States"))) %>%
mutate(pctwhite = as.numeric(White)/ as.numeric(Total),
pctblack = as.numeric(Black) / as.numeric(Total),
pctasian = as.numeric(Asian) / as.numeric(Total),
pcthisp = as.numeric(Hispanic) / as.numeric(Total),
white2000=c(.266,.645,.688,.844,.705,.497,.51 ,.853,.547,.691),
black2000=c(.667,.227,.233,.076,.251,.492,.446,.098,.373,.121),
asian2000=c(.023,.031,.026,.013,.006,0 ,.005,.008,.021,.037),
hispanic2000=c(.031,.071,.016,.051,.028,.006,.029,.025,.044,.125)) #%>%
#.[-2,]
orleansdemo_csv <- ParishDemo %>% filter(PlaceName == "Orleans") %>% select(PlaceName, Total:Hispanic) %>%
pivot_longer(cols = -PlaceName, names_to = "race", values_to = "est2023")
write.csv(orleansdemo_csv, "outputs/spreadsheets/orleansdemo.csv")
storage_write_csv(orleansdemo_csv, cont_proj, "who_lives/2024/outputs/orleansdemo.csv")
parishdemo_csv <- ParishDemo %>% select(-c(Total:Hispanic)) %>%
pivot_longer(cols = -PlaceName, names_to = c("race", "year"), names_sep = "2", values_to = "val") %>%
mutate(year = case_when(year == "000" ~ "2000",
is.na(year) ~ "2023",
T ~ year),
race = factor(case_when(grepl("white", race) ~ "White, non-Hispanic",
grepl("black", race) ~ "Black",
grepl("hisp", race) ~ "Hispanic, any race",
grepl("asian", race) ~ "Asian"), levels = c("White, non-Hispanic", "Black", "Hispanic, any race", "Asian"))) %>%
arrange(PlaceName, year) %>%
pivot_wider(names_from = c(PlaceName, year), values_from = val) %>%
arrange(race)
write.csv(parishdemo_csv, "outputs/spreadsheets/ParishDemo.csv")
storage_write_csv(parishdemo_csv, cont_proj, "who_lives/2024/outputs/ParishDemo.csv")
#Table 3 African American Population, New Orleans, 2000-current
#Pulling population estimates for 2010-current
load("inputs/blackpopestRaw.RData")
AAhistorical <- blackpopestRaw %>%
select(year, POP) %>%
arrange(year) %>%
#.[-(2:3),] %>% #Remove 2010 estimates we don't need. We use Census Population for 2010 so we can delete 2010 Population estimate
bind_rows(data.frame(POP = c(323392,0,0,0,0,0,133015,159887,181882,197337), row.names = (NULL)), .) %>%
select(POP) %>%
bind_cols(data.frame(year = as.factor(c(2000:2023))), .)
write.csv(AAhistorical, "outputs/spreadsheets/AAHistorical.csv")
storage_write_csv(AAhistorical, cont_proj, "who_lives/2024/outputs/AAHistorical.csv")
#######AA historical part 2
BlackPopyears <- allparishesRaw2023 %>%
filter(age == "Total" & sex == "Total") %>%
filter(raceSimple=="Black") %>%
filter(place %in% c("Orleans Parish", "Jefferson Parish", "Plaquemines Parish", "St. Bernard Parish", "St. Charles Parish",
"St. James Parish", "St. John the Baptist Parish", "St. Tammany Parish"))
BlackpopM <- blackpopestRaw %>%
add_row(year = "2000", place= "Orleans", POP=323392) %>%
select(year, POP)
write.csv(BlackpopM, "outputs/spreadsheets/BlackpopM.csv")
storage_write_csv(BlackpopM, cont_proj, "who_lives/2024/outputs/BlackpopM.csv")
#Table 4 Hispanic population change by population
HispanicPop <- allparishesRaw2023 %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>%
filter(age == "Total" & sex == "Total") %>%
filter(raceSimple=="Hispanic")%>%
select(PlaceName, population) %>%
mutate(est2000 = 0,
est2000 = ifelse(PlaceName == "St. Tammany", 4737, est2000),
est2000 = ifelse(PlaceName == "St. John the Baptist", 1230, est2000),
est2000 = ifelse(PlaceName == "St. James", 130, est2000),
est2000 = ifelse(PlaceName == "St. Charles", 1346, est2000),
est2000 = ifelse(PlaceName == "St. Bernard", 3425, est2000),
est2000 = ifelse(PlaceName == "Plaquemines", 433, est2000),
est2000 = ifelse(PlaceName == "Orleans", 14826, est2000),
est2000 = ifelse(PlaceName == "Jefferson", 32418, est2000))
#Table 5 Hispanic population for parishes in metro by year
HispanicPopyears <- allparishesRaw2023 %>%
filter(age == "Total" & sex == "Total") %>%
filter(raceSimple=="Hispanic") %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany"))
HispanicPopyears <- HispanicPopyears %>%
select(PlaceName, date, population) %>%
pivot_wider(id_cols = date, names_from = PlaceName, values_from = population )
write.csv(HispanicPopyears, "outputs/spreadsheets/HispanicPopyears.csv")
storage_write_csv(HispanicPopyears, cont_proj, "who_lives/2024/outputs/HispanicPopyears.csv")
load("inputs/hisppopestRaw.RData")
HISPpopM <- hisppopestRaw %>%
mutate(year = as.numeric(year)) %>%
filter(place %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>%
add_row(year = 2000, place= "Orleans", POP=14826) %>%
add_row(year = 2000, place= "Jefferson", POP=32418) %>%
add_row(year = 2000, place= "St. Tammany", POP=4737) %>%
add_row(year = 2000, place= "Plaquemines", POP=433) %>%
add_row(year = 2000, place= "St. Bernard", POP=3425) %>%
add_row(year = 2000, place= "St. Charles", POP=1346) %>%
add_row(year = 2000, place= "St. James", POP=130) %>%
add_row(year = 2000, place= "St. John the Baptist", POP=1230) %>%
select(place, year, POP) %>% unique()
HISPpopM_CSV <- HISPpopM %>% pivot_wider(names_from = "place", values_from = POP) %>%
select(year, Orleans, Jefferson, Plaquemines, `St. Bernard`, `St. Charles`, `St. James`, `St. John the Baptist`, `St. Tammany`) %>%
arrange(year)
write.csv(HISPpopM_CSV, "outputs/spreadsheets/HISPpopM.csv")
storage_write_csv(HISPpopM_CSV, cont_proj, "who_lives/2024/outputs/HISPpopM_CSV.csv")
#For excel
# HISPpopSheet1 <- HISPpopM %>%
# select(year, place, POP) %>%
# mutate(POP = as.numeric(POP))
#
# HiSPpopSheet <- spread(HISPpopSheet1, place, POP)
# I thought about calculating age in this way, but in the end, ACS metro-level estimate makes more sense to use -- this is kinda weird to do the weighted mean/median. Leaving this here to remember that I tried it! -- Jenna, 7/13/2020
# medAge <- as.data.frame(matrix(data = c(POPESTIMATE = c(432493, 390144, 23197 , 47244 , 53100 , 21096 , 42837 , 260419), MEDIAN_AGE_TOT = c(39.6, 37.7, 37.1, 35.1, 38.4, 39.5, 37.8, 40.5)), ncol = 2)) %>%
# summarise(med = mean(x = V2, wt = V1))
load("inputs/medageRaw.RData")
#Table 5 Population by age group
orderAge <- c(rep("Jefferson",18),rep("Orleans", 18),rep("Plaquemines",18),
rep("St. Bernard", 18),rep("St. Charles", 18),rep("St. James", 18),
rep("St. John The Baptist", 18),rep("St. Tammany",18))
Agepop <- allparishesRaw2023 %>%
filter(age== "Under 5 years" | age== "5 to 9"| age== "10 to 14" | age== "15 to 19"|
age=="20 to 24"| age== "25 to 29"| age== "30 to 34"| age== "35 to 39"| age== "40 to 44"
| age== "45 to 49" | age=="50 to 54"| age== "55 to 59"| age== "60 to 64"| age== "65 to 69"|
age== "70 to 74"| age== "75 to 79"| age== "80 to 84"| age== "85 plus")%>%
filter(raceSimple=="Total")%>%
filter(sex=="Total")%>%
filter(date == "7/1/2023 population estimate") %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>%
arrange(factor(PlaceName, levels = c("Jefferson","Orleans","Plaquemines",
"St. Bernard","St. Charles","St. James",
"St. John the Baptist","St. Tammany"))) %>%
select(age, PlaceName, population) %>%
mutate(est2000 = c(30226,31811,32657,32436,29793,31838,32713,36367,36834,34166,30658,23741,17911,15034,14991,11973,6942,5375,33496,
37133,36769,38312,38932,36416,34050,35053,36444,34562,29128,21068,16658,14648,14301,12458,7838,7408,1977,2183,2241,
2197,1668,1621,2024,2271,2247,1855,1554,1272,1034,854,769,524,259,207,4242,4639,4996,5021,4257,4196,4584,5327,5530,
4939,4398,3241,2597,2569,2714,2148,1051,780,3511,3994,4352,4063,2649,2662,3440,4407,4569,3732,2872,2025,1488,1345,
1244,859,462,398,1483,1711,1863,1936,1346,1142,1439,1671,1713,1496,1220,918,916,736,616,448,275,287,3463,3692,3874,
3837,2721,2699,3118,3612,3588,3240,2503,1907,1434,1006,925,663,416,346,13556,15029,16147,14672,9045,10257,12729,16457,
17655,16062,13641,9733,7125,5825,5168,4033,2296,1838))
Agepop_csv <- Agepop %>%
mutate(est22 = population,
est00 = est2000) %>%
pivot_wider(id_cols = age, names_from = PlaceName, values_from = c(est00, est22)) %>% select(est00_Orleans, est22_Orleans,
est00_Jefferson, est22_Jefferson,
est00_Plaquemines, est22_Plaquemines,
`est00_St. Bernard`, `est22_St. Bernard`,
`est00_St. Charles`, `est22_St. Charles`,
`est00_St. James`, `est22_St. James`,
`est00_St. John the Baptist`, `est22_St. John the Baptist`,
`est00_St. Tammany`, `est22_St. Tammany`)
write.csv(Agepop_csv, "outputs/spreadsheets/Agepop.csv")
storage_write_csv(Agepop_csv, cont_proj, "who_lives/2024/outputs/Agepop.csv")
#Table 6 Under 18 population
#Different than estimates from google sheets but aligns with American fact finder
under18pars<-allparishesRaw2023 %>%
filter(age=="18 years and over" | age=="Total")%>%
filter(raceSimple=="Total")%>%
filter(sex=="Total")%>%
filter(date == "7/1/2023 population estimate") %>%
filter(PlaceName %in% c("Orleans", "Jefferson", "Plaquemines", "St. Bernard", "St. Charles",
"St. James", "St. John the Baptist", "St. Tammany")) %>%
select(age, PlaceName, population)
#Creating metro
under18metro<- under18pars %>%
group_by(age)%>%
summarise(population=sum(population))
under18metro$PlaceName <- "Metro"
#stack back with other under 18
popunder18 <-bind_rows(under18pars,under18metro) %>%
spread(., age, population) %>%
mutate(under18 = Total-`18 years and over`) %>%
filter(PlaceName == "Orleans" | PlaceName =="Jefferson" | PlaceName == "St. Tammany" | PlaceName == "Metro")%>%
select(PlaceName, under18) %>%
mutate(est2000=c(115255,358092,129408,54399))
popunder18CSV <- popunder18 %>%
select(PlaceName, est2000, under18) %>%
pivot_longer(-c("PlaceName"), names_to = "under18", values_to = "Value") %>%
mutate(name = paste(PlaceName, under18, sep = "-"),
year = 2023) %>%
select(-PlaceName) %>%
pivot_wider(id_cols = c("year"), names_from = "name", values_from = "Value") %>%
select(`Orleans-est2000`, `Orleans-under18`, `Jefferson-est2000`, `Jefferson-under18`, `St. Tammany-est2000`, `St. Tammany-under18`, `Metro-est2000`, `Metro-under18`)
write.csv(popunder18CSV, "outputs/spreadsheets/under18.csv")
storage_write_csv(popunder18CSV, cont_proj, "who_lives/2024/outputs/under18.csv")
###########################
# Jenna's analysis expanded
###########################
childPovProspInd <- read_csv("inputs/indicator expansion drafts/ProspInd_tables_WhoLives2022/childPov.csv")
homeownershipProspInd <- read_csv("inputs/indicator expansion drafts/ProspInd_tables_WhoLives2022/homeownership.csv")
educationalAttainmentProspInd <- read_csv("inputs/indicator expansion drafts/ProspInd_tables_WhoLives2022/educationalAttainment.csv")
medHHincProspInd <- read_csv("inputs/indicator expansion drafts/ProspInd_tables_WhoLives2022/medHHinc.csv")
### Median household income ###
###
load("inputs/medhhRaw_exp.RData")
medhh_exp <- medhhRaw_exp %>%
mutate(placenames = NA,
placenames = ifelse(place == "103", "St. Tammany", placenames),
placenames = ifelse(place == "051", "Jefferson", placenames),
placenames = ifelse(place == "071", "Orleans", placenames),
placenames = ifelse(place == "35380","Metro",placenames),
placenames = ifelse(place == "1", "U.S.", placenames)) %>%
mutate(place.fac = factor(.$placenames,levels = c("Orleans", "Jefferson","St. Tammany","Metro", "U.S."))) %>%
select(-place, -placenames, -placename, -contains("MOE")) %>%
pivot_longer(-place.fac,names_to = "var",values_to = "val")
### Across geos median hh income bar chart ###
medhh.totals <- medhh_exp %>%
filter(var == "MedianHHIncome")%>%
mutate(var.fac = factor(.$var, levels = c("Black","White,\nnon-Hispanic","Asian","Hispanic,\nany race")))
medhh.race <- medhh_exp %>%
filter(var != "MedianHHIncome") %>%
mutate(var = ifelse(grepl("asian",var), "Asian",var),
var = ifelse(grepl("blk",var), "Black", var),
var = ifelse(grepl("hisp",var), "Hispanic,\nany race", var),
var = ifelse(grepl("wht",var), "White,\nnon-Hispanic", var)) %>%
mutate(var.fac = factor(.$var, levels = c("Black","White,\nnon-Hispanic","Asian","Hispanic,\nany race")))
### Historical median hh income line chart ###
## median hh income adjusted to 2022 dollars ###
#using https://data.bls.gov/cgi-bin/cpicalc.pl from january to january
#1979 to 2022 = 3.83
#1989 to 2022 = 2.16
#1999 to 2022 = 1.59
#2010 to 2022 = 1.21
#2016 to 2022 = 1.10
load("inputs/medhh_unadjusted.RData")
medhhinc_adjusted21 <- medhh_unadjusted %>% mutate(value = as.numeric(value),
inc_adj21 = case_when(Year == 1979 ~ value * 3.83,
Year == 1989 ~ value * 2.16,
Year == 1999 ~ value * 1.59,
Year == 2010 ~ value * 1.21,
Year == 2016 ~ value * 1.10))
# write_csv(medhhinc_adjusted21, "inputs/medHHinc_exp.csv")
medhh.hist <- medhhinc_adjusted21 %>%
select(-value) %>%
rename(val = inc_adj21) %>%
mutate(Year = as.numeric(Year),
var = ifelse(var == "Overall", "All", var),
var = ifelse(grepl("Bla",var), "Black", var),
var = ifelse(grepl("Hispanic,",var), "Hispanic,\nany race", var),
var = ifelse(grepl("Whi",var), "White,\nnon-Hispanic", var)) %>%
bind_rows(medhh_exp %>%
filter(place.fac == "Orleans",
!grepl("asian",var)) %>% ## remove asian numbers
select(-place.fac) %>%
mutate(Year = 2022, ## for the drafts, this is the wrong year, but will make the x axis the correct length for when we update the numbers
var = ifelse(var == "MedianHHIncome", "All", var),
var = ifelse(grepl("blk",var), "Black", var),
var = ifelse(grepl("hisp",var), "Hispanic,\nany race", var),
var = ifelse(grepl("wht",var), "White,\nnon-Hispanic", var)))%>%
mutate(var.fac = factor(.$var, levels = c("All","Black","White,\nnon-Hispanic","Hispanic,\nany race")))
### stat testing ###
medhh.race_stattest <- medhhRaw_exp %>%
mutate(sig_wht_blk = stattest(x=MedianHHIncome_wht, moex = MedianHHIncomeMOE_wht, y=MedianHHIncome_blk, moey = MedianHHIncomeMOE_blk),
sig_wht_hisp = stattest(x=MedianHHIncome_wht, moex = MedianHHIncomeMOE_wht, y=MedianHHIncome_hisp, moey = MedianHHIncomeMOE_hisp),
sig_wht_asian = stattest(x=MedianHHIncome_wht, moex = MedianHHIncomeMOE_wht, y=MedianHHIncome_asian, moey = MedianHHIncomeMOE_asian),
sigall_wht = stattest(x=MedianHHIncome_wht, moex = MedianHHIncomeMOE_wht, y=MedianHHIncome, moey = MedianHHIncomeMOE),
sig_blk_hisp = stattest(x=MedianHHIncome_blk, moex = MedianHHIncomeMOE_blk, y=MedianHHIncome_hisp, moey = MedianHHIncomeMOE_hisp),
sig_blk_asian = stattest(x=MedianHHIncome_blk, moex = MedianHHIncomeMOE_blk, y=MedianHHIncome_asian, moey = MedianHHIncomeMOE_asian),
sigall_blk = stattest(x=MedianHHIncome_blk, moex = MedianHHIncomeMOE_blk, y=MedianHHIncome, moey = MedianHHIncomeMOE),
sig_hisp_asian = stattest(x=MedianHHIncome_hisp, moex = MedianHHIncomeMOE_hisp, y=MedianHHIncome_asian, moey = MedianHHIncomeMOE_asian),
sigall_hisp = stattest(x=MedianHHIncome_hisp, moex = MedianHHIncomeMOE_hisp, y=MedianHHIncome, moey = MedianHHIncomeMOE),
sigall_asian = stattest(x=MedianHHIncome_asian, moex = MedianHHIncomeMOE_asian, y=MedianHHIncome, moey = MedianHHIncomeMOE)
)
medhh_stat_all <- medhh.race_stattest %>% select(place, placename, (contains("sigall")), (contains("MedianHHIncome") & !contains("MOE"))) %>%
pivot_longer(cols = c(-place, -placename, -contains("sig")), names_to = "race", values_to = "val") %>%
pivot_longer(cols = contains("sig"), names_to = "var", values_to = "stat_all") %>% group_by(place, placename) %>%
mutate(race = case_when(race == "MedianHHIncome" ~ "All",
grepl("asian",race) & grepl("asian",var) ~ "Asian",
grepl("blk",race) & grepl("blk",var) ~ "Black",
grepl("hisp",race) & grepl("hisp",var) ~ "Hispanic, any race",
grepl("wht", race) & grepl("wht",var) ~ "White, non-Hispanic"),
placename = case_when(placename == "New Orleans Metro Area" ~ "Metro",
T ~ placename)) %>% na.omit()
medhh_stat_all$stat_all[medhh_stat_all$race == "All"] <- "yes"
medhh_stat_all <- medhh_stat_all %>% group_by(place, placename, race) %>%
mutate(val_lab = paste0("$", comma(val))) %>% select(-var, -placename) %>% unique()
medhh_stat_race <- medhh.race_stattest %>% select(place, placename, (contains("sig") & !contains("all"))) %>%
pivot_longer(cols = contains("sig"), names_to = "var", values_to = "stat_race") %>% select(-var) %>%
group_by(place, placename) %>%
mutate(placename = case_when(placename == "New Orleans Metro Area" ~ "Metro",
T ~ placename),
placename = case_when("no" %in% stat_race ~ paste0(placename, "*"),
T ~ placename)) %>% select(-stat_race) %>% unique()
medhh_with_stats <- medhh_stat_all %>% left_join(medhh_stat_race, by = "place") %>% unique() %>% filter(race != "All") %>%
mutate(placename.fac = factor(placename.y, levels = c("Orleans*", "Jefferson*", "St. Tammany*", "Metro*", "United States")),
var.fac = factor(race, levels = c("Black","White, non-Hispanic","Asian","Hispanic, any race")))
### Across geos pov bar chart ###
medhh.totals <- medhh_stat_all %>% left_join(medhh_stat_race, by = "place") %>% unique() %>%
filter(race == "All") %>%
mutate(var.fac = factor(race, levels = c("Black","White, non-Hispanic","Asian","Hispanic, any race")),
placename.fac = factor(placename.y, levels = c("Orleans ◊", "Jefferson ◊", "St. Tammany ◊", "Metro ◊", "United States")))
medhh.totals_CSV <- medhh.totals %>% ungroup() %>% select(placename.x, race, val) %>%
mutate(placename.x = ifelse(placename.x == "United States", "U.S.", placename.x)) %>%
pivot_wider(names_from = placename.x, values_from = val)
medhh.race_CSV <- medhh.race %>% select(race = var, place.fac, val) %>%
pivot_wider(names_from = place.fac, values_from = val) %>% rbind(medhh.totals_CSV)
write.csv(medhh.race_CSV, "outputs/spreadsheets/medhhrace.csv")
storage_write_csv(medhh.race_CSV, cont_proj, "who_lives/2024/outputs/medhhrace.csv")
medhh.hist_stattest.EST <- medhhRaw_exp %>%
filter(place == "071") %>%