Loading Libraries
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Loading required package: grid
Loading required package: Matrix
Loading required package: survival
Attaching package: 'survey'
The following object is masked from 'package:graphics':
dotchart
Attaching package: 'srvyr'
The following object is masked from 'package:stats':
filter
Loading in Data
Data was taken from KIDSCOUNT
snap_data <- read.csv ("raw_data/Supplemental Nutrition Assistance (SNAP, formerly Food Stamps) recipients (total).csv" )
acs5_vars_2023 <- load_variables (2023 , "acs5" , cache = TRUE )
Pulling data from ACS
Getting data from the 2019-2023 5-year ACS
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.
Getting data from the 2019-2023 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================= | 34%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|============================== | 44%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|========================================================== | 84%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
Selecting Function
select_data <- function (data) {
final_data <- data |>
#unemployment
mutate (snap_married_no_workers = snap_no_workers_married/ total_work_snap_married) |>
mutate (no_snap_married_no_workers = no_snap_no_workers_married/ total_work_no_snap_married) |>
mutate (snap_male_no_workers = snap_no_workers_male/ total_work_snap_males) |>
mutate (snap_female_no_workers = snap_no_workers_female/ total_work_snap_females) |>
mutate (no_snap_male_no_workers = no_snap_no_workers_male/ total_no_snap_male) |>
mutate (no_snap_female_no_workers = no_snap_no_workers_female/ total_no_snap_female) |>
mutate (total_no_work_snap = (snap_no_workers_married + snap_no_workers_male + snap_no_workers_female)/ total_work_snap) |>
mutate (total_no_work_no_snap = (no_snap_no_workers_married + no_snap_no_workers_male + no_snap_no_workers_female)/ total_work_no_snap) |>
#poverty level
mutate (no_snap_above_pov = total_above_pov_no_snap/ total_pov_pop_no_snap) |>
mutate (snap_above_pov = total_above_pov_snap/ total_pov_pop_snap) |>
#disability
mutate (snap_dis_per = snap_dis/ total_snap_dis) |>
mutate (no_snap_dis_per = no_snap_dis/ total_no_snap_dis) |>
mutate (snap_per = snap_rec/ total_pop)|>
mutate (no_snap_per = no_snap/ total_pop) |>
#selects median income
select (snap_married_no_workers, no_snap_married_no_workers, total_no_work_snap, total_no_work_no_snap, no_snap_above_pov, snap_above_pov, total_med_income, total_med_income_snap, total_med_income_no_snap, snap_male_no_workers, snap_female_no_workers, no_snap_male_no_workers, no_snap_female_no_workers, snap_dis_per, no_snap_dis_per, snap_per, no_snap_per, NAME)
return (final_data)
}
#state
snap_data_calc_state <- select_data (snap_dataset_state)
snap_data_calc_counties <- select_data (snap_dataset_counties) |>
mutate (NAME = gsub (", Texas" , "" , NAME)) |>
rename (County = NAME)
STATE
snap_rec_state <- snap_data_calc_state |>
select (snap_per, no_snap_per)
med_income_state <- snap_data_calc_state |>
select (total_med_income, total_med_income_snap, total_med_income_no_snap)
snap_workers_state <- snap_data_calc_state |>
select (snap_married_no_workers, no_snap_married_no_workers, snap_male_no_workers, snap_female_no_workers, no_snap_male_no_workers, no_snap_female_no_workers)
poverty_state <- snap_data_calc_state |>
select (no_snap_above_pov, snap_above_pov)
disability_state <- snap_data_calc_state |>
select (snap_dis_per, no_snap_dis_per)
write.csv (file = "snap_recipients_state.csv" , snap_rec_state, row.names = FALSE )
write.csv (file = "snap_med_income_state.csv" , med_income_state, row.names = FALSE )
write.csv (file = "snap_workers_state.csv" , snap_workers_state, row.names = FALSE )
write.csv (file = "snap_poverty_state.csv" , poverty_state, row.names = FALSE )
write.csv (file = "snap_dis_state.csv" , disability_state, row.names = FALSE )
# A tibble: 1 × 2
snap_per no_snap_per
<dbl> <dbl>
1 0.261 0.739
# A tibble: 1 × 2
no_snap_above_pov snap_above_pov
<dbl> <dbl>
1 0.906 0.568
# A tibble: 1 × 2
snap_dis_per no_snap_dis_per
<dbl> <dbl>
1 0.435 0.230
# A tibble: 1 × 3
total_med_income total_med_income_snap total_med_income_no_snap
<dbl> <dbl> <dbl>
1 76292 32969 83035
snap_workers_state |>
select (contains ("snap_" ))
# A tibble: 1 × 6
snap_married_no_workers no_snap_married_no_workers snap_male_no_workers
<dbl> <dbl> <dbl>
1 0.113 0.120 0.164
# ℹ 3 more variables: snap_female_no_workers <dbl>,
# no_snap_male_no_workers <dbl>, no_snap_female_no_workers <dbl>
snap_workers_state |>
select (contains ("no_snap_" ))
# A tibble: 1 × 3
no_snap_married_no_workers no_snap_male_no_workers no_snap_female_no_workers
<dbl> <dbl> <dbl>
1 0.120 0.0661 0.0972
COUNTIES
snap_rec_counties <- snap_data_calc_counties |>
select (County, snap_per, no_snap_per) |>
mutate (selection = "recipients" )
med_income_state <- snap_data_calc_counties |>
select (County,total_med_income, total_med_income_snap, total_med_income_no_snap) |>
mutate (selection = "median_income" )
snap_workers_state <- snap_data_calc_counties |>
select (County,snap_married_no_workers, no_snap_married_no_workers, snap_male_no_workers, snap_female_no_workers, no_snap_male_no_workers, no_snap_female_no_workers) |>
mutate (selection = "workers" )
poverty_state <- snap_data_calc_counties |>
select (County,no_snap_above_pov, snap_above_pov) |>
mutate (selection = "poverty" )
disability_state <- snap_data_calc_counties |>
select (County,snap_dis_per, no_snap_dis_per) |>
mutate (selection = "disability" )
write.csv (file = "counties/SNAP_Recipients_Counties.csv" , snap_rec_counties, row.names = FALSE )
write.csv (file = "counties/SNAP_Recipeints_Counties.csv" , med_income_state, row.names = FALSE )
write.csv (file = "counties/SNAP_Recipeints_Counties.csv" , snap_workers_state, row.names = FALSE )
write.csv (file = "counties/SNAP_Recipeints_Counties.csv" , poverty_state, row.names = FALSE )
write.csv (file = "counties/SNAP_Disability_Counties.csv" , disability_state, row.names = FALSE )