Ignacio Ignacio - 1 month ago 9
R Question

get population by state 12 and older using census data?

Is it possible to get the US population by state age 12 or older? I'm trying to use the

tidycensus
package, but I'm not sure how to limit the count to add the age restriction.

library(tidycensus)
library(tidyverse)
census_api_key("MYKEY")
pop90 <- get_acs(geography = "state", variables = "B01003_001", year = 1990)

Answer Source

The "Universe" for that particular variable"B01003-001" is TOTAL POPULATION, it is not broken down any further than that, so you are not able to get the 12+ ages from "B01003-001", only the population of the whole state or county or tract you are pulling from at the time.

However, you can pull and aggregate a data frame for the tables you would like, using B01001 and the suffixes _001 through _049 to pull out the populations by age and gender and then add them up.

OR

You could pull the entire population as you have above and subtract out the ages (both male and female NOT in your target group, which is much less work given the breakdown of age groups for children compared to the rest of life)

The one thing you will have a hard time with is getting 12+, because the highest groupings you would want to exclude are 10-14...which means you could not select under 12

General Age by Sex for All Races Codes:

    B01001_001                     Total: 
    B01001_002                      Male: 
    B01001_003        Male: Under 5 years 
    B01001_004         Male: 5 to 9 years 
    B01001_005       Male: 10 to 14 years 
    B01001_006       Male: 15 to 17 years 
    B01001_007      Male: 18 and 19 years 
    B01001_008             Male: 20 years 
    B01001_009             Male: 21 years 
    B01001_010       Male: 22 to 24 years 
    B01001_011       Male: 25 to 29 years 
    B01001_012       Male: 30 to 34 years 
    B01001_013       Male: 35 to 39 years 
    B01001_014       Male: 40 to 44 years 
    B01001_015       Male: 45 to 49 years 
    B01001_016       Male: 50 to 54 years 
    B01001_017       Male: 55 to 59 years 
    B01001_018      Male: 60 and 61 years 
    B01001_019       Male: 62 to 64 years 
    B01001_020      Male: 65 and 66 years 
    B01001_021       Male: 67 to 69 years 
    B01001_022       Male: 70 to 74 years 
    B01001_023       Male: 75 to 79 years 
    B01001_024       Male: 80 to 84 years 
    B01001_025    Male: 85 years and over 
    B01001_026                    Female: 
    B01001_027      Female: Under 5 years 
    B01001_028       Female: 5 to 9 years 
    B01001_029     Female: 10 to 14 years 
    B01001_030     Female: 15 to 17 years 
    B01001_031    Female: 18 and 19 years 
    B01001_032           Female: 20 years 
    B01001_033           Female: 21 years 
    B01001_034     Female: 22 to 24 years 
    B01001_035     Female: 25 to 29 years 
    B01001_036     Female: 30 to 34 years 
    B01001_037     Female: 35 to 39 years 
    B01001_038     Female: 40 to 44 years 
    B01001_039     Female: 45 to 49 years 
    B01001_040     Female: 50 to 54 years 
    B01001_041     Female: 55 to 59 years 
    B01001_042    Female: 60 and 61 years 
    B01001_044    Female: 65 and 66 years 
    B01001_045     Female: 67 to 69 years 
    B01001_046     Female: 70 to 74 years 
    B01001_047     Female: 75 to 79 years 
    B01001_048     Female: 80 to 84 years 
    B01001_049  Female: 85 years and over

So you willl need to adjust your model in some way or get PUMS data and aggregate to your liking.