library(haven)
library(foreign) 
library(readr)
library(dplyr)
library(ggplot2)
library(broom)
library(car)
library(MASS) 
library(lmtest)
library(zoo)
library(nortest)
library(plotrix)
library(scales)
library(tableone)
library(Weighted.Desc.Stat)
library(mitools)
library(survey)
library(VGAM)
library(stargazer)
library(sandwich)
library(pastecs)
library(muhaz)
library(ggpubr)
library(survminer)
library(eha)
library(reshape2)
library(data.table)
library(magrittr)
library(tidyverse)
library(sjmisc)
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(weights)
library(GGally)
library(tigris)
library(RColorBrewer)
library(patchwork)
library(tidycensus)
library(censusapi)
library(spdep)
library(classInt)
library(sf)
library(spatialreg)

This analysis examines segregation between non-Hispanic blacks and whites in California counties and tracts.

Data

track<-  get_acs(geography = "tract",
                         year=2017,
                         geometry = F,
                         output="wide",
                         table = "B02001",
                         cache_table = T,
                         state = "CA")
## Getting data from the 2013-2017 5-year ACS
## Loading ACS5 variables for 2017 from table B02001 and caching the dataset for faster future access.
t<-track%>%
  mutate(nh.w=B02001_002E,
         nh.b= B02001_003E,
         tot=B02001_001E,
         year=2017,
         cofips=substr(GEOID, 1,5))%>%
  dplyr::select(GEOID,nh.w, nh.b ,  tot, year, cofips )%>%
  arrange(cofips, GEOID)

head(t)
## # A tibble: 6 x 6
##   GEOID        nh.w  nh.b   tot  year cofips
##   <chr>       <dbl> <dbl> <dbl> <dbl> <chr> 
## 1 06001400100  2132    84  2991  2017 06001 
## 2 06001400200  1532    18  1997  2017 06001 
## 3 06001400300  3712   482  5123  2017 06001 
## 4 06001400400  2763   239  3991  2017 06001 
## 5 06001400500  2334   951  3944  2017 06001 
## 6 06001400600   801   417  1635  2017 06001
c<-t%>%
  group_by(cofips)%>%
  summarise(co_wht=sum(nh.w),
            co_blk=sum(nh.b),
            co_total=sum(tot))



merged<-left_join(x=t,
                  y=c,
                  by="cofips")
head(merged)
## # A tibble: 6 x 9
##   GEOID        nh.w  nh.b   tot  year cofips co_wht co_blk co_total
##   <chr>       <dbl> <dbl> <dbl> <dbl> <chr>   <dbl>  <dbl>    <dbl>
## 1 06001400100  2132    84  2991  2017 06001  694720 180446  1629615
## 2 06001400200  1532    18  1997  2017 06001  694720 180446  1629615
## 3 06001400300  3712   482  5123  2017 06001  694720 180446  1629615
## 4 06001400400  2763   239  3991  2017 06001  694720 180446  1629615
## 5 06001400500  2334   951  3944  2017 06001  694720 180446  1629615
## 6 06001400600   801   417  1635  2017 06001  694720 180446  1629615

Dissimilarity

co.dis<-merged%>%
  mutate(d.wb=abs(nh.w/co_wht - nh.b/co_blk))%>%
  group_by(cofips)%>%
  summarise(dissim= .5*sum(d.wb, na.rm=T))

head(co.dis)
## # A tibble: 6 x 2
##   cofips dissim
##   <chr>   <dbl>
## 1 06001   0.469
## 2 06003   0    
## 3 06005   0.830
## 4 06007   0.480
## 5 06009   0.492
## 6 06011   0.320

Interaction

co.int<-merged%>%
  mutate(int.bw=(nh.b/co_blk * nh.w/tot))%>%
  group_by(cofips)%>%
  summarise(inter_bw= sum(int.bw, na.rm=T))

head(co.int)
## # A tibble: 6 x 2
##   cofips inter_bw
##   <chr>     <dbl>
## 1 06001     0.354
## 2 06003     0.687
## 3 06005     0.649
## 4 06007     0.765
## 5 06009     0.873
## 6 06011     0.875

Isolation

co.isob<-merged%>%
  mutate(isob=(nh.b/co_blk  * nh.b/tot))%>%
  group_by(cofips)%>%
  summarise(iso_b= sum(isob, na.rm=T))

head(co.isob)
## # A tibble: 6 x 2
##   cofips  iso_b
##   <chr>   <dbl>
## 1 06001  0.236 
## 2 06003  0.0150
## 3 06005  0.138 
## 4 06007  0.0375
## 5 06009  0.0132
## 6 06011  0.0171

Join tables

ca_seg<-list(co.dis, co.int, co.isob)%>% reduce (left_join, by="cofips")
head(ca_seg)
## # A tibble: 6 x 4
##   cofips dissim inter_bw  iso_b
##   <chr>   <dbl>    <dbl>  <dbl>
## 1 06001   0.469    0.354 0.236 
## 2 06003   0        0.687 0.0150
## 3 06005   0.830    0.649 0.138 
## 4 06007   0.480    0.765 0.0375
## 5 06009   0.492    0.873 0.0132
## 6 06011   0.320    0.875 0.0171
descstats<-cbind(co.dis$dissim,co.int$inter_bw,co.isob$iso_b)
options(scipen=10)
options(digits=5)
stat.desc(descstats,basic=F)
##                    V1       V2        V3
## median       0.414107 0.697896 0.0447956
## mean         0.426708 0.680102 0.0721878
## SE.mean      0.018948 0.020781 0.0085752
## CI.mean.0.95 0.037942 0.041613 0.0171715
## var          0.020823 0.025046 0.0042649
## std.dev      0.144301 0.158261 0.0653065
## coef.var     0.338172 0.232701 0.9046745
options(tigris_class = "sf")
ca_counties<- counties(state="CA", cb=T, year=2010)
ca_counties$cofips<-substr(ca_counties$GEO_ID, 10,15)
ca_seg_dat<- geo_join(ca_counties,ca_seg, by_sp="cofips", by_df="cofips")
## Warning: We recommend using the dplyr::*_join() family of functions instead.
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help

Maps of segregation

This map shows higher levels of dissimilarity between non-Hispanic blacks and whites in the area near Yosemite National Park and Reno, Nevada.

This map shows higher levels of isolation for non-Hispanic blacks from whites in the LA and San Francisco area, as well as some suburban areas.

This map shows higher levels of interaction between non-Hispanic blacks and whites in the areas outside of LA and San Francisco area.