{"id":22298028,"url":"https://github.com/ericmshearer/people","last_synced_at":"2025-03-25T22:45:00.974Z","repository":{"id":266136367,"uuid":"894125080","full_name":"ericmshearer/people","owner":"ericmshearer","description":"Data Extraction from US Census","archived":false,"fork":false,"pushed_at":"2025-02-07T22:56:10.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T23:26:46.345Z","etag":null,"topics":["api","census","epidemiology","public-health","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericmshearer.png","metadata":{"files":{"readme":"READme.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-25T19:53:23.000Z","updated_at":"2025-02-07T22:56:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"34ef9e97-5d47-408f-a643-ce46b8622850","html_url":"https://github.com/ericmshearer/people","commit_stats":null,"previous_names":["ericmshearer/people"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmshearer%2Fpeople","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmshearer%2Fpeople/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmshearer%2Fpeople/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmshearer%2Fpeople/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericmshearer","download_url":"https://codeload.github.com/ericmshearer/people/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245556960,"owners_count":20634889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","census","epidemiology","public-health","r"],"created_at":"2024-12-03T17:59:23.121Z","updated_at":"2025-03-25T22:45:00.955Z","avatar_url":"https://github.com/ericmshearer.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"people\r\n================\r\n\r\n![](https://img.shields.io/badge/lifecycle-experimental-brightgreen.svg)\r\n\r\nThis experimental package will extract common population datasets from\r\nthe Decennial Census (Demographic and Housing Characteristics File) as\r\nwell as CA Department of Finance. While there are many interesting data\r\npoints from the Census, the purpose of this package is to quickly pull\r\ndenominator data. A list of other R packages that extract Census data\r\nare listed below in the resources section.\r\n\r\n*An API key is required*. If you don’t have one, you can request (for\r\nfree) from \u003chttps://api.census.gov/data/key_signup.html\u003e. **Do not share\r\nthis key with anyone**. You may elect to store your API key using a\r\npackage like [keyring](https://r-lib.github.io/keyring/index.html), but\r\nresearch all packages and their strengths/weaknesses for security.\r\n\r\n## Overview\r\n\r\nThe primary function to retrieve data from the 2020 decennial census is\r\n`people::get_population`. To retrieve data, specify the following\r\narguments:\r\n\r\n- `year`: year of interest, character or numeric.\r\n- `dataset`: need to specify api and table to pull from; ex: “dec/dhc”\r\n  pulls from Decennial/Demographic and Housing Characteristics File. To\r\n  view all available datasets for the year of interest, use\r\n  `people::census_datasets(year = x)`.\r\n- `geography`: currently works for census tract, zip code, places (aka\r\n  city), county, or school district.\r\n- `geo_id`: either zip code or place name. For places, use\r\n  `people::get_places(county = \"Orange\")` to pull place codes for your\r\n  jurisdiction. If you need to pull data for multiple geo_id’s, supply\r\n  the argument a vector e.g. `geo_id = c(\"92701\",\"92702\")`.\r\n- `var`: variable or group you want to extract. If you’re wanting a\r\n  single variable, for example, set `var` equal to “P1_001N”. If you\r\n  need a group, set `var` equal to “group(P5)”.\r\n- `key`: your census API key, either specified as character or retrieved\r\n  from `keyring`.\r\n- `state`: two character state fips code.\r\n- `county`: three character county fips code.\r\n\r\nBonus argument - if pulling data at the zip code, you can use\r\n`partial = TRUE` to get data that falls within your jurisdiction. This\r\nis particularly useful for zip codes that border neighboring\r\njurisdictions where you might share populations. All other geographies\r\nignore this argument.\r\n\r\nFor epidemiologists/research analysts working in California,\r\n`people::get_dof` will import the latest P3 file from the Department of\r\nFinance. This function has two arguments:\r\n\r\n- `fips`: three character fips code. If you specify your fips code, the\r\n  P3 file will be filtered for your jurisdiction’s data. Otherwise, the\r\n  entire dataset is imported.\r\n- `dir`: directory where you want the P3 file saved. If you don’t\r\n  specify one, a temporary directory will be created.\r\n\r\n## Examples\r\n\r\n### CA Department of Finance\r\n\r\n``` r\r\noc_dof \u003c- get_dof(fips = \"059\", dir = \"C:\\\\Users\\\\user name\\\\Documents\")\r\n\r\nsm_dof \u003c- get_dof(fips = \"081\")\r\n```\r\n\r\n### Setup\r\n\r\nIf you don’t know your jurisdictions FIPS code, `people::get_profile`\r\nwill provide you with your county and state codes. Do not add the word\r\n“county” after your jurisdiction name. State should be a capitalized two\r\nletter abbreviation.\r\n\r\n``` r\r\nprofile \u003c- get_profile(county = \"Orange\", state = \"CA\")\r\n\r\nprint(profile)\r\n```\r\n\r\n    ##   STATE    COUNTYNAME STATEFP COUNTYFP\r\n    ## 1    CA Orange County      06      059\r\n\r\nTo see all available datasets for a given year, supply year to\r\n`people::census_datasets`. Review the titles and descriptions, and when\r\nyou know which dataset you need, copy and paste dataset code (“x/x”) to\r\n`people::vars_census` to view all available variables in that dataset.\r\n\r\n``` r\r\ncen_datasets \u003c- census_datasets(year = 2023)\r\n\r\nhead(cen_datasets, 10)\r\n```\r\n\r\n    ##                                                              Title\r\n    ## 1                         Current Population Survey: Basic Monthly\r\n    ## 2                         Current Population Survey: Basic Monthly\r\n    ## 3                         Current Population Survey: Basic Monthly\r\n    ## 4                         Current Population Survey: Basic Monthly\r\n    ## 5                         Current Population Survey: Basic Monthly\r\n    ## 6                         Current Population Survey: Basic Monthly\r\n    ## 7  Current Population Survey Annual Social and Economic Supplement\r\n    ## 8                         Current Population Survey: Basic Monthly\r\n    ## 9                         Current Population Survey: Basic Monthly\r\n    ## 10                        Current Population Survey: Basic Monthly\r\n    ##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Description\r\n    ## 1                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 2                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 3                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 4                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 5                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 6                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 7  The Annual Social and Economic Supplement or March CPS supplement is the primary source of detailed information on income and work experience in the United States. Numerous publications based on this survey are issued each year by the Bureaus of Labor Statistics and Census. A public-use microdata file is available for private researchers, who also produce many academic and policy-related documents based on these data. The Annual Social and Economic Supplement is used to generate the annual Population Profile of the United States, reports on geographical mobility and educational attainment, and detailed analysis of money income and poverty status. The labor force and work experience data from this survey are used to profile the U.S. labor market and to make employment projections. To allow for the same type of in-depth analysis of hispanics, additional hispanic sample units are added to the basic CPS sample in March each year. Additional weighting is also performed so that estimates can be made for households and families, in addition to persons.\r\n    ## 8                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 9                                                                                                                                                                                                To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ## 10                                                                                                                                                                                               To provide estimates of employment, unemployment, and other characteristics of the general labor force, of the population as a whole, and of various subgroups of the population. Monthly labor force data for the country are used by the  Bureau of Labor Statistics (BLS) to determine the distribution of funds under the Job Training Partnership Act. These data are collected through combined computer-assisted personal interviewing (CAPI) and computer-assisted telephone interviewing (CATI). In addition to the labor force data, the CPS basic funding provides annual data on work experience, income, health insurance, and migration data from the Annual Social and Economic Supplement (ASEC), and on school enrollment of the population from the October Supplement. Other supplements, some of which are sponsored by other agencies, are conducted biennially or intermittently.\r\n    ##                        dataset\r\n    ## 1                     acs/acs1\r\n    ## 2            acs/acs1/cprofile\r\n    ## 3             acs/acs1/profile\r\n    ## 4                acs/acs1/pums\r\n    ## 5              acs/acs1/pumspr\r\n    ## 6  acs/acs1/sdataprofile/cd119\r\n    ## 7                 acs/acs1/spp\r\n    ## 8             acs/acs1/subject\r\n    ## 9                     acs/acs5\r\n    ## 10           acs/acs5/cprofile\r\n\r\n``` r\r\ncen_vars \u003c- census_vars(year = 2023, dataset = \"acs/acs1\")\r\n\r\nhead(cen_vars, 10)\r\n```\r\n\r\n    ##             name\r\n    ## 2            for\r\n    ## 3             in\r\n    ## 4          ucgid\r\n    ## 5    B24022_060E\r\n    ## 6   B19001B_014E\r\n    ## 7  B07007PR_019E\r\n    ## 8   B19101A_004E\r\n    ## 9    B24022_061E\r\n    ## 10  B19001B_013E\r\n    ## 11 B07007PR_018E\r\n    ##                                                                                                         label\r\n    ## 2                                                                                Census API FIPS 'for' clause\r\n    ## 3                                                                                 Census API FIPS 'in' clause\r\n    ## 4                                                                  Uniform Census Geography Identifier clause\r\n    ## 5           Estimate!!Total:!!Female:!!Service occupations:!!Food preparation and serving related occupations\r\n    ## 6                                                                      Estimate!!Total:!!$100,000 to $124,999\r\n    ## 7                  Estimate!!Total:!!Moved from different municipio:!!Foreign born:!!Naturalized U.S. citizen\r\n    ## 8                                                                        Estimate!!Total:!!$15,000 to $19,999\r\n    ## 9  Estimate!!Total:!!Female:!!Service occupations:!!Building and grounds cleaning and maintenance occupations\r\n    ## 10                                                                       Estimate!!Total:!!$75,000 to $99,999\r\n    ## 11                                           Estimate!!Total:!!Moved from different municipio:!!Foreign born:\r\n    ##                                                                                                                                                                          concept\r\n    ## 2                                                                                                                                             Census API Geography Specification\r\n    ## 3                                                                                                                                             Census API Geography Specification\r\n    ## 4                                                                                                                                             Census API Geography Specification\r\n    ## 5  Sex by Occupation and Median Earnings in the Past 12 Months (in 2023 Inflation-Adjusted Dollars) for the Full-Time, Year-Round Civilian Employed Population 16 Years and Over\r\n    ## 6                                                      Household Income in the Past 12 Months (in 2023 Inflation-Adjusted Dollars) (Black or African American Alone Householder)\r\n    ## 7                                                                              Geographical Mobility in the Past Year by Citizenship Status for Current Residence in Puerto Rico\r\n    ## 8                                                                             Family Income in the Past 12 Months (in 2023 Inflation-Adjusted Dollars) (White Alone Householder)\r\n    ## 9  Sex by Occupation and Median Earnings in the Past 12 Months (in 2023 Inflation-Adjusted Dollars) for the Full-Time, Year-Round Civilian Employed Population 16 Years and Over\r\n    ## 10                                                     Household Income in the Past 12 Months (in 2023 Inflation-Adjusted Dollars) (Black or African American Alone Householder)\r\n    ## 11                                                                             Geographical Mobility in the Past Year by Citizenship Status for Current Residence in Puerto Rico\r\n\r\n### 2020 Decennial Census\r\n\r\n``` r\r\n#Race/ethnicity data at the census tract level\r\nttt \u003c- get_population(\r\n  year = 2020,\r\n  geography = \"census tract\",\r\n  geo_id = \"011718\",\r\n  var = \"group(P5)\",\r\n  key = keyring::key_get(\"census_key\"),\r\n  state = \"06\",\r\n  county = \"059\",\r\n  dataset = \"dec/dhc\"\r\n)\r\n```\r\n\r\n    ## # A tibble: 17 × 7\r\n    ##    NAME                              GEO_ID state county tract variable estimate\r\n    ##    \u003cchr\u003e                             \u003cchr\u003e  \u003cchr\u003e \u003cchr\u003e  \u003cchr\u003e \u003cchr\u003e       \u003cint\u003e\r\n    ##  1 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_001N      3291\r\n    ##  2 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_002N      2530\r\n    ##  3 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_003N      1862\r\n    ##  4 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_004N        42\r\n    ##  5 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_005N         1\r\n    ##  6 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_006N       471\r\n    ##  7 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_007N         4\r\n    ##  8 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_008N         7\r\n    ##  9 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_009N       143\r\n    ## 10 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_010N       761\r\n    ## 11 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_011N       159\r\n    ## 12 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_012N         0\r\n    ## 13 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_013N        13\r\n    ## 14 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_014N        13\r\n    ## 15 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_015N         0\r\n    ## 16 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_016N       188\r\n    ## 17 Census Tract 117.18; Orange Coun… 14000… 06    059    0117… P5_017N       388\r\n\r\n``` r\r\n# Total population at four zip codes\r\nxxx \u003c- get_population(\r\n  year = 2020,\r\n  geography = \"zip code\",\r\n  geo_id = c(\"92870\",\"92886\",\"90630\"),\r\n  var = \"P1_001N\",\r\n  key = keyring::key_get(\"census_key\"),\r\n  state = \"06\",\r\n  county = \"059\",\r\n  partial = TRUE,\r\n  dataset = \"dec/dhc\"\r\n  )\r\n```\r\n\r\n    ## # A tibble: 3 × 6\r\n    ##   NAME         state zip code tabulation …¹ `county (or part)` variable estimate\r\n    ##   \u003cchr\u003e        \u003cchr\u003e \u003cchr\u003e                  \u003cchr\u003e              \u003cchr\u003e       \u003cint\u003e\r\n    ## 1 Orange Coun… 06    92870                  059                P1_001N     52749\r\n    ## 2 Orange Coun… 06    92886                  059                P1_001N     50001\r\n    ## 3 Orange Coun… 06    90630                  059                P1_001N     49771\r\n    ## # ℹ abbreviated name: ¹​`zip code tabulation area (or part)`\r\n\r\n### 2010 Decennial Census\r\n\r\n``` r\r\nvars \u003c- census_vars(year = 2010, dataset = \"dec/sf1\")\r\n\r\n# Total population for San Mateo County\r\nlll \u003c- get_population(\r\n  year = 2010,\r\n  geography = \"county\",\r\n  var = \"group(PCT12)\",\r\n  key = keyring::key_get(\"census_key\"),\r\n  state = \"06\",\r\n  county = \"081\",\r\n  dataset = \"dec/sf1\"\r\n  )\r\n\r\nlll \u003c- merge(lll, vars, by.x = \"variable\", by.y = \"name\")\r\n```\r\n\r\n    ##    variable                         NAME         GEO_ID state county estimate\r\n    ## 1 PCT012001 San Mateo County, California 0500000US06081    06    081   718451\r\n    ## 2 PCT012002 San Mateo County, California 0500000US06081    06    081   353168\r\n    ## 3 PCT012003 San Mateo County, California 0500000US06081    06    081     4746\r\n    ## 4 PCT012004 San Mateo County, California 0500000US06081    06    081     4673\r\n    ## 5 PCT012005 San Mateo County, California 0500000US06081    06    081     4786\r\n    ## 6 PCT012006 San Mateo County, California 0500000US06081    06    081     4743\r\n    ##                       label    concept\r\n    ## 1                     Total SEX BY AGE\r\n    ## 2               Total!!Male SEX BY AGE\r\n    ## 3 Total!!Male!!Under 1 year SEX BY AGE\r\n    ## 4       Total!!Male!!1 year SEX BY AGE\r\n    ## 5      Total!!Male!!2 years SEX BY AGE\r\n    ## 6      Total!!Male!!3 years SEX BY AGE\r\n\r\n**Resources:**\r\n\r\n- [Datasets](https://www.census.gov/data/developers/data-sets/decennial-census.html)\r\n  from Decennial 2020\r\n- [API Key Signup](https://api.census.gov/data/key_signup.html)\r\n- Other R packages that extract census data:\r\n  - [tidycensus](https://walker-data.com/tidycensus/)\r\n  - [censusapi](https://www.hrecht.com/censusapi/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmshearer%2Fpeople","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericmshearer%2Fpeople","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmshearer%2Fpeople/lists"}