Fail to get the exact female percentage from tidycensus in R

I use tidycensus to collect demographic data but it seems something wrong since I got 0 female percentage for the zipcode 39309, 87040 and 78712. I also have the same problem, getting some zero values for bachelor's degree percentage, age percentage and population density

Here is my code for female percentage.

library(tidycensus)
library(tidyverse)

# Create the data frame
zipcode_df <- data.frame(as.character(c(39309, 87040, 78712)))

# Rename the column to "zipcode"
colnames(zipcode_df)[1] <- "zipcode"

# Display the result
print(zipcode_df)

# Set up Census  key
census_api_key("94d96c1dfb04afe285d0db958f78ded8a4b197f7")

# Get total population and female population for all zip code tabulation areas (ZCTAs)
population_gender <- get_acs(
  geography = "zcta",
  variables = c("total_population" = "B01003_001E",
                "female_population" = "B01001A_017"),
  year = 2021,
  survey = "acs5",
  output = "wide"
) |>
  mutate(zipcode = as.character(GEOID)) |>
  select(zipcode, total_population, female_populationE) |>
  rename(female_population = female_populationE)

# Calculate the percentage of male population
percentage_female_population <- population_gender %>%
  mutate(percentage_female = (female_population / total_population) * 100) %>%
  select(zipcode, percentage_female)

outcome <- zipcode_df |> left_join(percentage_female_population, by = "zipcode")
> outcome
  zipcode percentage_female
1   39309                 0
2   87040                 0
3   78712                 0

Base code B01001A covers "white" women only

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.