Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kate #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Years of Schooling/code/distribution/ingest_va.R
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a more detailed explanation of these weights might be appreciated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! let me know if there's anything more to be added

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ get_ays <- function(acs_data, tract_geoid) {
pop <- tract_data[tract_data$variable %in% c("B15003_001"), c("estimate")][[1]]

# value assigned to each grade level (no schooling, nursery school, kindergarten each assigned 0)
values <- c("005" = 1, "006" = 2, "007" = 3, "008" = 4, "009" = 5, "010" = 6,
"011" = 7, "012" = 8, "013" = 9, "014" = 10, "015" = 11, "016" = 12,
"017" = 12, "018" = 12, "019" = 12.5, "020" = 13, "021" = 14,
values <- c("005" = 2.5, "006" = 2.5, "007" = 2.5, "008" = 2.5, "009" = 5.5, "010" = 5.5,
"011" = 7.5, "012" = 7.5, "013" = 9, "014" = 10, "015" = 11, "016" = 11,
"017" = 12, "018" = 12, "019" = 13, "020" = 13, "021" = 14,
"022" = 16, "023" = 18, "024" = 19, "025" = 20)

ays <- 0
Expand Down Expand Up @@ -99,25 +99,25 @@ for (yr in c(2021, 2020, 2019, 2018, 2017)) {
# Get the data for the current year
acsdata_year <- acs_yos %>% filter(year==yr)

tract_ays <- NULL
ct_ays <- NULL

# Calculate AYS for all tracts
unq_tracts <- unique(acsdata_year$GEOID)
for (t in unq_tracts) {
ays_t <- get_ays(acsdata_year, t)

tract_ays <- rbind(tract_ays, data.frame(GEOID=c(t), value=c(ays_t)))
ct_ays <- rbind(ct_ays, data.frame(GEOID=c(t), value=c(ays_t)))
}

acsdata_year <- acsdata_year %>% group_by(GEOID) %>% summarise(year=first(year), moe='')
acsdata_year <- merge(acsdata_year, tract_ays, by='GEOID')
acsdata_year <- merge(acsdata_year, ct_ays, by='GEOID')

all_ct <- rbind(all_ct, acsdata_year)
}

all_ct <- all_ct %>% filter(!is.nan(value)) %>% rename(geoid=GEOID)

# combine tract, county, health district data
# combine tract, county data
tr_ct <- rbind(all_tr, all_ct)

readr::write_csv(tr_ct, xzfile('Years of Schooling/data/working/va_trct_acs5_2017_2021_years_of_schooling.csv', compression=9))
Expand All @@ -126,6 +126,10 @@ readr::write_csv(tr_ct, xzfile('Years of Schooling/data/working/va_trct_acs5_201
# select('CT2', 'Education')
#
# merged <- merge(testing, all_tr %>% filter(year==2020) %>% mutate(value1=round(value, 1)), by.x='CT2', by.y='geoid')
#
# diffs <- merged %>% mutate(diffs = (Education - value1)/(mean(Education + value1)))
# mean(diffs$diffs) * 100
# max(diffs$diffs) * 100
# ggplot(merged, aes(x=Education, y=value1)) + geom_point() + geom_abline(slope=1)


Expand Down
1 change: 1 addition & 0 deletions Years of Schooling/code/distribution/prepare_va.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ all <- rbind(ct_hd, dat_fin_tr)

# fwrite(dat_fin, "Years of Schooling/data/distribution/va_tr_acs5_2017_2021_years_of_schooling.csv")
readr::write_csv(all, xzfile("Years of Schooling/data/distribution/va_hdcttr_acs5_2017_2021_years_of_schooling.csv.xz", compression = 9))

Binary file not shown.
Binary file not shown.