Project 2 — Dataset 3: US State Population Change, 2020–2024
Author
Yalda Azamee
Published
November 28, 2026
Introduction
The U.S. Census Bureau publishes yearly population estimates for every state, together with the components of change: births, deaths, international migration, and domestic migration (people moving between states) (Census Bureau: State Population Totals and Components of Change, 2020–2024). The file is very wide: each measure is repeated for every year in its own column, such as POPESTIMATE2020 … POPESTIMATE2024 and BIRTHS2020 … BIRTHS2024. Analysis question: Which states grew fastest from 2020 to 2024, and did the growth come from natural change (births minus deaths) or from migration?
Data Source
I downloaded the “Annual Estimates of the Resident Population and Components of Change” dataset (NST-EST2024-ALLDATA.csv) and saved it without changes as data/census_state_population_raw.csv in my GitHub repository. The code below reads it from GitHub, so it runs on any computer.
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
theme_set(theme_minimal(base_size =12)) # same chart style in all three datasetsraw_url <-"https://raw.githubusercontent.com/YaldaAzamee/data607-project2/main/data/census_state_population_raw.csv"raw <-read.csv(raw_url)
Data Structure Before Tidying
The raw data has 66 rows and 75 columns. The column names are:
Except for the first five ID columns, every column name joins a measure and a year (for example BIRTHS2021, NPOPCHG_2022). This is why the table is wide.
The rows mix different geographic levels, identified by SUMLEV: 10, 20, 30, 40 (010 = United States, 020 = region, 030 = division, 040 = state).
Column names are uppercase codes, such as NATURALCHG (natural change) and RBIRTH (birth rate).
Transformation Steps
Step 1: Reshape from wide to long
I stack all the measure-year columns into rows with pivot_longer(). names_pattern splits each column name into the measure (letters) and the year (last four digits). The optional _ handles names like NPOPCHG_2020.
long <- raw |>pivot_longer(cols =matches("\\d{4}$"),names_to =c("measure", "year"),names_pattern ="^(.*?)_?(\\d{4})$",values_to ="value" )head(long)
# A tibble: 6 × 8
SUMLEV REGION DIVISION STATE NAME measure year value
<int> <chr> <chr> <int> <chr> <chr> <chr> <dbl>
1 10 0 0 0 United States ESTIMATESBASE 2020 331515736
2 10 0 0 0 United States POPESTIMATE 2020 331577720
3 10 0 0 0 United States POPESTIMATE 2021 332099760
4 10 0 0 0 United States POPESTIMATE 2022 334017321
5 10 0 0 0 United States POPESTIMATE 2023 336806231
6 10 0 0 0 United States POPESTIMATE 2024 340110988
The value column now mixes very different measures: people, births, and rates. In tidy data each measure should be its own variable, so I use pivot_wider() to give every measure its own column. Each row is then one geographic area in one year. I also convert year to an integer and replace the SUMLEV and REGION codes with readable labels.
# Missing values in each column, by yearrenamed |>group_by(year) |>summarise(across(everything(), ~sum(is.na(.x)))) |>select(year, where(~is.numeric(.x) &&sum(.x) >0)) |> knitr::kable()
year
population_base
birth_rate
death_rate
natural_change_rate
international_mig_rate
domestic_mig_rate
net_mig_rate
2020
0
66
66
66
66
66
66
2021
66
0
0
0
0
0
0
2022
66
0
0
0
0
0
0
2023
66
0
0
0
0
0
0
2024
66
0
0
0
0
0
0
# Puerto Rico: region code and domestic migrationrenamed |>filter(area =="Puerto Rico") |>select(area, region, year, domestic_mig) |> knitr::kable()
area
region
year
domestic_mig
Puerto Rico
X
2020
0
Puerto Rico
X
2021
0
Puerto Rico
X
2022
0
Puerto Rico
X
2023
0
Puerto Rico
X
2024
0
Decisions:
Missing rates in 2020: the rate columns (birth_rate, …) do not exist for 2020 in the raw file, so they are NA after reshaping. The 2020 estimates only cover April 1 to July 1, 2020 (about three months), so rates are not published. I keep the NA values because they are correct, and my analysis does not use rates for 2020.
Missing population_base in 2021–2024: the base population (the April 1, 2020 starting point) exists only for 2020, so it is NA in the other years. This is also correct, and I do not use it in the analysis.
Partial year 2020: for the same reason, the 2020 components (births, deaths, migration) cover only three months. To compare full years, I add up the components for 2021–2024 only (each covers July 1 to June 30). I measure growth from the July 1, 2020 estimate to the July 1, 2024 estimate, so both use the same time period.
Mixed geographic levels: the nation, regions, and divisions are sums of states. I keep only states (geo_level == "State") so nothing is counted twice.
Puerto Rico: its region is "X" (not part of any region) and its domestic migration is always 0, because moving between Puerto Rico and the states is counted differently. I remove it, so the analysis covers the 50 states and the District of Columbia.
states_tidy <- renamed |>filter(geo_level =="State", area !="Puerto Rico") |>select(-geo_level)n_distinct(states_tidy$area)
[1] 51
head(states_tidy)
# A tibble: 6 × 19
region area year population_base population pop_change births deaths
<chr> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
1 South Alabama 2020 5025369 5033094 7725 13867 15146
2 South Alabama 2021 NA 5049196 16102 57184 69134
3 South Alabama 2022 NA 5076181 26985 58103 67246
4 South Alabama 2023 NA 5117673 41492 58528 60059
5 South Alabama 2024 NA 5157699 40026 57541 59273
6 West Alaska 2020 733395 733017 -378 2406 1169
# ℹ 11 more variables: natural_change <dbl>, international_mig <dbl>,
# domestic_mig <dbl>, net_mig <dbl>, residual <dbl>, birth_rate <dbl>,
# death_rate <dbl>, natural_change_rate <dbl>, international_mig_rate <dbl>,
# domestic_mig_rate <dbl>, net_mig_rate <dbl>
The final tidy dataset has 255 rows (51 states × 5 years) and 19 columns.
Analytical Methods
All analysis uses the tidy dataset states_tidy. For each state I calculate:
Growth (%) = (population on July 1, 2024 − population on July 1, 2020) ÷ population in 2020 × 100.
Components of growth, 2021–2024: the sum of natural change, international migration, and domestic migration, each shown as a percentage of the 2020 population. This makes large and small states comparable and shows where the growth came from.
I then compare the fastest- and slowest-growing states, and summarize the components for the ten fastest-growing states in a stacked bar chart.
top10 <- growth |>slice_head(n =10)top10 |>select(area, natural_pct, international_mig_pct, domestic_mig_pct) |>pivot_longer(-area, names_to ="component", values_to ="pct") |>mutate(component =recode(component,natural_pct ="Natural change (births − deaths)",international_mig_pct ="International migration",domestic_mig_pct ="Domestic migration"),area =factor(area, levels =rev(top10$area)) ) |>ggplot(aes(pct, area, fill = component)) +geom_col() +geom_vline(xintercept =0, color ="grey40") +scale_fill_manual(values =c("Natural change (births − deaths)"="#009E73","International migration"="#0072B2","Domestic migration"="#D55E00" )) +labs(title ="Where Growth Came From in the 10 Fastest-Growing States",subtitle ="Components of population change, July 2020 to July 2024",x ="Change as % of 2020 population",y =NULL,fill ="Component" ) +theme(legend.position ="bottom")
Conclusions
Findings
Florida grew the fastest: its population rose by 8.2%, from 21,592,035 to 23,372,215.
West Virginia had the lowest growth (-1.2%). In total, 7 states lost population between 2020 and 2024.
Migration drove the fastest growth, not births. In 8 of the 10 fastest-growing states, domestic migration (people moving from other states) added more people than natural change.
The South dominates: 6 of the 10 fastest-growing states are in the South region.
Natural change is small or negative in many states: in 22 states, deaths outnumbered births from 2021 to 2024, so those states could only grow through migration.
AI Use
Anthropic. (2026). Claude Opus 5.5 [Large language model]. https://claude.ai. Accessed November 28, 2026. Used to help select the dataset,and understand the assignment requirements.