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

Issue:
Parameterize the age in the `is_person_demographic_tanf_eligible` variable 
[Currently hard coded](https://github.com/PolicyEngine/policyengine-us/blob/master/policyengine_us/variables/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.py#L12)


In #4954 we will add a parallel structure for NC demographic eligibility which should be accessing the same parameter 


Discussion / hints:
Does the US or states define this?
I am seeing it [here](https://www.law.cornell.edu/cfr/text/45/260.30)

Fix patch:
diff --git a/changelog_entry.yaml b/changelog_entry.yaml
index e69de29bb2d..c9b9a683bad 100644
--- a/changelog_entry.yaml
+++ b/changelog_entry.yaml
@@ -0,0 +1,4 @@
+- bump: minor
+  changes:
+    added:
+    - Parameterize the age in is_person_demographic_tanf_eligible.
diff --git a/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/non_student.yaml b/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/non_student.yaml
new file mode 100644
index 00000000000..b32b3d1782e
--- /dev/null
+++ b/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/non_student.yaml
@@ -0,0 +1,12 @@
+description: The Temporary Assistance for Needy Families (TANF) program defines one of the qualifying criteria of a minor child as an individual who has not yet reached this age.
+
+values:
+  2010-07-01: 18
+
+metadata:
+  unit: year
+  period: year
+  label: TANF minor child non student age limit
+  reference:
+    - title: 45 CFR § 260.30 - What definitions apply under the TANF regulations?
+      href: https://www.law.cornell.edu/cfr/text/45/260.30
diff --git a/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/student.yaml b/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/student.yaml
new file mode 100644
index 00000000000..9cc01c318cd
--- /dev/null
+++ b/policyengine_us/parameters/gov/hhs/tanf/cash/eligibility/age_limit/student.yaml
@@ -0,0 +1,12 @@
+description: The Temporary Assistance for Needy Families (TANF) program defines one of the qualifying criteria of a minor child as an individual who has not yet reached this age and is a full-time student in a secondary school (or an equivalent level of vocational or technical training).
+
+values:
+  2010-07-01: 19
+
+metadata:
+  unit: year
+  period: year
+  label: TANF minor child student age limit
+  reference:
+    - title: 45 CFR § 260.30 - What definitions apply under the TANF regulations?
+      href: https://www.law.cornell.edu/cfr/text/45/260.30
diff --git a/policyengine_us/variables/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.py b/policyengine_us/variables/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.py
index f4cf90c3341..ef3b8853d6f 100644
--- a/policyengine_us/variables/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.py
+++ b/policyengine_us/variables/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.py
@@ -6,11 +6,20 @@ class is_person_demographic_tanf_eligible(Variable):
     entity = Person
     definition_period = YEAR
     label = "Person-level eligiblity for TANF based on age, pregnancy, etc."
+    reference = "https://www.law.cornell.edu/cfr/text/45/260.30"
 
     def formula(person, period, parameters):
-        child_0_17 = person("is_child", period)
-        is_18 = person("age", period) == 18
-        full_time_student = person("is_full_time_student", period)
-        school_enrolled_18_year_old = full_time_student & is_18
+        p = parameters(period).gov.hhs.tanf.cash.eligibility.age_limit
+        age = person("age", period)
+        age_eligible_if_student = age < p.student
+        age_eligible_non_student = age < p.non_student
+        secondary_school_student = person("is_in_secondary_school", period)
+        age_eligible_secondary_school_student = (
+            secondary_school_student & age_eligible_if_student
+        )
         pregnant = person("is_pregnant", period)
-        return child_0_17 | school_enrolled_18_year_old | pregnant
+        return (
+            age_eligible_non_student
+            | age_eligible_secondary_school_student
+            | pregnant
+        )
diff --git a/policyengine_us/variables/household/demographic/person/is_in_secondary_school.py b/policyengine_us/variables/household/demographic/person/is_in_secondary_school.py
new file mode 100644
index 00000000000..e2d626f5887
--- /dev/null
+++ b/policyengine_us/variables/household/demographic/person/is_in_secondary_school.py
@@ -0,0 +1,8 @@
+from policyengine_us.model_api import *
+
+
+class is_in_secondary_school(Variable):
+    value_type = bool
+    entity = Person
+    label = "Is in secondary school (or in an equivalent level of training)"
+    definition_period = YEAR


Test patch:
diff --git a/policyengine_us/tests/policy/baseline/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.yaml b/policyengine_us/tests/policy/baseline/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.yaml
index da944cf78f5..e40924e042a 100644
--- a/policyengine_us/tests/policy/baseline/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.yaml
+++ b/policyengine_us/tests/policy/baseline/gov/hhs/tanf/cash/eligibility/is_person_demographic_tanf_eligible.yaml
@@ -7,6 +7,7 @@
   period: 2022
   input:
     age: 17
+    is_in_secondary_school: false
   output:
     is_person_demographic_tanf_eligible: true
 
@@ -14,6 +15,7 @@
   period: 2022
   input:
     age: 18
+    is_in_secondary_school: false
   output:
     is_person_demographic_tanf_eligible: false
 
@@ -28,6 +30,6 @@
   period: 2022
   input:
     age: 18
-    is_full_time_student: true
+    is_in_secondary_school: true
   output:
     is_person_demographic_tanf_eligible: true
diff --git a/policyengine_us/tests/policy/baseline/gov/states/co/cdhs/tanf/co_tanf_integration.yaml b/policyengine_us/tests/policy/baseline/gov/states/co/cdhs/tanf/co_tanf_integration.yaml
index ec377818f8a..55ad1de4bf2 100644
--- a/policyengine_us/tests/policy/baseline/gov/states/co/cdhs/tanf/co_tanf_integration.yaml
+++ b/policyengine_us/tests/policy/baseline/gov/states/co/cdhs/tanf/co_tanf_integration.yaml
@@ -4,8 +4,10 @@
     people:
       person1:
         is_adult: true
+        age: 40
       person2:
         is_child: true
+        age: 12
     spm_units:
       spm_unit:
         members: [person1, person2]
@@ -32,30 +34,43 @@
       adult2:
         is_adult: true
         is_pregnant: true
+        age: 29
       child1:
         is_child: true
+        age: 11
       child2:
         is_child: true
+        age: 12
       child3:
         is_child: true
+        age: 6
       child4:
         is_child: true
+        age: 6
       child5:
         is_child: true
+        age: 7
       child6:
         is_child: true
+        age: 4
       child7:
         is_child: true
+        age: 5
       child8:
         is_child: true
+        age: 13
       child9:
         is_child: true
+        age: 11
       child10:
         is_child: true
+        age: 11
       child11:
         is_child: true
+        age: 11
       child12:
         is_child: true
+        age: 11
     spm_units:
       spm_unit:
         members: [adult1, adult2, child1, child2, child3, child4, child5, child6, child7, child8, child9, child10, child11, child12]
@@ -68,3 +83,4 @@
         state_code: CO
   output:
     co_tanf: 19_868
+