Compare state consumer spending by category in Python
Compare BEA food and housing spending per person and category shares in North Carolina, Georgia and Virginia, 2019 and 2025.
A regional market brief needs more than total spending: states with more residents usually have larger totals. Dollars per person and each category’s share of spending help make a more useful comparison. This example uses North Carolina, Georgia and Virginia to compare food purchased for off-premises consumption and housing/utilities in 2019 and 2025.
Sample data
state_spending.csv below is a genuine subset of the paid main table: the three states, two categories and two years used here, with all 19 fields unchanged. The optional input.csv supplies the actual state FIPS codes and names. Those selections also appear in the places list in the Python code below. No spending observations or households have been invented.
Save the sample as state_spending.csv in your working folder. The product supplies BEA’s resident-based personal consumption expenditures (PCE): purchases by or on behalf of people living in each state. These figures include third-party payments and imputed services, so they are broader than out-of-pocket household budgets.
Code example
The code selects reported observations, compares BEA’s current-dollar spending per person, and prints each category’s share of total PCE. It runs in a notebook or as a script using Python’s standard library.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
import csv
from decimal import Decimal
# The same real state selections are also supplied in example_input.csv.
places = [
{"state_fips": "37", "state_name": "North Carolina"},
{"state_fips": "13", "state_name": "Georgia"},
{"state_fips": "51", "state_name": "Virginia"},
]
categories = {"9": "Food off-premises", "15": "Housing & utilities"}
start_year, end_year = "2019", "2025"
with open("state_spending.csv", newline="", encoding="utf-8") as stream:
selected = {}
for row in csv.DictReader(stream):
if (row["geography_type"] == "state"
and row["state_fips"] in {p["state_fips"] for p in places}
and row["category_code"] in categories
and row["year"] in {start_year, end_year}):
key = row["state_fips"], row["category_code"], row["year"]
if key in selected:
raise ValueError(f"Duplicate observation: {key}")
if row["per_capita_status"] != "reported" or row["expenditure_status"] != "reported":
raise ValueError(f"Unavailable observation: {key}")
selected[key] = row
results = []
for place in places:
for code, label in categories.items():
old = selected[place["state_fips"], code, start_year]
new = selected[place["state_fips"], code, end_year]
old_pc, new_pc = Decimal(old["per_capita_dollars"]), Decimal(new["per_capita_dollars"])
result = {
"state_fips": place["state_fips"], "state_name": place["state_name"],
"category_code": code, "category": label,
"per_capita_2019": str(old_pc), "per_capita_2025": str(new_pc),
"nominal_change_pct": f"{(new_pc / old_pc - 1) * 100:.2f}",
"share_2019_pct": f"{Decimal(old['share_of_pce_pct']):.2f}",
"share_2025_pct": f"{Decimal(new['share_of_pce_pct']):.2f}",
}
results.append(result)
print(f"{result['state_name']} | {label}: "
f"${old_pc:,.0f} → ${new_pc:,.0f} per person; "
f"nominal change {result['nominal_change_pct']}%; "
f"share of PCE {result['share_2019_pct']}% → {result['share_2025_pct']}%")
Analysis of the output
North Carolina | Food off-premises: $3,241 → $4,343 per person; nominal change 34.00%; share of PCE 8.29% → 7.80%
North Carolina | Housing & utilities: $6,882 → $10,351 per person; nominal change 50.41%; share of PCE 17.60% → 18.58%
Georgia | Food off-premises: $3,296 → $4,534 per person; nominal change 37.56%; share of PCE 8.43% → 8.22%
Georgia | Housing & utilities: $6,853 → $10,332 per person; nominal change 50.77%; share of PCE 17.52% → 18.73%
Virginia | Food off-premises: $3,348 → $4,523 per person; nominal change 35.10%; share of PCE 7.66% → 7.46%
Virginia | Housing & utilities: $8,259 → $11,316 per person; nominal change 37.01%; share of PCE 18.90% → 18.67%
North Carolina’s housing and utilities spending rises from $6,882 to $10,351 per person, while its share of PCE rises from 17.60% to 18.58%. Georgia has a similar pattern. Virginia’s housing/utilities level also rises, but its share falls slightly, from 18.90% to 18.67%. A category can therefore grow in dollars while taking a smaller share of overall spending.
Food purchased for off-premises consumption increases in dollars per person in all three states, while its share falls. The two measures answer different questions: dollars per person describe the level of spending; the share describes its place in the spending mix. Neither establishes why the change happened.
What the categories include
Housing includes actual rents and imputed rental services for owner-occupied homes, plus household utilities. It is not a mortgage-payment average or a house-price series. Food purchased for off-premises consumption is separate from food services and accommodations; these observations should not be labeled total food spending. Original BEA definitions accompany each category.
The percentage changes above are nominal. They include price and consumption changes, even after dividing by population. The data do not establish changes in quantities or affordability, and these source tables do not supply standard errors for a significance test. National CPI and regional price parities provide different context; neither supplies an automatic category-specific inflation adjustment for this example.
Using the full dataset
After purchase, replace the sample with state_spending.csv from the archive. Change the text state codes in places, the years or the category selection. To use your own CSV of states, load it with csv.DictReader in place of the inline list. The downloadable areas.csv and categories.csv document valid identifiers and definitions.
The unique observation key is geography_type + bea_area_code + year + category_code. Join areas on geography type and BEA code, and categories on category code. Keep state FIPS and BEA codes as text. The state geography includes DC; the national and eight regional reference areas are separate aggregates, not additional states.
Use expenditure_millions for total market scale and per_capita_dollars for the published per-resident level. The share is calculated from the category’s total divided by same-area/year total PCE. Six decimal places record the calculation, not greater source accuracy. Per-capita figures are retained as BEA published them, using its unrounded inputs.
Choosing categories without double counting
Do not sum all 22 categories: the file includes totals and their components. The parent_category_code and is_terminal fields identify the hierarchy. The 16 terminal expenditure categories partition total PCE within source rounding. Nonprofit gross output and sales receipts are supplied in nonprofit_adjustments.csv; their difference is net nonprofit spending, already included in services and total PCE.
Do not add regions to their member states or force the published national total to equal the state sum. BEA identifies net expenditure abroad in the national PCE, goods, nondurables and other nondurables figures. This is resident-based spending, not sales at stores located inside each state.
Explore spending, inflation and regional price data for companion questions. National spending by income or age remains a different population breakdown; it cannot be assigned to individual states using this file.
Sources and versions
Source: BEA Consumer Spending by State, SAPCE1 and SAPCE2, September 30, 2026 release. It adds 2025; the total-spending table revises 2021–2024, while the per-capita table revises 2020–2024. We retained this source on November 18, 2026 UTC. The download is one revised historical edition, not a collection of original annual publication vintages.
BEA provides the original data free. Actually Clean Data sells preparation, documentation, checks and a reproducible download. Processing improvements and publisher error corrections to the purchased edition are included; new source editions may be separate purchases. Read the release notes and BEA methodology.
Example checked November 18, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.