#Perform an extract of the 2019 5 Year ACS data:
library(ipumsr)
## Warning: package 'ipumsr' was built under R version 4.1.3
ddi <- read_ipums_ddi("C:/Users/shahi/OneDrive - University of Texas at San Antonio/Desktop/Spring'22/Dem 5093 (GIS)/usa_00006.xml")
data <- read_ipums_micro(ddi)
## Use of data from IPUMS USA is subject to conditions including that users should
## cite the data appropriately. Use command `ipums_conditions()` for more details.
data<-haven::zap_labels(data) #necessary to avoid problems with "labelled" data class
names(data)<-tolower(names(data))
library(survey, quietly = T)
library(tidyverse, quietly = T)
library(car, quietly = T)
library(ggplot2, quietly = T)
library(tigris, quietly = T)
library(classInt, quietly = T)
library(tmap, quietly = T)
library(janitor,quietly = T)
## Warning: package 'janitor' was built under R version 4.1.3
library(mapview, quietly= T)
library(knitr, quietly = T)
#Using these data, create estimates for Californian PUMAs of the % of the population that lived in the same house last year:
options(tigris_class = "sf")
pumas<-pumas(state = "CA",
year = 2019,
cb = T)
##
|
| | 0%
|
|= | 2%
|
|=== | 5%
|
|===== | 7%
|
|====== | 8%
|
|======= | 11%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 16%
|
|============ | 17%
|
|============== | 19%
|
|=============== | 22%
|
|================ | 23%
|
|================== | 26%
|
|==================== | 28%
|
|====================== | 32%
|
|======================== | 35%
|
|========================== | 37%
|
|============================ | 40%
|
|============================== | 44%
|
|================================== | 49%
|
|===================================== | 52%
|
|====================================== | 55%
|
|======================================== | 58%
|
|=========================================== | 61%
|
|============================================ | 63%
|
|=============================================== | 67%
|
|================================================= | 70%
|
|================================================== | 72%
|
|===================================================== | 75%
|
|======================================================= | 79%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================= | 87%
|
|================================================================= | 93%
|
|=================================================================== | 96%
|
|======================================================================| 100%
plot(pumas["GEOID10"],
main = "Public Use Microdata Areas in California")
mapview::mapview(pumas, zcol= "GEOID10")
Here I recode several demographic variables
data$pwt <- data$perwt
data$hwt <- data$hhwt
#Migration
data$migration<- Recode(data$migrate1, recodes = "1=1; 2:4=0; else=NA")
Here we identify the person weights and the survey design variables.
des<-svydesign(ids = ~cluster,
strata = ~ strata,
weights = ~pwt,
data = data)
puma_est_migration<-svyby( ~I(migration==1),
by = ~puma,
design = des,
FUN=svymean,
na.rm = TRUE ) %>%
clean_names() %>%
mutate(Pctsh=round((i_migration_1_true*100),1), Pctnsh=round((i_migration_1_false*100),1)) %>%
rename(propnsh=i_migration_1_false,
propsh=i_migration_1_true,
Stderr=se_i_migration_1_true) %>%
select(puma,Pctsh,Pctnsh,Stderr)
pumas<- pumas(state = "CA",
year = 2019,
cb= T) %>%
mutate(puma=as.numeric(PUMACE10))
geo1<-left_join(pumas, puma_est_migration, by=c("puma"= "puma"))
tmap_mode("view")
## tmap mode set to interactive viewing
tm_basemap("OpenStreetMap.Mapnik")
tm_shape(geo1)+
tm_polygons("Pctsh",
style="kmeans",
title=c("Percent Estimates"),
palette="Blues",
n=8,
legend.hist = TRUE) +
tm_layout(legend.outside = TRUE,
title = "Percent of the population living in the same house in California PUMAs \n 2015-2019",
title.size =1.5,
legend.frame = TRUE,
) + tm_compass(position = c("left","top")) + tm_format("World",
legend.position = c("left", "bottom"),
main.title.position =c("center")) + tm_scale_bar(position = c("left","bottom"))
## Compass not supported in view mode.
## legend.postion is used for plot mode. Use view.legend.position in tm_view to set the legend position in view mode.