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

Fix: Use Population Percentage Instead of Raw Population Counts #3186

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fixing pct_relative_inequity bug
  • Loading branch information
eriwarr committed Apr 23, 2024
commit cacc90665ed9261c94cc987749fab3738e2bebd2
66 changes: 29 additions & 37 deletions python/datasources/cdc_wisqars_youth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
"""
This documentation outlines the procedure for acquiring gun violence data for the general
eriwarr marked this conversation as resolved.
Show resolved Hide resolved
population from the CDC WISQARS database. The data, once downloaded, is stored locally in
the `data/cdc_wisqars` directory for further processing and analysis.

Instructions for Downloading Data:
1. Access the WISQARS website at https://wisqars.cdc.gov/reports/.
2. Select `Fatal` as the injury outcome.
3. Specify the data years of interest, from `2018-2021 by Single Race`.
4. Set geography to `United States`.
5. Choose `All Intents` for the intent.
6. Under mechanism, opt for `Firearm`.
7. For youth demographics, select `Custom Age Range: <1 to 17`, `Both Sexes`, `All Races`.
8. For youth demographics, select `Custom Age Range: 18 to 25`, `Both Sexes`, `All Races`.
9. Decide on the report layout based on your requirements:
- For youth-national-all: `Intent`, `None`, `None`, `None`
- For youth-national-race: `Intent`, `Race`, `Ethnicity`, `None`
- For youth-state-all: `Intent`, `State`, `None`, `None`
- For youth-state-race: `Intent`, `State`, `Race`, `Ethnicity`

Notes:
- There is no county-level data.
- Race data is provided only for fatal data outcomes and covers the period from 2018-2021.

Last Updated: 4/23
"""

import pandas as pd

from datasources.data_source import DataSource
Expand All @@ -24,41 +51,6 @@
)
from ingestion.merge_utils import merge_state_ids

"""
Data Source: CDC WISQARS Youth (data on gun violence)

Description:
- The data on gun violence by youth and race is downloaded from the CDC WISQARS database.
- The downloaded data is stored locally in our data/cdc_wisqars directory for subsequent use.

Instructions for Downloading Data:
1. Visit the WISQARS website: https://wisqars.cdc.gov/reports/
2. Select the injury outcome:
- `Fatal`
3. Select the year and race options:
- `2018-2021 by Single Race`
4. Select the desired data years:
- `2018-2021`
5. Select the geography:
- `United States`
6. Select the intent:
- `All Intents`
7. Select the mechanism:
- `Firearm`
8. Select the demographic selections:
- `Custom Age Range: <1 to Unknown`, `Both Sexes`, `All Races`
5. Select appropriate report layout:
- For youth-national-all: `Intent`, `None`, `None`, `None`
- For youth-national-race: `Intent`, `Race`, `Ethnicity`, `None`
- For youth-state-all: `Intent`, `State`, `None`, `None`
- For youth-state-race: `Intent`, `State`, `Race`, `Ethnicity`
Notes:
- There is no county-level data.
- Race data is only available for fatal data and is available from 2018-2021.

Last Updated: 2/24
"""

CATEGORIES_LIST = [std_col.GUN_DEATHS_YOUNG_ADULTS_PREFIX, std_col.GUN_DEATHS_YOUTH_PREFIX]
ESTIMATED_TOTALS_MAP = generate_cols_map(CATEGORIES_LIST, std_col.RAW_SUFFIX)
PCT_REL_INEQUITY_MAP = generate_cols_map(ESTIMATED_TOTALS_MAP.values(), std_col.PCT_REL_INEQUITY_SUFFIX)
Expand Down Expand Up @@ -131,9 +123,9 @@ def generate_breakdown_df(self, breakdown: str, geo_level: str, alls_df: pd.Data

for col in ESTIMATED_TOTALS_MAP.values():
pop_col = (
std_col.GUN_DEATHS_YOUNG_ADULTS_POPULATION
std_col.GUN_DEATHS_YOUNG_ADULTS_POP_PCT
if col == std_col.GUN_DEATHS_YOUNG_ADULTS_PREFIX
else std_col.GUN_DEATHS_YOUTH_POPULATION
else std_col.GUN_DEATHS_YOUTH_POP_PCT
)
df = generate_pct_rel_inequity_col(df, PCT_SHARE_MAP[col], pop_col, PCT_REL_INEQUITY_MAP[col])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
time_period,state_name,state_fips,race_and_ethnicity,gun_deaths_young_adults_pct_relative_inequity,gun_deaths_youth_pct_relative_inequity,gun_deaths_young_adults_pct_share,gun_deaths_youth_pct_share,gun_deaths_young_adults_per_100k,gun_deaths_youth_per_100k
2018,United States,00,American Indian and Alaska Native (NH),-100.0,,1.2,,28.56,
2018,United States,00,Asian (NH),-100.0,-100.0,1.2,2.4,4.23,1.03
2018,United States,00,Black or African American (NH),-100.0,-100.0,43.3,36.0,60.86,6.03
2018,United States,00,Hispanic or Latino,-100.0,-100.0,16.5,15.3,15.0,1.0
2018,United States,00,Two or more races (NH),-100.0,-100.0,1.6,2.4,10.9,1.26
2018,United States,00,American Indian and Alaska Native (NH),50.0,,1.2,,28.56,
2018,United States,00,Asian (NH),-77.4,-54.7,1.2,2.4,4.23,1.03
2018,United States,00,Black or African American (NH),216.1,162.8,43.3,36.0,60.86,6.03
2018,United States,00,Hispanic or Latino,-34.5,-39.3,16.5,15.3,15.0,1.0
2018,United States,00,Two or more races (NH),-63.6,-45.5,1.6,2.4,10.9,1.26
2018,United States,00,Native Hawaiian and Pacific Islander (NH),,,,,,
2018,United States,00,White (NH),-100.0,-100.0,36.2,43.9,13.62,2.0
2019,United States,00,American Indian and Alaska Native (NH),-100.0,-100.0,1.1,1.4,25.59,3.82
2019,United States,00,Asian (NH),-100.0,-100.0,1.5,1.5,5.18,0.67
2019,United States,00,Black or African American (NH),-100.0,-100.0,45.9,39.6,65.43,6.69
2019,United States,00,Hispanic or Latino,-100.0,-100.0,15.4,16.1,14.0,1.0
2019,United States,00,Two or more races (NH),-100.0,-100.0,1.9,2.4,11.98,1.24
2018,United States,00,White (NH),-28.0,-12.7,36.2,43.9,13.62,2.0
2019,United States,00,American Indian and Alaska Native (NH),37.5,75.0,1.1,1.4,25.59,3.82
2019,United States,00,Asian (NH),-72.2,-72.2,1.5,1.5,5.18,0.67
2019,United States,00,Black or African American (NH),235.0,189.1,45.9,39.6,65.43,6.69
2019,United States,00,Hispanic or Latino,-39.4,-36.6,15.4,16.1,14.0,1.0
2019,United States,00,Two or more races (NH),-57.8,-46.7,1.9,2.4,11.98,1.24
2019,United States,00,Native Hawaiian and Pacific Islander (NH),,,,,,
2019,United States,00,White (NH),-100.0,-100.0,34.3,39.0,13.04,1.81
2020,United States,00,American Indian and Alaska Native (NH),-100.0,-100.0,1.2,1.6,37.79,5.96
2020,United States,00,Asian (NH),-100.0,-100.0,1.3,1.2,5.84,0.65
2020,United States,00,Black or African American (NH),-100.0,-100.0,49.3,42.7,92.04,9.37
2020,United States,00,Hispanic or Latino,-100.0,-100.0,16.0,16.6,18.0,2.0
2020,United States,00,Two or more races (NH),-100.0,-100.0,1.7,2.0,13.68,1.29
2019,United States,00,White (NH),-31.3,-21.8,34.3,39.0,13.04,1.81
2020,United States,00,American Indian and Alaska Native (NH),50.0,100.0,1.2,1.6,37.79,5.96
2020,United States,00,Asian (NH),-75.9,-77.8,1.3,1.2,5.84,0.65
2020,United States,00,Black or African American (NH),259.9,211.7,49.3,42.7,92.04,9.37
2020,United States,00,Hispanic or Latino,-37.5,-35.2,16.0,16.6,18.0,2.0
2020,United States,00,Two or more races (NH),-63.0,-56.5,1.7,2.0,13.68,1.29
2020,United States,00,Native Hawaiian and Pacific Islander (NH),,,,,,
2020,United States,00,White (NH),-100.0,-100.0,30.5,36.0,15.09,2.18
2021,United States,00,American Indian and Alaska Native (NH),-100.0,-100.0,1.1,1.0,35.88,4.37
2021,United States,00,Asian (NH),-100.0,-100.0,1.4,1.4,6.68,0.9
2021,United States,00,Black or African American (NH),-100.0,-100.0,48.8,46.6,96.78,11.81
2021,United States,00,Hispanic or Latino,-100.0,-100.0,17.1,16.3,20.0,2.0
2021,United States,00,Two or more races (NH),-100.0,-100.0,2.1,2.4,17.5,1.77
2021,United States,00,Native Hawaiian and Pacific Islander (NH),-100.0,,0.2,,30.61,
2021,United States,00,White (NH),-100.0,-100.0,29.3,32.2,15.31,2.28
2020,United States,00,White (NH),-38.6,-27.6,30.5,36.0,15.09,2.18
2021,United States,00,American Indian and Alaska Native (NH),37.5,25.0,1.1,1.0,35.88,4.37
2021,United States,00,Asian (NH),-74.1,-74.1,1.4,1.4,6.68,0.9
2021,United States,00,Black or African American (NH),253.6,237.7,48.8,46.6,96.78,11.81
2021,United States,00,Hispanic or Latino,-33.5,-36.6,17.1,16.3,20.0,2.0
2021,United States,00,Two or more races (NH),-55.3,-48.9,2.1,2.4,17.5,1.77
2021,United States,00,Native Hawaiian and Pacific Islander (NH),0.0,,0.2,,30.61,
2021,United States,00,White (NH),-40.7,-34.8,29.3,32.2,15.31,2.28
2018,United States,00,Unknown race,,,,,,
2019,United States,00,Unknown race,,,,,,
2020,United States,00,Unknown race,,,,,,
2021,United States,00,Unknown race,,,,,,
2021,United States,00,All,-100.0,-100.0,100.0,100.0,27.73,3.52
2020,United States,00,All,-100.0,-100.0,100.0,100.0,26.36,3.07
2019,United States,00,All,-100.0,-100.0,100.0,100.0,20.45,2.37
2018,United States,00,All,-100.0,-100.0,100.0,100.0,20.35,2.36
2021,United States,00,All,0.0,0.0,100.0,100.0,27.73,3.52
2020,United States,00,All,0.0,0.0,100.0,100.0,26.36,3.07
2019,United States,00,All,0.0,0.0,100.0,100.0,20.45,2.37
2018,United States,00,All,0.0,0.0,100.0,100.0,20.35,2.36
Loading