Maintain and use geo_dictionary
Gradient Metrics
2025-10-16
Source:vignettes/create_geo_dictionary.Rmd
create_geo_dictionary.RmdThis vignette focuses on maintaining and using
geo_dictionary. This data contains metadata that describe
in a systematic way which variables from ACS should be
selected and how to process them.
If you are going to update geo_dictionary dataset,
please follow the instructions below and follow the rules of creating
data for packages (refer to: R
Packages: External Data). You should reuse the code stored in
data-raw folder under DATASET.R file. After
creating new geo_dictionary dataset, remember to update
data files in package: ds_state_acs_raw.rds,
ds_county_acs_raw.rds, ds_regions_acs_raw.rds
and ds_zip_acs_raw.csv file that is stored on
S3.
Selecting variables from ACS dataset
ACS data set from 2019 is made of 27040 variables (called
labels,
e.g. Estimate!!Total:!!Male:!!Under 5 years) grouped in
1135 concepts (e.g. SEX BY AGE). Most of these
concepts are out of our scope of interest. Moreover we also do not need
many of the variables from concepts that are of interest, or we would
like to have some of the variables grouped (e.g. we would like to use
less detailed breaks for household income variables). Finding
proper names of labels and concepts is a
cumbersome task, especially when you try to do it directly in code. That
is why here, we will use a hybrid approach where we will create and
alter **Excel* files, which allow for easy selecting variables that we
need in geo_dictionary set.
Step 1: Selecting concepts
First we need an Excel file with that will contain all
the concept names and a column indicating if the concept should be
included in final dictionary file. This file is already created and
stored on shared drive in Google Drive in Geo
AXC Dictionary under ACS_concepts_list_df.xlsx. It contains 3
sheets: all_concepts_list,
included_concepts_list and
excluded_concepts_list.
In the case you wish to include or exclude concepts that will be
stored in geo_dictionary dataset, please follow step
below:
- Go to
all_concepts_listsheet. - In the column
Includedput 0 for concepts that are not needed and 1 for concepts that are going to be included ingeo_dictionary. - Delete all the rows besides firs in
included_concepts_listandexcluded_concepts_list. - Use autofilter in
Includedcolumn fromall_concepts_listand select only 1. - Copy the resulting rows to
included_concepts_list. - Use autofilter in
Includedcolumn fromall_concepts_listand select only 0. - Copy the resulting rows to
exluded_concepts_list.
When finished you can read the file and clean concept names using
following code from DATASET.R:
#Folder Google Drive ID
geo_acs_dict_id <- as_id("1A3EJU8PzYkGqPYRB_bQXpd0GT8kL-Pgq")
# After downloading move the file from top dir to data-raw/
# and change the name by adding yyyymmdd_
googledrive::drive_download(
file = "ACS_concepts_list_df.xlsx",
path = geo_acs_dict_id,
type = "xlsx"
)
# Make df with selected concepts
acs_concept_df <- readxl::read_xlsx(
paste0(getwd(), "/data-raw/20211014_ACS_concepts_list_df.xlsx"),
sheet = "included_concepts_list"
)
# RECODING CONCEPTS ----
concept_recode_df <- tibble::tribble(
~concept, ~concept_short,
"SEX BY AGE", "sex_age",
"MEDIAN AGE BY SEX", "med_age_sex",
"TOTAL POPULATION", "population",
"RACE", "race",
"HISPANIC OR LATINO ORIGIN", "hispanic_latino",
"NATIVITY AND CITIZENSHIP STATUS IN THE UNITED STATES", "nativity",
"AGGREGATE TRAVEL TIME TO WORK (IN MINUTES) OF WORKERS BY SEX", "agg_work_travel",
"AGGREGATE NUMBER OF VEHICLES (CAR, TRUCK, OR VAN) USED IN COMMUTING BY WORKERS 16 YEARS AND OVER BY SEX", "agg_n_vehicles",
"MEDIAN AGE BY MEANS OF TRANSPORTATION TO WORK", "med_age_transportation",
"HOUSEHOLD SIZE BY VEHICLES AVAILABLE", "hhsize_vehicles",
"MEANS OF TRANSPORTATION TO WORK", "transportation",
"TIME OF DEPARTURE TO GO TO WORK", "work_departure",
"TRAVEL TIME TO WORK", "work_travel",
"POPULATION UNDER 18 YEARS BY AGE", "pop_u18",
"OWN CHILDREN UNDER 18 YEARS BY FAMILY TYPE AND AGE", "children_u18",
"MEDIAN AGE AT FIRST MARRIAGE", "med_age_first_marriage",
"MEDIAN DURATION OF CURRENT MARRIAGE IN YEARS BY SEX BY MARITAL STATUS FOR THE MARRIED POPULATION 15 YEARS AND OVER", "med_marriage_duration",
"TOTAL FIELDS OF BACHELOR'S DEGREES REPORTED", "bachelor_field",
"LANGUAGE SPOKEN AT HOME BY ABILITY TO SPEAK ENGLISH FOR THE POPULATION 5 YEARS AND OVER", "language_english_ability",
"POVERTY STATUS IN THE PAST 12 MONTHS BY AGE", "poverty",
"HOUSEHOLD INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS)", "hhincome",
"MEDIAN HOUSEHOLD INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS)", "med_hhincome",
"AGGREGATE HOUSEHOLD INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS)", "agg_hhincome",
"WAGE OR SALARY INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_salary",
"SELF-EMPLOYMENT INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_self_employed",
"INTEREST, DIVIDENDS, OR NET RENTAL INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_dividends",
"SOCIAL SECURITY INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_social_security",
"SUPPLEMENTAL SECURITY INCOME (SSI) IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_suplemental_security",
"PUBLIC ASSISTANCE INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_public_assistance",
"PUBLIC ASSISTANCE INCOME OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_assistance_stamps",
"RETIREMENT INCOME IN THE PAST 12 MONTHS FOR HOUSEHOLDS", "hhincome_retirement",
"AGGREGATE EARNINGS IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS) FOR HOUSEHOLDS", "agg_earnings",
"HOUSEHOLD INCOME QUINTILE UPPER LIMITS", "hhincome_quintile",
"GINI INDEX OF INCOME INEQUALITY", "gini_index",
"PER CAPITA INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS)", "per_capita_income",
"AGGREGATE INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS)", "agg_income",
"MEAN USUAL HOURS WORKED IN THE PAST 12 MONTHS FOR WORKERS 16 TO 64 YEARS", "mean_hours_worked",
"EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER", "employment_status",
"HOUSING UNITS", "housing_units",
"TENURE", "tenure",
"AVERAGE HOUSEHOLD SIZE OF OCCUPIED HOUSING UNITS BY TENURE", "avg_hhsize_tenure",
"ROOMS", "rooms",
"MEDIAN NUMBER OF ROOMS", "med_rooms",
"AGGREGATE NUMBER OF ROOMS", "agg_rooms",
"MEDIAN GROSS RENT BY BEDROOMS", "med_rent_bedrooms",
"YEAR STRUCTURE BUILT", "house_year_built",
"MEDIAN YEAR STRUCTURE BUILT", "med_year_built",
"HOUSE HEATING FUEL", "heating",
"BEDROOMS", "bedrooms",
"LOWER CONTRACT RENT QUARTILE (DOLLARS)", "lower_q_rent",
"MEDIAN CONTRACT RENT (DOLLARS)", "med_contract_rent",
"UPPER CONTRACT RENT QUARTILE (DOLLARS)", "upper_q_rent",
"MEDIAN GROSS RENT (DOLLARS)", "med_gross_rent",
"VALUE", "house_value",
"MORTGAGE STATUS", "house_mortgage",
"SELECTED MONTHLY OWNER COSTS", "house_month_cost",
"MORTGAGE STATUS BY MEDIAN VALUE (DOLLARS)", "med_house_value_mortage",
"MEDIAN MONTHLY HOUSING COSTS (DOLLARS)", "med_monthly_housing_cost",
"HEALTH INSURANCE COVERAGE STATUS BY SEX BY AGE", "insurance",
"PRIVATE HEALTH INSURANCE STATUS BY SEX BY AGE", "insurance_private",
"PUBLIC HEALTH INSURANCE STATUS BY SEX BY AGE", "insurance_public",
"COMPUTERS IN HOUSEHOLD", "hh_computer",
"INTERNET SUBSCRIPTIONS IN HOUSEHOLD", "hh_internet",
)Next download the data from ACS, do the basic label cleaning and join it with data.frame containing abbreviated concept names. This code should be adjusted if needed.
v19 <- load_variables(2019, "acs5", cache = TRUE)
# Clean the labels----
acs_labels_partial_clean_df <- v19 %>%
dplyr::filter(concept %in% acs_concept_df$Concept) %>%
dplyr::mutate(
label_clean = str_replace(label, "Estimate!!Total:!!", ""),
label_clean = str_replace(label_clean, "Estimate!!Total:", "Total"),
label_clean = str_replace(label_clean, "Estimate!!Total", "Total"),
label_clean = str_replace(label_clean, "Estimate!!Median age --!!Total", "Total"),
label_clean = str_replace(label_clean, "Estimate!!Average household size --!!Total", "Total"),
label_clean = str_replace(label_clean, "Estimate!!Mean usual hours--!!Total", "Total"),
label_clean = str_replace_all(label_clean, " :!!", " "),
label_clean = str_replace_all(label_clean, ":!!", " "),
label_clean = str_replace_all(label_clean, "!!", " "),
label_clean = str_replace_all(label_clean, ":$", ""),
label_clean = str_replace_all(label_clean, "\\$", "USD"),
label_clean = str_replace_all(label_clean, "!!", " "),
label_clean = str_replace_all(label_clean, "a\\.m\\.", "_am_"),
label_clean = str_replace_all(label_clean, "p\\.m\\.", "_pm_"),
label_clean = str_replace_all(label_clean, " years", "y"),
label_clean = str_replace_all(label_clean, " year", "y"),
label_clean = str_replace_all(label_clean, "\"", ""),
label_clean = str_replace_all(label_clean, "month", "MTH"),
label_clean = ifelse(str_detect(name, "01$"), "Total", label_clean)
) %>%
group_by(name) %>%
mutate(
concept_label = paste(concept, label_clean, sep = " | ")
)
acs_labels_partial_clean_df <- acs_labels_partial_clean_df %>%
left_join(concept_recode_df)The pre-filtered dataset is now ready. It should be uploaded to
Google Drive, so it is easier to decide which variables
(labels) should be eventually included into data set.
# Update name of file with proper data in ISO format
acs_labels_partial_clean_df %>%
writexl::write_xlsx(
paste0(
dir_raw_data,
"20211018_acs_labels_partial_clean_df.xlsx"
)
)
googledrive::drive_upload(
media = paste0(
dir_raw_data,
"20211018_acs_labels_partial_clean_df.xlsx"
),
path = geo_acs_dict_id,
overwrite = TRUE,
type = 'spreadsheet'
)Step 2: Selecting variables (labels)
In the next step we should add a column named
include_label where we put 1 when the particular variable
should be included in geo_dictionary and 0 when not. After
all the variables are marked 0 or 1, please select only those with value
1 with filter and copy them to new sheet called
included_labs. For reference please check the file that is
already stored on Google Drive under name 20211018_acs_labels_partial_clean_df.xlsx.
You should now download the file from Google Drive and change its name to keep steps separate:
# Download file with label that needs to be included ----
# rename to yyyymmdd_acs_labels_partial_clean_include_df.xlsx
googledrive::drive_download(
file = "20211018_acs_labels_partial_clean_df.xlsx",
path = michal_drive_id,
type = "xlsx"
)
acs_labels_include_df <- readxl::read_xlsx(
paste0(getwd(), "/data-raw/20211018_acs_labels_partial_clean_include_df.xlsx"),
sheet = "included_labs"
)Step 3: cleaning names and finalizing
geo_dictionary
Our geo_dictionary should have column with names for
variables that will be included in datasets. To keep things clean the
names (stored in var_name column) will be derived from
concept_short and abbreviated label name (stored in
label_short column. Unfortunately, there is no good way to
abbreviate the names of labels automatically and simultaneously keep
those abbreviations meaningful. Also, we should not do this
manually, so our workflow can be reproduced and we keep track
of what was done. Last but not least, we need another column –
combined_var that will allow us to merge some of the labels
into different breaks (e.g. into wider breaks of household
income). The variables that will be NOT collapsed
will have the same name as in var_name, the rest needs new
name.
The solution is to keep all the changes in code. Below code chunk was
used to create current version of geo_dictionary. Should
you ever be in need to maintain or change geo_dictionary
please adjust the code below.
Some of the concepts might have total variable. Mostly the
number will exactly same as the number for population
variable. Unfortunately sometimes it will be different. Since we need to
calculate ratio subvariables (like Male for
Sex by Age concept) to the totals we will preserve
this variables in the final dataset. In order to automatically calculate
the ratios with geo_tidy_acs_data please add
_n suffix to the total variables names.
acs_labels_include_df <-
acs_labels_include_df %>%
mutate(
label_short = str_replace_all(label_clean, "Total", "n"),
label_short = str_replace_all(label_short, "Male", "m"),
label_short = str_replace_all(label_short, "Female", "f"),
label_short = str_replace(label_short, "Under", "u"),
label_short = str_replace(label_short, "m ", "m_"),
label_short = str_replace(label_short, "f ", "f_"),
label_short = str_replace(label_short, "Estimate Median age --", ""),
label_short = str_replace(label_short, "Hispanic or Latino", "yes"),
label_short = str_replace(label_short, "Puerto Rico", "PR"),
label_short = str_replace(label_short, "U\\.S\\. citizen, born in ", "us_citizen"),
label_short = str_replace(label_short, "the United States", "_us"),
label_short = str_replace(label_short, "PR or U\\.S\\. Island Areas", "_pr"),
label_short = str_replace(label_short, "U\\.S\\. citizen, born abroad of_American parent\\(s\\)", "abroad"),
label_short = str_replace(label_short, "U\\.S\\. citizen by naturalization", "_naturalization"),
label_short = str_replace(label_short, "Not a U\\.S\\. citizen", "_non_us_citizen"),
label_short = str_replace(label_short, "Estimate Aggregate travel time to work \\(in minutes\\) m", "male"),
label_short = str_replace(label_short, "Estimate Aggregate travel time to work \\(in minutes\\) f", "female"),
label_short = str_replace(label_short, "Estimate Aggregate number of_vehicles \\(car, truck, or van\\) used in commuting m", "male"),
label_short = str_replace(label_short, "Estimate Aggregate number of_vehicles \\(car, truck, or van\\) used in commuting f", "female"),
label_short = str_replace(label_short, "n Car, truck, or van \\- drove alone", "car_alone"),
label_short = str_replace(label_short, "n Car, truck, or van \\- carpooled", "carpooled"),
label_short = str_replace(label_short, "n Public transportation \\(excluding taxicab\\)", "pub_transport_excl_taxi"),
label_short = str_replace(label_short, "n Walked", "walked"),
label_short = str_replace(label_short, "n Taxicab, motorcycle, bicycle, or other means", "other"),
label_short = str_replace(label_short, "n Worked from_home", "wfh"),
label_short = str_replace(label_short, "Worked from_home", "wfh"),
label_short = str_replace(label_short, "Public transportation \\(excluding taxicab\\)", "pub_transportation_excl_taxi"),
label_short = str_replace(label_short, " Ferryboat", "_ferryboat"),
label_short = str_replace(label_short, "drove alone ", "alone_"),
label_short = str_replace(label_short, "Drove alone", "alone"),
label_short = str_replace(label_short, " or more minutes", "_mm"),
label_short = str_replace(label_short, " minutes", "_m"),
label_short = str_replace(label_short, "Less than ", "less_"),
label_short = str_replace(label_short, "\\- ", "_"),
label_short = str_replace(label_short, "Estimate Median age at first marriage -_f", "female"),
label_short = str_replace(label_short, "Science and Engineering ", ""),
label_short = str_replace(label_short, "Computers, Mathematics and Statistics", "math_statistics"),
label_short = str_replace(label_short, "Biological, Agricultural, and Environmental Sciences", "biology_agriculture"),
label_short = str_replace(label_short, "Physical and Related Sciences", "physical"),
label_short = str_replace(label_short, "Multidisciplinary ", "mutli_"),
label_short = str_replace(label_short, "Arts, Humanities, and Other ", "arts_humanities_"),
label_short = str_replace(label_short, "Literature and Languages", "literature"),
label_short = str_replace(label_short, "Literature and Languages", "literature"),
label_short = str_replace(label_short, "Liberal Arts and History", "history"),
label_short = str_replace(label_short, "Visual and Performing Arts", "visual"),
label_short = str_replace(label_short, "Income in the past 12 [:print:]*", "below"),
label_short = str_replace(label_short, "Speak only English", "only_eng"),
label_short = str_replace(label_short, "With wage or salary income", "yes"),
label_short = str_replace(label_short, "With self-employment income", "yes"),
label_short = str_replace(label_short, "With interest, dividends, or net rental income", "yes"),
label_short = str_replace(label_short, "With Social Security income", "yes"),
label_short = str_replace(label_short, "With Supplemental Security Income \\(SSI\\)", "yes"),
label_short = str_replace(label_short, "With public assistance income", "yes"),
label_short = str_replace(label_short, "With cash public assistance or Food Stamps/SNAP", "yes"),
label_short = str_replace(label_short, "With retirement income", "yes"),
label_short = str_replace(label_short, "Estimate Quintile Upper Limits Second Quintile", "2_n"),
label_short = str_replace(label_short, "Estimate Quintile Upper Limits Third Quintile", "3_n"),
label_short = str_replace(label_short, "Estimate Quintile Upper Limits Fourth Quintile", "4_n"),
label_short = str_replace(label_short, "Estimate Lower Limit of_Top 5 Percent", "top5percent_n"),
label_short = str_replace(label_short, "n f", "_female"),
label_short = str_replace(label_short, "n m", "_male"),
label_short = str_replace(label_short, "In labor force Civilian labor force Unemployed", "labor_force_civilian_unemployed"),
label_short = str_replace(label_short, "In labor force Civilian labor force Employed", "labor_force_civilian_employed"),
label_short = str_replace(label_short, "In labor force Civilian labor force", "labor_force_civilian_yes"),
label_short = str_replace(label_short, "In labor force Armed Forces", "labor_force_armed_yes"),
label_short = str_replace(label_short, "Not in labor force", "labor_no"),
label_short = str_replace(label_short, "In labor force", "labor_yes"),
label_short = str_replace(label_short, "Owner occupied", "owner"),
label_short = str_replace(label_short, "Renter occupied", "renter"),
label_short = str_replace(label_short, "n owner", "owner"),
label_short = str_replace(label_short, "n renter", "renter"),
label_short = str_replace(label_short, " or more rooms", "_more"),
label_short = str_replace(label_short, " rooms| room", ""),
label_short = str_replace(label_short, "Estimate Median gross rent \\-_n ", ""),
label_short = str_replace(label_short, " bedrooms", ""),
label_short = str_replace(label_short, " bedroom", ""),
label_short = str_replace(label_short, " or more", "_more"),
label_short = str_replace(label_short, " or later", "_later"),
label_short = str_replace(label_short, " or earlier", "_earlier"),
label_short = str_replace(label_short, "Bottled, tank, or LP gas", "tank_lp_gas"),
label_short = str_replace(label_short, "Housing units with a mortgage[:print:]*", "with"),
label_short = str_replace(label_short, "Housing units without a mortgage", "without"),
label_short = str_replace(label_short, "Estimate Median value \\-_n Median value for units with a mortgage", "with"),
label_short = str_replace(label_short, "Estimate Median value \\-_n Median value for units without a mortgage", "without"),
label_short = str_replace(label_short, " With health insurance coverage", "_health_ins"),
label_short = str_replace(label_short, " With private health insurance", "_pirv_health_ins"),
label_short = str_replace(label_short, " With public coverage", "_pub_health_ins"),
label_short = str_replace(label_short, "Has one_more types of_computing devices", "yes"),
label_short = str_replace(label_short, "No Computer", "no"),
label_short = str_replace(label_short, "With an Internet subscription", "yes"),
label_short = str_replace(label_short, "No Internet access", "no"),
label_short = str_replace(label_short, "White alone", "white"),
label_short = str_replace(label_short, "Asian alone", "asian"),
label_short = str_replace(label_short, "Black or African American alone", "black"),
label_short = str_replace(label_short, "American Indian and Alaska Native alone", "native_am"),
label_short = str_replace(label_short, "Native Hawaiian and Other Pacific Islander alone", "pacific_islander"),
label_short = str_replace(label_short, "Some other race alone", "other"),
label_short = str_replace(label_short, "Two_more races Two races excluding[:print:]*", "two_no_other"),
label_short = str_replace(label_short, "Two_more races Two races including[:print:]*", "two_other"),
label_short = str_replace(label_short, "Two_more races", "two"),
label_short = str_replace_all(label_short, "Car, truck, or van", "cars"),
label_short = str_replace_all(label_short, "to |_$|Built ", ""),
label_short = str_replace_all(label_short, " ", "_"),
label_short = tolower(label_short)
) %>%
mutate(
var_name = paste(concept_short, label_short, sep = "_"),
var_name = str_replace(var_name, "hhincome_quintile_n", "hhincome_quintile_1_n"),
var_name = str_replace_all(var_name, "[_]{2,3}", "_")
) %>%
mutate(
combined_var = case_when(
str_detect(var_name, "nativity_us") |
var_name %in% c(
"nativity_naturalization", "nativity_abroad"
) ~ "nativity_us_citizen",
var_name == "work_departure_4:00_pm_11:59_pm" ~ "work_departure_evening",
var_name == "work_departure_12:00_pm_3:59_pm" ~ "work_departure_afternoon",
var_name %in% c(
"work_departure_12:00_am_4:59_am", "work_departure_5:00_am_5:29_am",
"work_departure_5:30_am_5:59_am", "work_departure_6:00_am_6:29_am",
"work_departure_6:30_am_6:59_am"
) ~ "work_departure_night",
var_name %in% c(
"work_departure_7:00_am_7:29_am", "work_departure_7:30_am_7:59_am",
"work_departure_8:00_am_8:29_am", "work_departure_8:30_am_8:59_am",
"work_departure_9:00_am_9:59_am", "work_departure_10:00_am_10:59_am",
"work_departure_11:00_am_11:59_am"
) ~ "work_departure_morning",
var_name %in% c(
"work_travel_less_5_m", "work_travel_5_9_m",
"work_travel_10_14_m", "work_travel_15_19_m"
) ~ "work_travel_20m_less",
var_name %in% c(
"work_travel_20_24_m", "work_travel_25_29_m",
"work_travel_30_34_m", "work_travel_35_39_m"
) ~ "work_travel_20m_40m",
var_name %in% c(
"work_travel_40_44_m", "work_travel_45_59_m",
"work_travel_60_89_m"
) ~ "work_travel_40m_90m",
var_name %in% c("work_travel_90_mm") ~ "work_travel_90m_plus",
str_detect(var_name, "bachelor_field_arts") ~ "bachelor_field_arts_humanities",
var_name %in% c(
"hhincome_less_usd10,000", "hhincome_usd10,000_usd14,999",
"hhincome_usd15,000_usd19,999", "hhincome_usd20,000_usd24,999"
) ~ "hhincome_25_less",
var_name %in% c(
"hhincome_usd25,000_usd29,999", "hhincome_usd30,000_usd34,999",
"hhincome_usd35,000_usd39,999", "hhincome_usd40,000_usd44,999",
"hhincome_usd45,000_usd49,999"
) ~ "hhincome_25_50",
var_name %in% c(
"hhincome_usd50,000_usd59,999",
"hhincome_usd60,000_usd74,999"
) ~ "hhincome_50_75",
var_name %in% c("hhincome_usd75,000_usd99,999") ~ "hhincome_75_100",
var_name %in% c(
"hhincome_usd100,000_usd124,999", "hhincome_usd125,000_usd149,999"
) ~ "hhincome_100_150",
var_name == "hhincome_usd150,000_usd199,999" ~ "hhincome_150_200",
var_name == "hhincome_usd200,000_more" ~ "hhincome_200_more",
var_name %in% c(
"house_value_less_usd10,000", "house_value_usd10,000_usd14,999",
"house_value_usd15,000_usd19,999", "house_value_usd20,000_usd24,999",
"house_value_usd25,000_usd29,999", "house_value_usd30,000_usd34,999",
"house_value_usd35,000_usd39,999", "house_value_usd40,000_usd49,999",
"house_value_usd50,000_usd59,999", "house_value_usd60,000_usd69,999",
"house_value_usd70,000_usd79,999", "house_value_usd80,000_usd89,999",
"house_value_usd90,000_usd99,999"
) ~ "house_value_100_less",
var_name %in% c(
"house_value_usd100,000_usd124,999", "house_value_usd125,000_usd149,999",
"house_value_usd150,000_usd174,999", "house_value_usd175,000_usd199,999"
) ~ "house_value_100_200",
var_name %in% c(
"house_value_usd200,000_usd249,999", "house_value_usd250,000_usd299,999",
"house_value_usd300,000_usd399,999", "house_value_usd400,000_usd499,999"
) ~ "house_value_200_500",
var_name %in% c(
"house_value_usd500,000_usd749,999", "house_value_usd750,000_usd999,999"
) ~ "house_value_500_1m",
var_name %in% c(
"house_value_usd1,000,000_usd1,499,999", "house_value_usd1,500,000_usd1,999,999"
) ~ "house_value_1m_2m",
var_name == "house_value_usd2,000,000_more" ~ "house_value_2m_plus",
var_name %in% c(
"house_month_cost_less_usd200", "house_month_cost_usd200_usd299",
"house_month_cost_usd300_usd399", "house_month_cost_usd400_usd499",
"house_month_cost_usd500_usd599", "house_month_cost_usd600_usd699",
"house_month_cost_usd700_usd799", "house_month_cost_usd800_usd899",
"house_month_cost_usd900_usd999"
) ~ "house_month_cost_1000_less",
var_name %in% c(
"house_month_cost_usd1,000_usd1,249", "house_month_cost_usd1,250_usd1,499",
"house_month_cost_usd1,500_usd1,999"
) ~ "house_month_cost_1000_2000",
var_name %in% c(
"house_month_cost_usd2,000_usd2,499", "house_month_cost_usd2,500_usd2,999"
) ~ "house_month_cost_2000_3000",
var_name %in% c(
"house_month_cost_usd3,000_usd3,499", "house_month_cost_usd3,500_usd3,999"
) ~ "house_month_cost_3000_4000",
var_name == "house_month_cost_usd4,000_more" ~ "house_month_cost_4000_plus",
TRUE ~ var_name
)
) %>%
select(name, concept, concept_short, label_clean, var_name, combined_var)To finalize, please store the final table on Google Drive and update
geo_dictionary in package data:
# Remember to update date in the file name with correct ISO value
acs_labels_include_df %>%
writexl::write_xlsx(
paste0(
dir_raw_data,
"20211018_acs_labels_included_df.xlsx"
)
)
googledrive::drive_upload(
media = paste0(
dir_raw_data,
"20211018_acs_labels_included_df.xlsx"
),
path = geo_acs_dict_id,
overwrite = TRUE,
type = 'spreadsheet'
)
geo_dictionary <- acs_labels_include_df
usethis::use_data(geo_dictionary, overwrite = TRUE)Geo Dictionary
After updating dictionary remember to reinstall the package. You can access the dictionary with:
data("geo_dictionary")
head(g6tr.geo::geo_dictionary)
[38;5;246m# A tibble: 6 × 6
[39m
name concept concept_short label_clean var_name combined_var
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<chr>
[39m
[23m
[3m
[38;5;246m<chr>
[39m
[23m
[38;5;250m1
[39m B01001_001 SEX BY AGE sex_age Total sex_age_n sex_age_n
[38;5;250m2
[39m B01001_002 SEX BY AGE sex_age Male sex_age_m sex_age_m
[38;5;250m3
[39m B01001_026 SEX BY AGE sex_age Female sex_age_f sex_age_f
[38;5;250m4
[39m B01002_001 MEDIAN AGE BY SEX med_age_sex Total med_age_sex_n med_age_sex_n
[38;5;250m5
[39m B01002_002 MEDIAN AGE BY SEX med_age_sex Estimate Median age -- Male med_age_sex_m med_age_sex_m
[38;5;250m6
[39m B01002_003 MEDIAN AGE BY SEX med_age_sex Estimate Median age -- Female med_age_sex_f med_age_sex_f