Skip to content

Floor Montana's joint-return medical and standard deductions on the return's Montana AGI, and on federal AGI from 2024 - #9903

Merged
MaxGhenis merged 2 commits into
mainfrom
fix-mt-medical-floor-joint-agi
Oct 10, 2026
Merged

MaxGhenis merged 2 commits into
mainfrom
fix-mt-medical-floor-joint-agi

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Montana's joint-path medical expense deduction and standard deduction computed their AGI base as add(tax_unit, ["mt_agi_indiv"]): the sum of each spouse's Montana AGI, each floored at zero. A joint return's Montana AGI is one figure that pools both spouses' income first, which PE already computes as mt_agi_joint and uses for taxable income. A spouse's loss was not fully reflected in those deductions: shared federal adjustments already reduced the old AGI base, but separately zero-clipped Montana AGIs still discarded part of the loss. In the medical example below, that partial effect produced $3,250 instead of the $2,500 without the loss; pooling the return's AGI correctly produces $4,000.

Checking whether the medical variable is still used from 2024 found a larger problem. It is: every non-separate Montana return (single, head of household, joint) reaches it through mt_itemized_deductions_joint, which feeds mt_taxable_income_joint in every year. From 2024, though, mt_agi_indiv is switched off (defined_for = mt_married_filing_separately_on_same_return_eligible, false from 2024 after #6348 / 2a20d65). The floor therefore became 7.5% × 0, and every Montana itemizer deducted their full medical expenses. From 2024, Form 2 line 2 takes federal itemized deductions, so the variable now carries the federal medical expense deduction (7.5% of federal AGI).

What the forms say

2021–2023 Form 2, Itemized Deductions Schedule (2022 Form 2, PDF p. 7; 2021 and 2023 are the same on p. 7):

1b Enter the amount from page 1, line 14
1c Multiply line 1b by 7.5% (0.075)
… This is your deductible medical and dental expenses subject to a percentage of Montana Adjusted Gross Income.

Same page, Standard Deduction Worksheet:

When filing separately on the same form, each spouse must figure their own deduction.
1 Enter your Montana Adjusted Gross Income from page 1, line 14
2 Multiply the amount on line 1 by 20% (0.20)

Form 2 page 1 (same PDF, p. 1). Line 14 is "Montana Adjusted Gross Income. Add lines 11 and 12, then subtract line 13." Line 11 is federal AGI. The amounts go in Column A; Column B is headed "for spouse when filing separately using filing status 2a". So a joint return (status 4) has one line 14 for the couple, and line 11 is the joint federal AGI. Only status 2a gives each spouse their own line 14. The 2022 instructions (PDF p. 32, printed p. 26) send line 1 back to "the instructions for lines 1c and 2". The 2021 instructions (PDF p. 31) and 2023 instructions (PDF p. 36) say the same.

Statute. Former MCA § 15-30-2131(1)(a) (MCA 2021, mca.legmt.gov) allows "the items referred to in sections 161 … and 211 of the Internal Revenue Code", which brings in the § 213 medical deduction and its 7.5%-of-AGI floor. The statute does not say which AGI; the form uses Montana AGI from line 14. The old code comment cited (1)(g)(i), which covers insurance premiums, so it now cites (1)(a).

From 2024 (2024 instructions, PDF p. 15, printed p. 7). Form 2 line 1 is "Federal adjusted gross income from Form 1040, line 11". Line 2 is the "Federal standard deduction or adjusted federal itemized deductions". Worksheet A line 1 reads: "Enter your total federal itemized deductions from Form 1040, line 12". It then removes state income tax and takes the greater of that and the federal standard deduction. PDF p. 8 lists the Itemized Deductions Schedule and the Standard Deduction Worksheet as discontinued. So from 2024 the medical component is federal Schedule A's: 7.5% of federal AGI (2024 Schedule A, PDF p. 1, lines 1–4).

Changes

  • mt_medical_expense_deduction_joint:
    • 2021–2023: max(0, itemized_medical_expenses − 7.5% × mt_agi_joint).
    • From 2024: the federal medical_expense_deduction (7.5% × positive_agi).
    • Either way it is held by the head only.
  • mt_standard_deduction_joint (2021–2023 branch): 20% × mt_agi_joint, held between the existing minimum and maximum. Its 2024+ branch, the federal standard deduction, is unchanged.
  • New parameter gov.states.mt.tax.income.deductions.itemized.state_specific_deduction_applies (true 2021, false 2024). It mirrors the existing deductions.standard.state_specific_deduction_applies.
  • The separate-filing variants (_indiv) are unchanged. On status 2a each spouse's column has its own line 14, which is mt_agi_indiv.

Household effects (real runs on main b79705b and this branch)

Case Montana deduction Montana income tax
2021 couple: head wages $100k and $10k medical, spouse self-employment −$20k medical $3,250 → $4,000 (Montana AGI $80,000, not $90,000) $1,398.22 → $1,361.65
2022 couple: head wages $50k, spouse self-employment −$10k standard $9,000 → $8,000 (20% × $40,000) $1,124.15 → $1,191.65
2024 single: wages $100k, $30k medical medical $30,000 → $22,500 $3,884.00 → $4,326.50
2026 couple: wages $120k, $40k medical medical $40,000 → $31,000; now takes the $32,200 standard deduction $3,760.00 → $4,126.60

Script and outputs: ~/reviews/mt-medical-floor-2026-10-06/household_examples.py, household_base.json, household_pr.json.

Hub microsimulation impact

Completed archival run from October 6, 2026, for tax year 2026, comparing former main b79705b with PR head 7fb88f0. Both used hf://datasets/policyengine/populace-us/populace_us_2024.h5@populace-us-2024-spm-20260909. This is the prior run, not a comparison against today's main; this review round changes tests and the description only.

Variable Weighted base total Weighted PR total Change Changed records Weighted affected entities
Montana income tax $2,277,244,447.68 $2,294,828,906.03 +$17,584,458.35 97 tax units 41,617.08 tax units
Joint medical deduction $3,335,573,763.67 $1,241,226,363.74 −$2,094,347,399.93 807 people 486,570.75 people
Joint itemized deductions $5,742,085,747.64 $3,647,738,317.43 −$2,094,347,430.21 807 people 486,570.75 people
Joint taxable income $46,880,465,090.73 $47,201,666,545.48 +$321,201,454.75 97 people 41,617.08 people

All 97 affected tax-unit records pay more; none pay less. The largest tax increase is $1,374.06. Person-level deduction and taxable-income variables are allocated to heads; their weighted affected-entity counts retain that entity label. Weighted tax change is recomputed as sum((PR − base) × weight), using identical saved weights and entity ordering; rounding the displayed totals can differ by one cent.

Evidence: ~/reviews/mt-medical-floor-2026-10-06/impact_2026.json, the completed impact_queue.sh (which records the compared heads), and ~/reviews/pe-us-merge-backlog-2026-10-02/impact/out/mtmedfl-{base,pr}.2026.{json,log} with the per-variable arrays. The output metadata records the year and pinned dataset; the head provenance comes from the queue script. This round recomputed the comparison from the saved arrays without launching a microsimulation. The hub can append a current-main comparison here if its landing gate requires one.

Tests

  • mt_medical_expense_deduction_joint.yaml:
    • Existing cases now give mt_agi_joint as the input.
    • New: the negative-income spouse case ($4,000; main gives $3,250).
    • New: a 2023 case on Montana AGI that ignores the federal deduction.
    • New: a 2024 case that carries the federal deduction through.
    • New: a 2024 age-70 case where Montana AGI ($94,500, after the $5,500 subtraction) differs from federal AGI ($100,000); the deduction is $2,500, on federal AGI.
    • Static comparison with the former main predicts failures in 5 of the 7 cases.
  • mt_standard_deduction_joint.yaml: existing cases moved to mt_agi_joint. New negative-income spouse case: $8,000, where main gives $9,000.
  • tests/unit/test_mt_joint_agi_deductions_properties.py: one vectorized grid simulation with 256 couples (with and without a dependent child) and 48 single filers, over 2021–2025, plus eight Hypothesis-generated batches over 2021–2026 with fixed witnesses for losses, dependent expenses, and senior subtractions. Static comparison with the former main predicts failures in 8 of the original 14 deterministic cases. The other 6 are premise checks and the single-filer agreement, which already held.
  • Prior-round verification ran both YAML files above and the original property file one at a time, plus these unchanged neighbours. Their reported passes are prior-round results; this round reruns the medical deduction file and both added/changed coverage files:
    • mt/tax/income/integration.yaml, mt_income_tax*.yaml, mt_taxable_income_joint.yaml, mt_regular_income_tax_joint.yaml;
    • mt_itemized_deductions_joint.yaml, mt_itemized_deductions_for_federal_itemization_joint.yaml;
    • mt_standard_deduction_indiv.yaml, mt_medical_expense_deduction_indiv.yaml;
    • states/tax/income/state_itemized_deductions.yaml, state_standard_deduction.yaml, irs/salt_refund_integration.yaml;
    • test_parameter_files.py and the reference-URL code-health tests.

Invariants (asserted by the deterministic grid and generated checks)

  1. 2021–2023: the medical deduction equals max(0, medical expenses − 7.5% × the return's Montana AGI). The standard deduction equals clip(20% × that AGI, minimum, maximum). For this grid, Montana AGI is max(0, federal AGI), and that premise is asserted too.
  2. Transfer invariance: moving the spouse's self-employment income to the head changes neither deduction when the return's applicable AGI and medical expenses are fixed. This is the property main violates.
  3. Each deduction is held once, by the head; other members hold 0.
  4. Bounds: 0 ≤ medical deduction ≤ medical expenses.
  5. Differential (deterministic grid): for single filers the joint and separate variants of both deductions agree, 2021–2023.
  6. From 2024 the medical deduction equals the federal medical expense deduction, including where Montana AGI differs from federal AGI.

Non-vacuity guards check, for each state-schedule year, that pooling changes the result somewhere on the grid. Hypothesis checks the same pooling, transfer, head-allocation, bounds and post-2024 federal-equivalence invariants; Medicare enrollment is disabled in the generated twins so expenses stay fixed when income is transferred. Generated cases include an older second adult; allocation is checked against the model's is_tax_unit_head flag rather than input order, with exactly one head asserted per return.

The new joint_agi_deductions_integration.yaml adds eight downstream cases: 2022 medical-floor selection below/at/above a controlled competing separate tax, the 2022 standard-loss example, and 2024 capital-gains threshold neighbors plus a medical itemizer. Both deduction aggregates, state deductions, selected filing treatment, taxable income, capital-gains tax and final tax are asserted. Hand arithmetic and source page anchors are recorded in comments; the separate-tax comparator is explicitly supplied to isolate the selection boundary.

Current-round runtime verification, one file at a time: 30 passed — 7 medical YAML cases, 8 downstream integration cases, and 15 property tests (14 deterministic tests plus the Hypothesis test with eight batches across 2021–2026). A counterfactual replay on this checkout using the exact pre-PR medical and standard formulas from b79705b4bd produced 7 failures and 1 pass when restricted to mt_files_separately and mt_income_tax; all assertions in the eight integration cases pass with the PR formulas. The first generated run exposed a test-fixture input-order assumption about head selection; the fixture now checks the calculated head and retains the minimized older-second-adult witness. The full property file then passed with the prescribed command. Ruff format/lint and git diff --check passed. A local description audit failed four checks on the original body and passes all five on this revision, including verbatim preservation of the axiom: line. Logs, the failing replay, and the initial fixture failure remain untracked in the assigned workspace's hub-evidence/ directory.

Methodology

  • Montana AGI below zero (2021–2023): retain the existing zero-clipping convention in mt_agi_joint, as on main; for the no-Social-Security cases here this is max(0, signed Montana AGI). The alternative is to use signed Form 2 line 14 literally in the medical worksheet. With line 14 = −$20,000 and expenses = $10,000, that alternative yields $10,000 − 7.5% × (−$20,000) = $11,500; the retained convention yields $10,000 and limits the deduction to expenses paid. 2022 Form 2, PDF pp. 1 and 7 does not explicitly resolve a negative medical-floor base. This PR changes pooling of spouses' incomes, but does not change this convention relative to main.
  • Return-level base and 2024 transition: use the joint return's Montana AGI through 2023, then the federal medical deduction from 2024. The alternatives are the sum of individually zero-clipped AGIs before 2024 or the discontinued Montana worksheet thereafter. 2022 Form 2, PDF p. 7 and 2024 instructions, PDF p. 15 support the selected reading. These choices change results relative to the former main comparison shown above. This review round adds coverage and documentation without changing model behavior.

Tax precision in regression expectations: retain main's unrounded marginal-rate calculation. The alternative is the rounded offset in the 2022 Form 2 tax table, PDF p. 8: $603 rather than the model's $602.50. The tests document this inherited precision difference and do not change it relative to main.

Review round

Corrected the loss mechanism and distinguished Axiom's 2026 coverage from the queued 2024–2025 years. Recovered the completed 2026 population impact evidence and added downstream regressions plus Hypothesis checks to cover filing selection, federal-itemization aggregates, state deductions, capital-gains thresholds, and final Montana tax. Partner contract tests remain untouched. No model formulas, policy conventions, merges, or new microsimulation runs are included in this round.

Coordination

Out of scope (filed separately)

  • Montana's taxsim_state_agi sums mt_agi_indiv (gov.states.household.state_agis). For 2021–2023 that misses pooling on joint returns, and from 2024 it is 0.
  • 2021–2023 Montana deducts medical insurance premiums in full on line 2 (former § 15-30-2131(1)(g)(i)). PE puts them under the 7.5% floor in both variants.

Axiom scope clarification: the federal module's encoded coverage starts in 2026 (effective_from: 2026-01-01 in 26/213). Federal years 2024–2025 and the historical Montana provisions remain queued in issue #1520. The hub's axiom: line below is preserved verbatim; its “2024+” wording does not establish encoded coverage for 2024–2025.

axiom: us/statute/26/213 encoded-correct for the 2024+ federal floor (us/statutes/26/213.yaml, companion test tax_unit_medical_expense_deduction_after_section_21_exclusion; the Montana 2026 pipeline takes federal itemized deductions as input mt_pit_2026_federal_itemized_deduction) | TheAxiomFoundation/rulespec-us#1520 queued for the 2021–2023 Montana schedule (former MCA § 15-30-2131(1)(a) medical floor and the Standard Deduction Worksheet on the return's Montana AGI)

🤖 Generated with Claude Code

…eturn's Montana AGI

The 2021-2023 Form 2 Itemized Deductions Schedule (line 1b) and Standard
Deduction Worksheet (line 1) take Montana AGI from page 1, line 14. Single,
head of household and joint returns report that line in one column, so a
joint return pools both spouses' income before flooring at zero. Both
joint-path variables instead summed each spouse's mt_agi_indiv, which floors
each spouse at zero first, so a spouse's loss never offset the other's
income. They now use mt_agi_joint.

From 2024 mt_agi_indiv is switched off (Montana repealed filing separately
on the same form), so the joint medical floor fell to zero and the full
medical expense was deducted. From 2024 Form 2 line 2 takes federal
itemized deductions (Worksheet A), so the variable now carries the federal
medical expense deduction (7.5% of federal AGI). A new parameter,
gov.states.mt.tax.income.deductions.itemized.state_specific_deduction_applies,
marks the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis closed this Oct 10, 2026
@MaxGhenis MaxGhenis reopened this Oct 10, 2026
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Reopened by the US + core hub to start a fresh CI run at the same head. The previous run failed on test_spm_system.py, which broke on every pull request when policyengine-core 3.33.1 was released; #10069 fixed it on main at 20:42Z on 2026-10-10. Nothing in this pull request changed.

@MaxGhenis
MaxGhenis merged commit 51487d5 into main Oct 10, 2026
51 of 52 checks passed
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

US + core hub merge audit, us#9903 at dc5b0f2bd44485326ba7630e6765ac0e50ca88bc (squash): floor Montana's joint-return medical and standard deductions on the return's Montana AGI, and on federal AGI from 2024.

  • Adopted from the open-PR backlog on 2026-10-10: ready since 10/06, with no hand-off and no review on file.
  • Review: independent GPT-6.1 Sol review r1 requested changes (impact missing; three body notes). A hub fix round added the impact, eight downstream cases and a Hypothesis test, with no model change. Delta review r2 approves this exact head, with no P1 or P2. It recomputed the new expectations by hand and ran no tests; CI at this head ran them.
  • Readings: the return-level base through 2023 and the federal deduction from 2024 follow the 2022 Form 2 (p. 7) and the 2024 instructions (p. 15). Two conventions are kept from main and not changed here: Montana AGI is floored at zero before the 7.5% floor, so the deduction never exceeds the expenses paid; and tax uses the unrounded $602.50 offset where the printed table shows $603.
  • Impact (in the body): tax year 2026, former main b79705b4bd against 7fb88f0abf, default dataset: +$17,584,458 Montana income tax, 41,617 weighted tax units affected. The run dates from 2026-10-06. The commits since then change tests and the description only, so the hub did not re-run it against today's main.
  • Gates checked live at merge:
    • gh pr checks exits 0;
    • the latest Pull request run at the head concluded success (a fresh run after the core 3.33.1 test fix, us#10069);
    • MERGEABLE, not a draft, no CHANGES_REQUESTED;
    • the semantic-overlap guard;
    • head pinned.
  • Axiom: the body's axiom: line is unchanged from the reviewed form (26 U.S.C. 213 encoded for the 2024+ federal floor; Montana 2024–2025 queued in rulespec-us#1520).
  • --admin: used only because a required approving review is the sole block.

@MaxGhenis
MaxGhenis deleted the fix-mt-medical-floor-joint-agi branch October 10, 2026 22:45
MaxGhenis added a commit that referenced this pull request Oct 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DTrim99 added a commit to DTrim99/policyengine-us that referenced this pull request Oct 12, 2026
… return

mt_agi_joint pooled every tax unit member's Montana additions and
subtractions, but a dependent's federal AGI is not on the filer's return
(adjusted_gross_income_person is zero for dependents). A dependent's
subtraction, such as unemployment compensation, therefore lowered the
filer's Montana AGI and, since main's PolicyEngine#9903, the joint standard
deduction. Pool additions and subtractions over the head and spouse only.

The adult-dependent exemption case had pinned the leaked AGI of 47,000;
under the law the filer's Montana AGI is 50,000 and the tax is 1,731.65.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LqCGPgxDukji8Bhs57c5rH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant