@@ -29,6 +29,7 @@ def create_constituency_target_matrix(
2929 if time_period is None :
3030 time_period = dataset .time_period
3131 ages = pd .read_csv (FOLDER / "targets" / "age.csv" )
32+ national_demographics = pd .read_csv (STORAGE_FOLDER / "demographics.csv" )
3233 incomes = pd .read_csv (FOLDER / "targets" / "spi_by_constituency.csv" )
3334 employment_incomes = pd .read_csv (
3435 FOLDER / "targets" / "employment_income.csv"
@@ -83,7 +84,12 @@ def create_constituency_target_matrix(
8384 * national_consistency_adjustment_factor
8485 )
8586
87+ uk_total_population = national_demographics [
88+ national_demographics .name == "uk_population"
89+ ][str (time_period )].values [0 ]
90+
8691 age = sim .calculate ("age" ).values
92+ targets_total_pop = 0
8793 for lower_age in range (0 , 80 , 10 ):
8894 upper_age = lower_age + 10
8995
@@ -100,6 +106,16 @@ def create_constituency_target_matrix(
100106
101107 age_str = f"{ lower_age } _{ upper_age } "
102108 y [f"age/{ age_str } " ] = age_count .values
109+ targets_total_pop += age_count .values .sum ()
110+
111+ # Adjust for consistency
112+ for lower_age in range (80 , 120 , 5 ):
113+ upper_age = lower_age + 5
114+
115+ in_age_band = (age >= lower_age ) & (age < upper_age )
116+
117+ age_str = f"{ lower_age } _{ upper_age } "
118+ y [f"age/{ age_str } " ] *= uk_total_population / targets_total_pop
103119
104120 employment_income = sim .calculate ("employment_income" ).values
105121 bounds = list (
@@ -158,9 +174,6 @@ def create_constituency_target_matrix(
158174 amount_target * adjustment
159175 )
160176
161- if uprate :
162- y = uprate_targets (y , dataset .time_period )
163-
164177 const_2024 = pd .read_csv (STORAGE_FOLDER / "constituencies_2024.csv" )
165178 const_2010 = pd .read_csv (STORAGE_FOLDER / "constituencies_2010.csv" )
166179
@@ -203,29 +216,3 @@ def create_country_mask(
203216 r [i ] = household_countries == constituency_countries [i ]
204217
205218 return r
206-
207-
208- def uprate_targets (y : pd .DataFrame , target_year : int = 2025 ) -> pd .DataFrame :
209- # Uprate age targets from 2020.
210-
211- frs_2023 = UKSingleYearDataset (STORAGE_FOLDER / "frs_2023.h5" )
212-
213- sim = Microsimulation (dataset = frs_2023 )
214- matrix_final , _ , _ = create_constituency_target_matrix (
215- frs_2023 , target_year , uprate = False
216- )
217- is_uprated_from_2020 = [
218- col .startswith ("age/" ) for col in matrix_final .columns
219- ]
220- uprating_from_2020 = np .zeros_like (matrix_final .columns , dtype = float )
221- population = (
222- sim .tax_benefit_system .parameters .gov .economic_assumptions .indices .ons .population
223- )
224- uprating_from_2020 [is_uprated_from_2020 ] = population (
225- target_year
226- ) / population (2020 )
227-
228- uprating = uprating_from_2020
229- y = y * (1 + uprating )
230-
231- return y
0 commit comments