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

Issue:
Los Angeles Infant Supplement and Expectant Parent Payment age threshold
[Reference](https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?lawCode=WIC&sectionNum=11400.)


Discussion / hints:

Fix patch:
diff --git a/changelog_entry.yaml b/changelog_entry.yaml
index e69de29bb2d..288a51ef3d0 100644
--- a/changelog_entry.yaml
+++ b/changelog_entry.yaml
@@ -0,0 +1,6 @@
+- bump: patch
+  changes:
+    fixed:
+    - Los Angeles Infant Supplement and Expectant Parent Payment age threshold.
+    added:
+    - Monthly age variable.
diff --git a/policyengine_us/parameters/gov/states/ca/foster_care/age_threshold.yaml b/policyengine_us/parameters/gov/states/ca/foster_care/age_threshold.yaml
new file mode 100644
index 00000000000..f1c27c11c79
--- /dev/null
+++ b/policyengine_us/parameters/gov/states/ca/foster_care/age_threshold.yaml
@@ -0,0 +1,13 @@
+description: California considers the foster child a minor dependent below the following age.
+values:
+  2011-01-01: 18
+  2012-01-01: 19
+  2013-01-01: 20
+  2014-01-01: 21
+metadata:
+  unit: year
+  period: year
+  label: California foster care minor dependent age threshold
+  reference:
+    - title: California Welfare and Institutions Code, Division 9, Part 3, Chapter 2, Article 5, Section 11400 (v)(1)
+      href: https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?lawCode=WIC&sectionNum=11400.
diff --git a/policyengine_us/variables/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.py b/policyengine_us/variables/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.py
index a36565ca6c3..4409a9f9399 100644
--- a/policyengine_us/variables/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.py
+++ b/policyengine_us/variables/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.py
@@ -9,10 +9,12 @@ class ca_la_expectant_parent_payment_eligible(Variable):
     defined_for = "in_la"
 
     def formula(person, period, parameters):
-        foster_care = person("is_in_foster_care", period)
         pregnancy_month = person("current_pregnancy_month", period)
         p = parameters(period).gov.local.ca.la.dss.expectant_parent_payment
         eligible_based_on_pregnancy_month = (
             p.pregnancy_month.min <= pregnancy_month <= p.pregnancy_month.max
         )
-        return foster_care & eligible_based_on_pregnancy_month
+        foster_care_minor_dependent = person(
+            "ca_foster_care_minor_dependent", period
+        )
+        return foster_care_minor_dependent & eligible_based_on_pregnancy_month
diff --git a/policyengine_us/variables/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.py b/policyengine_us/variables/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.py
index 1fc283e772e..124eb946e99 100644
--- a/policyengine_us/variables/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.py
+++ b/policyengine_us/variables/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.py
@@ -9,6 +9,9 @@ class ca_la_infant_supplement_eligible_person(Variable):
     defined_for = "in_la"
 
     def formula(person, period, parameters):
-        foster_care = person("is_in_foster_care", period)
         is_parent = person("is_pregnant", period)
-        return foster_care & is_parent
+        # Needed as numeric yearly variables get divided by 12 in monthly formulas.
+        foster_care_minor_dependent = person(
+            "ca_foster_care_minor_dependent", period
+        )
+        return foster_care_minor_dependent & is_parent
diff --git a/policyengine_us/variables/gov/states/ca/ca_foster_care_minor_dependent.py b/policyengine_us/variables/gov/states/ca/ca_foster_care_minor_dependent.py
new file mode 100644
index 00000000000..c9c51a41dc4
--- /dev/null
+++ b/policyengine_us/variables/gov/states/ca/ca_foster_care_minor_dependent.py
@@ -0,0 +1,16 @@
+from policyengine_us.model_api import *
+
+
+class ca_foster_care_minor_dependent(Variable):
+    value_type = bool
+    entity = Person
+    label = "California foster care minor dependent"
+    definition_period = MONTH
+    defined_for = StateCode.CA
+
+    def formula(person, period, parameters):
+        age = person("monthly_age", period)
+        p = parameters(period).gov.states.ca.foster_care
+        age_eligible = age < p.age_threshold
+        in_foster_care = person("is_in_foster_care", period)
+        return age_eligible & in_foster_care
diff --git a/policyengine_us/variables/household/demographic/age/monthly_age.py b/policyengine_us/variables/household/demographic/age/monthly_age.py
new file mode 100644
index 00000000000..203cf641bf7
--- /dev/null
+++ b/policyengine_us/variables/household/demographic/age/monthly_age.py
@@ -0,0 +1,14 @@
+from policyengine_us.model_api import *
+
+
+class monthly_age(Variable):
+    value_type = float
+    entity = Person
+    label = "Monthly age"
+    definition_period = MONTH
+
+    def formula(person, period, parameters):
+        # We divide annual variables by 12 when bringing them down to a month.
+        # This reverses that to preserve the true age.
+        yearly_age = person("age", period)
+        return yearly_age * MONTHS_IN_YEAR


Test patch:
diff --git a/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.yaml b/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.yaml
index 3023ec26ba8..51821614890 100644
--- a/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.yaml
+++ b/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/expectant_parent_payment/ca_la_expectant_parent_payment_eligible.yaml
@@ -1,44 +1,44 @@
 - name: Eligible person, 
   period: 2022-01
   input:
-    in_la: True
-    is_in_foster_care: True
+    in_la: true
+    ca_foster_care_minor_dependent: true
     current_pregnancy_month: 6
   output:
-    ca_la_expectant_parent_payment_eligible: True
+    ca_la_expectant_parent_payment_eligible: true
 
 - name: Pregnancy month before 6
   period: 2023-01
   input:
-    in_la: True
-    is_in_foster_care: True
+    in_la: true
+    ca_foster_care_minor_dependent: true
     current_pregnancy_month: 5
   output:
-    ca_la_expectant_parent_payment_eligible: False
+    ca_la_expectant_parent_payment_eligible: false
 
 - name: Not in LA
   period: 2023-01
   input:
-    in_la: False
-    is_in_foster_care: True
+    in_la: false
+    ca_foster_care_minor_dependent: true
     current_pregnancy_month: 7
   output:
-    ca_la_expectant_parent_payment_eligible: False
+    ca_la_expectant_parent_payment_eligible: false
 
 - name: Not in foster care
   period: 2024-01
   input:
-    in_la: True
-    is_in_foster_care: False
+    in_la: true
+    ca_foster_care_minor_dependent: false
     current_pregnancy_month: 8
   output:
-    ca_la_expectant_parent_payment_eligible: False
+    ca_la_expectant_parent_payment_eligible: false
 
 - name: Pregnancy month after 9
   period: 2023-01
   input:
-    in_la: True
-    is_in_foster_care: True
+    in_la: true
+    ca_foster_care_minor_dependent: true
     current_pregnancy_month: 10
   output:
-    ca_la_expectant_parent_payment_eligible: False
+    ca_la_expectant_parent_payment_eligible: false
diff --git a/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.yaml b/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.yaml
index f148e12b50a..61a76722cd1 100644
--- a/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.yaml
+++ b/policyengine_us/tests/policy/baseline/gov/local/ca/la/dss/infant_supplement/ca_la_infant_supplement_eligible_person.yaml
@@ -2,7 +2,7 @@
   period: 2022
   input:
     in_la: true
-    is_in_foster_care: true
+    ca_foster_care_minor_dependent: true
     is_pregnant: true
   output:
     ca_la_infant_supplement_eligible_person: true
@@ -11,25 +11,25 @@
   period: 2023
   input:
     in_la: true
-    is_in_foster_care: true
-    is_pregnant: False
+    ca_foster_care_minor_dependent: true
+    is_pregnant: false
   output:
-    ca_la_infant_supplement_eligible_person: False
+    ca_la_infant_supplement_eligible_person: false
 
 - name: Not in LA
   period: 2023
   input:
     in_la: False
-    is_in_foster_care: true
+    ca_foster_care_minor_dependent: true
     is_pregnant: true
   output:
-    ca_la_infant_supplement_eligible_person: False
+    ca_la_infant_supplement_eligible_person: false
 
 - name: Not in foster care
   period: 2024
   input:
     in_la: true
-    is_in_foster_care: False
+    ca_foster_care_minor_dependent: false
     is_pregnant: true
   output:
-    ca_la_infant_supplement_eligible_person: False
+    ca_la_infant_supplement_eligible_person: false
diff --git a/policyengine_us/tests/policy/baseline/gov/states/ca/foster_care/ca_foster_care_minor_dependent.yaml b/policyengine_us/tests/policy/baseline/gov/states/ca/foster_care/ca_foster_care_minor_dependent.yaml
new file mode 100644
index 00000000000..87f64f0fa59
--- /dev/null
+++ b/policyengine_us/tests/policy/baseline/gov/states/ca/foster_care/ca_foster_care_minor_dependent.yaml
@@ -0,0 +1,26 @@
+- name: Eligible foster child
+  period: 2021
+  input:
+    monthly_age: 20
+    state_code: CA
+    is_in_foster_care: true
+  output:
+    ca_foster_care_minor_dependent: true
+
+- name: Not in foster care
+  period: 2021
+  input:
+    monthly_age: 20
+    state_code: CA
+    is_in_foster_care: false
+  output:
+    ca_foster_care_minor_dependent: false
+
+- name: Age ineligible
+  period: 2021
+  input:
+    monthly_age: 21
+    state_code: CA
+    is_in_foster_care: false
+  output:
+    ca_foster_care_minor_dependent: false
diff --git a/policyengine_us/tests/policy/baseline/household/demographic/age/monthly_age.yaml b/policyengine_us/tests/policy/baseline/household/demographic/age/monthly_age.yaml
new file mode 100644
index 00000000000..30bd7c0b267
--- /dev/null
+++ b/policyengine_us/tests/policy/baseline/household/demographic/age/monthly_age.yaml
@@ -0,0 +1,6 @@
+- name: Monthly age conversion
+  period: 2022-01
+  input:
+    age: 21
+  output:
+    monthly_age: 21