Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions us/poverty/michigan_under_age_1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "intro",
"metadata": {},
"source": [
"# Number of Children Under Age 1 in Michigan\n",
"\n",
"Calculates the weighted count of persons with `age < 1` in Michigan.\n",
"\n",
"**Two approaches compared:**\n",
"1. State-specific dataset (`MI.h5`)\n",
"2. National dataset filtered to Michigan via `state_code`\n",
"\n",
"Result: the state dataset significantly undercounts MI population (~4.1M vs actual ~10M), so the national dataset gives the realistic figure."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "imports",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-18T19:49:56.996452Z",
"iopub.status.busy": "2026-05-18T19:49:56.996452Z",
"iopub.status.idle": "2026-05-18T19:50:15.838852Z",
"shell.execute_reply": "2026-05-18T19:50:15.838852Z"
}
},
"outputs": [],
"source": [
"from policyengine_us import Microsimulation\n",
"from huggingface_hub import hf_hub_download\n",
"\n",
"YEAR = 2026"
]
},
{
"cell_type": "markdown",
"id": "md-state",
"metadata": {},
"source": [
"## Approach 1: State-specific MI.h5 dataset"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "state",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-18T19:50:15.841743Z",
"iopub.status.busy": "2026-05-18T19:50:15.841743Z",
"iopub.status.idle": "2026-05-18T19:50:16.968247Z",
"shell.execute_reply": "2026-05-18T19:50:16.968247Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MI total population (state dataset): 4,104,577\n",
"MI children under age 1 (state dataset): 43,689\n"
]
}
],
"source": [
"mi_path = hf_hub_download(\n",
" repo_id=\"policyengine/policyengine-us-data\",\n",
" filename=\"states/MI.h5\",\n",
" repo_type=\"model\",\n",
")\n",
"sim_state = Microsimulation(dataset=mi_path)\n",
"age_state = sim_state.calculate(\"age\", YEAR)\n",
"\n",
"# (boolean_series).sum() applies weights once -> weighted count of True rows\n",
"state_total = (age_state >= 0).sum()\n",
"state_under_1 = (age_state < 1).sum()\n",
"print(f\"MI total population (state dataset): {state_total:,.0f}\")\n",
"print(f\"MI children under age 1 (state dataset): {state_under_1:,.0f}\")"
]
},
{
"cell_type": "markdown",
"id": "md-nat",
"metadata": {},
"source": [
"## Approach 2: National dataset filtered to Michigan"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "national",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-18T19:50:16.971253Z",
"iopub.status.busy": "2026-05-18T19:50:16.970256Z",
"iopub.status.idle": "2026-05-18T19:50:17.298029Z",
"shell.execute_reply": "2026-05-18T19:50:17.298029Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MI total population (national dataset): 10,106,712\n",
"MI children under age 1 (national dataset): 101,162\n"
]
}
],
"source": [
"sim_nat = Microsimulation()\n",
"age_nat = sim_nat.calculate(\"age\", YEAR).values\n",
"weight_nat = sim_nat.calculate(\"person_weight\", YEAR).values\n",
"state_code_person = sim_nat.calculate(\"state_code\", YEAR, map_to=\"person\").values\n",
"\n",
"in_mi = state_code_person == \"MI\"\n",
"mi_total = float(weight_nat[in_mi].sum())\n",
"mi_under_1 = float(weight_nat[(age_nat < 1) & in_mi].sum())\n",
"print(f\"MI total population (national dataset): {mi_total:,.0f}\")\n",
"print(f\"MI children under age 1 (national dataset): {mi_under_1:,.0f}\")"
]
},
{
"cell_type": "markdown",
"id": "md-cmp",
"metadata": {},
"source": [
"## Comparison"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "compare",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-18T19:50:17.301058Z",
"iopub.status.busy": "2026-05-18T19:50:17.300058Z",
"iopub.status.idle": "2026-05-18T19:50:17.304642Z",
"shell.execute_reply": "2026-05-18T19:50:17.304642Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Source MI total Age < 1\n",
"----------------------------------------------------------------\n",
"State MI.h5 dataset 4,104,577 43,689\n",
"National dataset (filter to MI) 10,106,712 101,162\n",
"Census / MDHHS (real-world) ~10,100,000 ~104,000\n"
]
}
],
"source": [
"print(f\"{'Source':<35} {'MI total':>15} {'Age < 1':>12}\")\n",
"print(\"-\" * 64)\n",
"print(f\"{'State MI.h5 dataset':<35} {state_total:>15,.0f} {state_under_1:>12,.0f}\")\n",
"print(f\"{'National dataset (filter to MI)':<35} {mi_total:>15,.0f} {mi_under_1:>12,.0f}\")\n",
"print(f\"{'Census / MDHHS (real-world)':<35} {'~10,100,000':>15} {'~104,000':>12}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
11 changes: 11 additions & 0 deletions us/searchlight_institute/reform_1_10year_budgetary_impact.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Year,Budgetary Impact
2026,-154164001783.69482
2027,-157864084761.3623
2028,-164597276521.37793
2029,-167287528290.4707
2030,-175556385052.03516
2031,-169573356121.84375
2032,-176599302199.34863
2033,-178463440201.4834
2034,-177017552448.71387
2035,-180123710118.63232
Loading