Repository: PolicyEngine/policyengine-canada (language: python)

Issue:
Manitoba Child Benefit
Reference: https://www.gov.mb.ca/fs/eia/mcb.html


Discussion / hints:

Fix patch:
diff --git a/changelog_entry.yaml b/changelog_entry.yaml
index e69de29bb..deb50016d 100644
--- a/changelog_entry.yaml
+++ b/changelog_entry.yaml
@@ -0,0 +1,4 @@
+- bump: minor
+  changes:
+    added:
+    - Manitoba age amount credit.
diff --git a/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/age_eligibility.yaml b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/age_eligibility.yaml
new file mode 100644
index 000000000..a7bcbef8a
--- /dev/null
+++ b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/age_eligibility.yaml
@@ -0,0 +1,13 @@
+description: Manitoba limits the age amount credit for seniors at or above the age. 
+values:
+  2022-01-01: 65
+metadata:
+  unit: year
+  label: Manitoba age amount credit age eligibility
+  reference:
+  - title: 2022 Manitoba Personal Tax Credits Return
+    href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb/td1mb-22e.pdf#page=1
+  - title: 2023 Manitoba Personal Tax Credits Return
+    href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb/td1mb-23e.pdf#page=1 
+  - title: 2023 Manitoba, The Income Tax Act § 4.6(4)
+    href: https://web2.gov.mb.ca/laws/statutes/ccsm/_pdf.php?cap=i10
diff --git a/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/max_amount.yaml b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/max_amount.yaml
new file mode 100644
index 000000000..5cdb8464b
--- /dev/null
+++ b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/max_amount.yaml
@@ -0,0 +1,14 @@
+description: Manitoba limits the age amount credit to the following maximum amount.
+values:
+  2022-01-01: 3_728
+metadata:
+  unit: currency-CAD
+  label: Manitoba age credit maximum amount
+  reference:
+  # Manitoba provides the same maximum age credit amount for both 2022 and 2023
+  - title: 2022 Manitoba Personal Tax Credits Return
+    href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb/td1mb-22e.pdf#page=1
+  - title: 2023 Manitoba Personal Tax Credits Return
+    href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb/td1mb-23e.pdf#page=1
+  - title: 2023 Manitoba, The Income Tax Act § 4.6(4)
+    href: https://web2.gov.mb.ca/laws/statutes/ccsm/_pdf.php?cap=i10
diff --git a/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/phase_out_rate.yaml b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/phase_out_rate.yaml
new file mode 100644
index 000000000..3de2e94df
--- /dev/null
+++ b/policyengine_canada/parameters/gov/provinces/mb/tax/income/credits/age_amount/phase_out_rate.yaml
@@ -0,0 +1,24 @@
+description: Manitoba phases the age credit out at this rate based on income.
+metadata:
+  type: marginal_rate
+  threshold_unit: currency-CAD
+  rate_unit: /1
+  label: Manitoba age amount credit phase out rate
+  reference:
+  - title:  Worksheet for the 2022 Manitoba Personal Tax Credits Return
+    href: https://www.cchwebsites.com/content/pdf/tax_forms/ca/en/td1mbws_en.pdf#page=1
+  - title:  Worksheet for the 2023 Manitoba Personal Tax Credits Return
+    href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb-ws/td1mb-ws-23e.pdf#page=1
+  - title: 2023 Manitoba, The Income Tax Act § 4.6(4)
+    href: https://web2.gov.mb.ca/laws/statutes/ccsm/_pdf.php?cap=i10
+
+brackets:
+  - threshold:
+      2022-01-01: 0
+    rate:
+      2022-01-01: 0
+  - threshold:
+      2022-01-01: 27_749
+    rate:
+      2022-01-01: 0.15 
+
diff --git a/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.py b/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.py
new file mode 100644
index 000000000..438a92f2d
--- /dev/null
+++ b/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.py
@@ -0,0 +1,16 @@
+from policyengine_canada.model_api import *
+
+
+class mb_age_credit(Variable):
+    value_type = float
+    entity = Person
+    label = "Manitoba age credit amount"
+    definition_period = YEAR
+    defined_for = "mb_age_credit_eligible"
+    reference = "https://www.cchwebsites.com/content/pdf/tax_forms/ca/en/td1mbws_en.pdf#page=1"
+
+    def formula(person, period, parameters):
+        age = person("age", period)
+        income = person("individual_net_income", period)
+        p = parameters(period).gov.provinces.mb.tax.income.credits.age_amount
+        return max_(p.max_amount - p.phase_out_rate.calc(income), 0)
diff --git a/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.py b/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.py
new file mode 100644
index 000000000..3cdb000a1
--- /dev/null
+++ b/policyengine_canada/variables/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.py
@@ -0,0 +1,15 @@
+from policyengine_canada.model_api import *
+
+
+class mb_age_credit_eligible(Variable):
+    value_type = bool
+    entity = Person
+    label = "Manitoba age credit eligibility"
+    definition_period = YEAR
+    reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1mb/td1mb-22e.pdf#page=1"
+    defined_for = ProvinceCode.MB
+
+    def formula(person, period, parameters):
+        p = parameters(period).gov.provinces.mb.tax.income.credits.age_amount
+        age = person("age", period)
+        return age >= p.age_eligibility


Test patch:
diff --git a/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.yaml b/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.yaml
new file mode 100644
index 000000000..ddcdb25d1
--- /dev/null
+++ b/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit.yaml
@@ -0,0 +1,35 @@
+- name: Ineligible
+  period: 2023
+  input:
+    province_code: MB
+    mb_age_credit_eligible: false
+    individual_net_income: 20_000
+  output:
+    mb_age_credit: 0
+
+- name: Eligible under phase-out income
+  period: 2023
+  input:
+    province_code: MB
+    mb_age_credit_eligible: true
+    individual_net_income: 20_000
+  output:
+    mb_age_credit: 3_728
+
+- name: Eligible over phase-out income # 3_728 - ((37_749 - 27_749) * 0.15)
+  period: 2023
+  input:
+    province_code: MB
+    mb_age_credit_eligible: true
+    individual_net_income: 37_749
+  output:
+    mb_age_credit: 2_228
+
+- name: Eligible over maximum phase-out income # max_(3_728 - ((100_000 - 27_749) * 0.15),0)
+  period: 2023
+  input:
+    province_code: MB
+    mb_age_credit_eligible: true
+    individual_net_income: 100_000
+  output:
+    mb_age_credit: 0
diff --git a/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.yaml b/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.yaml
new file mode 100644
index 000000000..9481f4117
--- /dev/null
+++ b/policyengine_canada/tests/gov/provinces/mb/tax/income/credits/age_amount/mb_age_credit_eligible.yaml
@@ -0,0 +1,15 @@
+- name: Ineligible Age
+  period: 2023
+  input:
+    province_code: MB
+    age: 64
+  output:
+    mb_age_credit_eligible: false
+
+- name: Eligible Age
+  period: 2023
+  input:
+    province_code: MB
+    age: 65
+  output:
+    mb_age_credit_eligible: true