Compare county Medicare spending and hospital use in Python
Compare spending per beneficiary and inpatient stays across counties and years using prepared CMS history, a free product sample and copyable Python.
Compare county spending alongside hospital use
Suppose you are preparing a healthcare market brief for Wake County, North Carolina; Maricopa County, Arizona; and Miami-Dade County, Florida. Compare Original Medicare spending per beneficiary in 2014 and 2024, then place that change alongside inpatient stays per 1,000 beneficiaries. The two measures tell you more than total spending alone.
The optional input.csv contains the three selected county FIPS codes. The identical list appears as counties in the Python code below. These are real geographic selections; no beneficiaries, claims or dollar values have been invented.
county_years.csv below is a genuine sample of the main file you buy: all 33 annual observations for these counties, with all 70 fields unchanged. Save it in your working folder. The full download contains 35,146 county-year records and adds separate benchmarks, county coverage, measure availability and source-row accounting.
Code example
The code keeps FIPS codes as text, selects the two comparison years and prints six results. It checks availability statuses before displaying a numeric value. It works in Jupyter, IPython or a Python script with no extra packages.
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 selected county codes are supplied in example_input.csv (input.csv online).
counties = [{'county_fips': '37183'}, {'county_fips': '04013'}, {'county_fips': '12086'}]
years = ('2014', '2024')
wanted = {c['county_fips'] for c in counties}
lookup = {}
with open('county_years.csv', newline='', encoding='utf-8') as stream:
for row in csv.DictReader(stream):
if row['county_fips'] in wanted and row['year'] in years:
key = (row['county_fips'], row['year'])
if key in lookup:
raise ValueError(f'Duplicate county/year: {key}')
lookup[key] = row
def display(row, field, money=False):
if row is None:
return 'year absent'
status = row[field + '_status']
if status != 'reported':
return status
value = Decimal(row[field])
return f'${value:,.2f}' if money else f'{value:,.1f}'
results = []
for county in counties:
code = county['county_fips']
for year in years:
row = lookup.get((code, year))
results.append({
'county': row['county_name'] if row else code,
'year': year,
'standardized_usd_per_beneficiary': display(row, 'standardized_spending_per_beneficiary_usd', True),
'inpatient_stays_per_1000': display(row, 'inpatient_stays_per_1000'),
})
print('County | Year | Standardized $/beneficiary | Inpatient stays/1,000')
for result in results:
print(' | '.join(result.values()))
Analysis of the output
County | Year | Standardized $/beneficiary | Inpatient stays/1,000
NC-Wake | 2014 | $8,140.99 | 230.5
NC-Wake | 2024 | $11,309.47 | 202.6
AZ-Maricopa | 2014 | $8,759.53 | 239.0
AZ-Maricopa | 2024 | $13,276.22 | 202.7
FL-Miami-Dade | 2014 | $14,771.34 | 408.9
FL-Miami-Dade | 2024 | $19,226.65 | 296.2
Published standardized spending per beneficiary is higher in 2024 in all three counties, while covered inpatient stays per 1,000 beneficiaries are lower. Wake rises from $8,140.99 to $11,309.47 per beneficiary while stays fall from 230.5 to 202.6 per 1,000. This provides a useful starting point for examining changes in service mix; it does not mean an inpatient stay caused the spending difference.
“Standardized” means CMS adjusts for geographic differences in payment rates. These values are not inflation-adjusted or health-risk-adjusted comparisons. Changing prices over time, beneficiary health and enrollment patterns can all matter. Miami-Dade has higher spending and more inpatient stays than the other two counties in both displayed years, but these figures alone do not establish differences in care quality.
The denominator is Original Medicare beneficiaries with both Part A and Part B for all entitled months, including qualifying new enrollees and deaths. Medicare Advantage spending is excluded. Stays count episodes, not unique patients; the rate is per 1,000 beneficiaries, not a percentage. These are county-of-residence measures, not totals for hospitals located in each county.
A source suppression or unavailable cell prints its status rather than zero. If you change the county selection and a year has no row, the output says year absent. The separate coverage table helps distinguish a missing year from a suppressed measure on an existing row.
Using the full dataset
Replace the sample with county_years.csv from the purchased ZIP and run the same code. Change counties to your county codes, or load your own CSV using csv.DictReader. Change years to compare any of 2014–2024. Additional fields support enrollment context, actual payments, emergency visits, outpatient visits, skilled nursing, home health and hospice research.
Check county_coverage.csv before building a trend. The source changes Connecticut from legacy counties through 2021 to planning regions from 2022. Some Alaska and South Dakota codes also change. The product exposes these histories; it does not allocate predecessor records or assume constant boundaries.
benchmarks.csv supplies separately keyed national and state-level comparisons. Choose the same year and the all age group to match county scope. Do not sum all-ages with the under-65 and 65-plus groups. CMS’s unnumbered Territory and ZZ aggregates remain separately identified; their blank source codes are not county FIPS.
For broader context, the county health insurance reference describes a different population and the population history uses a different geography vintage. Match boundaries and denominators before combining them. The hospital reference describes facilities, so a shared county label would not establish which hospitals served these beneficiaries.
Sources and versions
Source: CMS Original Medicare Geographic Variation, 2014–2024 file, metadata modified May 15, 2026. ACD retained the source and its May 2026 documentation on October 22, 2026 UTC; this package was prepared 2026-10-22. The eleven observation years are part of one revised source edition, not eleven separately frozen vintages.
The prepared product selects 32 measures; it does not include every CMS column or the condition-specific PQI measures. Its dictionaries state source fields, units and denominators, and its quality report lists the unselected fields. Original CMS data remain free; the purchase provides prepared tables, documented decisions, validation and delivery.
Example checked October 22, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.