library(ipumsr)
## Warning: package 'ipumsr' was built under R version 4.1.3
ddi <- read_ipums_ddi("C:/Users/drayr/OneDrive/Desktop/DEM Spring 2022/DEM 7093/HW7/usa_00010.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)
names(data)<-tolower(names(data))
library(survey, quietly = T)
## Warning: package 'survey' was built under R version 4.1.3
library(tidyverse, quietly = T)
library(car, quietly = T)
## Warning: package 'car' was built under R version 4.1.3
## Warning: package 'carData' was built under R version 4.1.3
library(ggplot2, quietly = T)
library(tigris, quietly = T)
library(classInt, quietly = T)
library(tmap, quietly = T)
The Public Use Microdata Area is the lowest level of geography in the PUMS data. They correspond to greographic ares of ~ 100,000 people.
options(tigris_class = "sf")
pumas<-pumas(state = "CA",
year = 2019,
cb = T)
##
|
| | 0%
|
|= | 2%
|
|=== | 4%
|
|=== | 5%
|
|===== | 7%
|
|====== | 8%
|
|======= | 11%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 16%
|
|============ | 17%
|
|============== | 19%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 25%
|
|================== | 26%
|
|==================== | 28%
|
|====================== | 32%
|
|======================== | 34%
|
|======================== | 35%
|
|========================== | 37%
|
|============================ | 40%
|
|============================== | 44%
|
|================================ | 46%
|
|================================== | 48%
|
|================================== | 49%
|
|==================================== | 51%
|
|===================================== | 52%
|
|====================================== | 55%
|
|======================================== | 58%
|
|=========================================== | 61%
|
|=============================================== | 67%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 72%
|
|==================================================== | 74%
|
|===================================================== | 75%
|
|======================================================= | 79%
|
|========================================================= | 81%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|=============================================================== | 90%
|
|================================================================= | 93%
|
|=================================================================== | 96%
|
|===================================================================== | 98%
|
|======================================================================| 100%
plot(pumas["GEOID10"],
main = "Public Use Microdata Areas in California")
mapview::mapview(pumas, zcol= "GEOID10")
data$pwt <- data$perwt
data$hwt <- data$hhwt
#citizenship
data$mig<-Recode(data$migrate1, recodes = "1='Same House'; 2:4='mover'; 3:4='notcitizen';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_mig<-svyby(formula = ~mig,
by = ~puma,
design = des,
FUN=svymean,
na.rm = TRUE )
head(puma_est_mig)
pumas$puma<-as.numeric(pumas$PUMACE10)
geo1<-left_join(pumas, puma_est_mig, by=c("puma"= "puma"))
head(geo1)
tmap_mode("view")
## tmap mode set to interactive viewing
geo1%>%
tm_shape()+
tm_polygons("migSame House",
style="kmeans",
n=8,
legend.hist = TRUE) +
tm_layout(legend.outside = TRUE,
title = "Same House in California PUMAs \n 2015-2019")