Regional Population Models
Regional Population Models
These models provide advanced and detailed demographic/population forecasting tools in Python and Excel. These include regional (national, provincial, and sub-provincial) population forecasts by single-age cohort, gender, and source of growth (international net migration, domestic net migration, births, and deaths).
Find a snapshot of just a section of the python script below
##4.Forecast Function
def pop_forecast(geog,sheet,int_coef,dom_coef,start_period,end_period):
for i in range (start_period,end_period+1):
###Forecast International and Domestic Net Migration.
if geog=='AB':
sheet[str(i)]['Int_Net_Mig']=round(sumproduct(int_coef,[1,(sheet[str(i-1)][0]/Exog['CAN_Tot_Pop'][i-1]),
(Exog['AB_Tot_Emp'][i-1]-Exog['AB_Tot_Emp'][i-2]),(Exog['Imm_Pol'][i])]),0)
sheet[str(i)]['Dom_Net_Mig']=round(sumproduct(dom_coef,[1,sheet[str(i-1)]['Dom_Net_Mig'],(Exog['AB_Tot_UR'][i-1]
/Exog['CAN_Tot_UR'][i-1]),0,(Exog['AB_Tot_Emp'][i-1]-Exog['AB_Tot_Emp'][i-2])]),0)
elif geog=='CER':
sheet[str(i)]['Int_Net_Mig']=round(sumproduct(int_coef,[1,(AB[str(i)]['Int_Net_Mig']),(Exog['CER_Tot_UR'][i-1]/Exog['AB_Tot_UR'][i-1])]),0) #type: ignore
sheet[str(i)]['Dom_Net_Mig']=round(sumproduct(dom_coef,[1,((AB[str(i)]['Dom_Net_Mig'])),(Exog['CER_Tot_UR'][i-1]/Exog['AB_Tot_UR'][i-1])]),0) #type: ignore
elif geog=='CMA':
sheet[str(i)]['Int_Net_Mig']=round(sumproduct(int_coef,[1, (CER[str(i)]['Int_Net_Mig'])]),0) #type: ignore
sheet[str(i)]['Dom_Net_Mig']=round(sumproduct(dom_coef,[1, (CER[str(i)]['Dom_Net_Mig'])]),0) #type: ignore
elif geog=='COC':
sheet[str(i)]['Int_Net_Mig']=(sumproduct(int_coef,[1,(Exog['CER_Tot_UR'][i-1]/Exog['CAN_Tot_UR'][i-1]), (sheet[str(i-1)][0]/Exog['CAN_Tot_Pop'][i-1]),(Exog
['CER_Tot_Emp'][i-1]-Exog['CER_Tot_Emp'][i-2]),(Exog['COC_Avg_Hprice'][i-1]),(Exog['CMA_CPI'][i-1]),(Exog['Imm_Pol'][i-1])]))
sheet[str(i)]['Dom_Net_Mig']=0
else:
print('geography listed cannot be found!')
#Apply Alberta YTD Assumptions To First Forecast Period
if i==start_period and geog=='AB':
sheet[str(start_period)]['Int_Net_Mig']=round(((1-(len(AB_YTD)*0.25))*sheet[str(start_period)]['Int_Net_Mig'])+sum(AB_YTD.Int_Net_Mig),0)
sheet[str(start_period)]['Dom_Net_Mig']=round(((1-(len(AB_YTD)*0.25))*sheet[str(start_period)]['Dom_Net_Mig'])+sum(AB_YTD.Dom_Net_Mig),0)
sheet[str(i)]['Tot_Net_Mig']=sheet[str(i)]['Int_Net_Mig']+sheet[str(i)]['Dom_Net_Mig']
###Shift Previous Age Cohorts A Year Ahead.
sheet[str(i)][12:132]= sheet[str(i-1)][11:131]
sheet[str(i)][133:253]=sheet[str(i-1)][132:252]
###Forecast Total Births By Gender as the Age Zero Cohort.
sheet[str(i)]['m0']=round(globals()[geog + "_Birth"]['Ratio']['Male']*(sumproduct(np.array(globals()[geog + "_Fert"][i]),(sheet[str(i-1)][24:60]))),0)
sheet[str(i)]['f0']=round(globals()[geog + "_Birth"]['Ratio']['Female']*(sumproduct(np.array(globals()[geog + "_Fert"][i]),(sheet[str(i-1)][24:60]))),0)
sheet[str(i)]['Births']=sheet[str(i)]['m0']+sheet[str(i)]['f0']
Interested in the full script?
Get access to the complete python scripts, excel data, pdfs and more
Interested in the full script?
Get access to the complete python scripts, excel data, pdfs and more
Interested in the full script?
Get access to the complete python scripts, excel data, pdfs and more