-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_clean.R
More file actions
67 lines (49 loc) · 2.33 KB
/
data_clean.R
File metadata and controls
67 lines (49 loc) · 2.33 KB
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
library(tidyverse)
library(readr)
# data clean --------------------------------------------------------------
raw <- read_csv("dta/community_profile_raw.csv")
final <- raw %>%
select(-variable, -code) %>%
write_rds("dta/final_dta.rds")
#generate lookup table
group_lookup <- raw %>%
select(group, variable, code)
#save lookup table
saveRDS(group_lookup, "dta/group_lookup.rds")
#cleanup the data
dta <- raw %>%
filter(variable == "aapi_alone" | variable == "detailed_hisp") %>%
select(-group) %>%
gather(label, estimate, -variable, -code)
#Cutting the dataset by topics
poverty <- dta %>%
filter(label %in% c("pov", "kpov", "spov"))
saveRDS(poverty, "dta/cleaned_poverty.rds")
cvap <- dta %>%
filter(label == "cvap")
saveRDS(cvap, "dta/cleaned_cvap.rds")
age <- dta %>%
# poverty -----------------------------------------------------------------
#pull raw data
dta1 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/aapi_alone_kpov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov_k")
dta2 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/aapi_alone_pov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov")
dta3 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/aapi_alone_spov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov_s")
dta4 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/detailed_hisp_kpov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov_k")
dta5 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/detailed_hisp_pov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov")
dta6 <- read_csv("/Users/sunnyshao/Dropbox/AAPIData HQ/Other Sites/Racial Data/geoprofile_ipums/output tables/detailed_hisp_spov.csv", skip = 2) %>%
rename(group=`0`, estimate = `X2`) %>%
mutate(label = "pov_s")
#merge into one
poverty <- rbind(dta1, dta2, dta3, dta4, dta5, dta6)
saveRDS(poverty, "dta/cleaned_poverty.RDS")
# cvap --------------------------------------------------------------------