In this tutorial we illustrate how to calibrate the model to the Italian data for a specific quarter
import BeforeIT as Bit
using Dates, FileIO
We start from loading the calibration oject for italy, which contains 4 datasets: calibration_data, figaro, data, and ea These are saved within BeforeIT for the Italian case, and would need to be appropriately generated for other countries
cal = Bit.ITALY_CALIBRATION
fieldnames(typeof(cal))
(:calibration, :figaro, :data, :ea, :max_calibration_date, :estimation_date)
These are essentually 4 dictionaries with well defined keys, such as
println(keys(cal.calibration))
println(keys(cal.figaro))
println(keys(cal.data))
println(keys(cal.ea))
["social_benefits", "government_debt_quarterly", "capital_taxes", "interest_government_debt", "dwellings_eu7", "pension_benefits", "nace64_capital_consumption_eu20", "fixed_assets_eu7", "firm_interest", "dwellings", "nominal_nace64_output_eu20", "social_contributions", "nominal_nace64_output", "income_tax", "wages", "employees", "fixed_assets", "firms", "mixed_income", "nominal_nace64_output_eu7", "firm_debt_quarterly", "bank_equity_quarterly", "corporate_tax", "property_income", "household_cash_quarterly", "gross_capitalformation_dwellings", "gross_fixed_capitalformation", "unemployment_benefits", "population", "years_num", "government_deficit", "capital_consumption", "firm_cash_quarterly", "quarters_num", "nace64_capital_consumption"]
["intermediate_consumption", "household_consumption", "capitalformation", "operating_surplus", "compensation_employees", "imports", "government_consumption", "inventory_changes", "exports", "taxes_products_government", "fixed_capitalformation", "taxes_products", "years_num", "quarters_num", "taxes_production", "taxes_products_capitalformation", "taxes_products_household"]
["unemployment_rate", "nominal_nace10_gva_quarterly", "operating_surplus", "nominal_household_consumption_growth_quarterly", "nominal_exports", "real_capitalformation_growth", "household_consumption_deflator", "gdp_deflator_growth", "gva_deflator_quarterly", "capitalformation_deflator_growth", "nominal_final_consumption_growth_quarterly", "real_fixed_capitalformation_growth", "real_exports_growth", "nominal_imports", "nominal_nace10_gva_growth_quarterly", "gdp_deflator_quarterly", "capitalformation_deflator_quarterly", "real_government_consumption_growth_quarterly", "real_final_consumption", "real_capitalformation_quarterly", "nominal_capitalformation_growth", "fixed_capitalformation_deflator", "real_imports_growth", "nace10_gva_deflator", "real_household_consumption_growth", "fixed_capitalformation_deflator_growth", "real_gva", "nominal_final_consumption", "nominal_exports_quarterly", "real_household_consumption", "real_imports_quarterly", "real_nace10_gva_growth", "real_gva_growth_quarterly", "nominal_household_consumption_growth", "nominal_imports_quarterly", "employed_quarterly", "nace10_gva_deflator_growth", "nominal_capitalformation_growth_quarterly", "nace10_gva_deflator_quarterly", "real_government_consumption_growth", "nominal_government_consumption_quarterly", "final_consumption_deflator", "real_capitalformation_growth_quarterly", "compensation_employees", "gva_deflator_growth", "imports_deflator_quarterly", "real_household_consumption_growth_quarterly", "gdp_deflator_growth_quarterly", "nominal_gdp_quarterly", "exports_deflator_growth_quarterly", "government_consumption_deflator_growth_quarterly", "exports_deflator_quarterly", "real_exports_growth_quarterly", "wages", "nominal_nace10_gva", "gdp_deflator", "household_consumption_deflator_growth", "nominal_nace10_gva_growth", "nominal_gdp_growth", "nominal_household_consumption", "fixed_capitalformation_deflator_quarterly", "nominal_exports_growth_quarterly", "wages_quarterly", "nominal_exports_growth", "euribor", "years_num", "real_final_consumption_quarterly", "nominal_gva_quarterly", "quarters_num", "real_capitalformation", "nominal_government_consumption_growth", "real_final_consumption_growth", "nominal_imports_growth", "nominal_government_consumption", "imports_deflator_growth", "nominal_fixed_capitalformation_quarterly", "real_nace10_gva_quarterly", "nominal_final_consumption_quarterly", "compensation_employees_quarterly", "nominal_fixed_capitalformation_growth_quarterly", "real_gdp_growth", "real_government_consumption", "exports_deflator_growth", "nominal_gdp", "imports_deflator_growth_quarterly", "real_nace10_gva", "real_exports_quarterly", "government_consumption_deflator_growth", "real_fixed_capitalformation_growth_quarterly", "nominal_capitalformation_quarterly", "nominal_gdp_growth_quarterly", "employed", "imports_deflator", "euribor_yearly", "fixed_capitalformation_deflator_growth_quarterly", "real_imports", "real_final_consumption_growth_quarterly", "nominal_household_consumption_quarterly", "real_fixed_capitalformation", "household_consumption_deflator_growth_quarterly", "nominal_fixed_capitalformation_growth", "gva_deflator_growth_quarterly", "final_consumption_deflator_growth_quarterly", "unemployment_rate_quarterly", "nominal_gva_growth_quarterly", "nominal_government_consumption_growth_quarterly", "final_consumption_deflator_quarterly", "real_gva_growth", "government_consumption_deflator_quarterly", "real_gdp_growth_quarterly", "exports_deflator", "real_gdp_quarterly", "final_consumption_deflator_growth", "capitalformation_deflator_growth_quarterly", "real_fixed_capitalformation_quarterly", "real_gdp", "nominal_fixed_capitalformation", "real_nace10_gva_growth_quarterly", "nace10_gva_deflator_growth_quarterly", "real_government_consumption_quarterly", "government_consumption_deflator", "nominal_gva_growth", "household_consumption_deflator_quarterly", "real_household_consumption_quarterly", "capitalformation_deflator", "nominal_capitalformation", "operating_surplus_quarterly", "nominal_imports_growth_quarterly", "gva_deflator", "nominal_final_consumption_growth", "real_gva_quarterly", "nominal_gva", "real_imports_growth_quarterly", "real_exports"]
["nominal_nace10_gva_quarterly", "operating_surplus", "nominal_household_consumption_growth_quarterly", "nominal_exports", "real_capitalformation_growth", "household_consumption_deflator", "gdp_deflator_growth", "gva_deflator_quarterly", "capitalformation_deflator_growth", "nominal_final_consumption_growth_quarterly", "real_fixed_capitalformation_growth", "real_exports_growth", "nominal_imports", "nominal_nace10_gva_growth_quarterly", "gdp_deflator_quarterly", "capitalformation_deflator_quarterly", "real_government_consumption_growth_quarterly", "real_final_consumption", "real_capitalformation_quarterly", "nominal_capitalformation_growth", "fixed_capitalformation_deflator", "real_imports_growth", "nace10_gva_deflator", "real_household_consumption_growth", "fixed_capitalformation_deflator_growth", "real_gva", "nominal_final_consumption", "nominal_exports_quarterly", "real_household_consumption", "real_imports_quarterly", "real_nace10_gva_growth", "real_gva_growth_quarterly", "nominal_household_consumption_growth", "nominal_imports_quarterly", "employed_quarterly", "nace10_gva_deflator_growth", "nominal_capitalformation_growth_quarterly", "nace10_gva_deflator_quarterly", "real_government_consumption_growth", "nominal_government_consumption_quarterly", "final_consumption_deflator", "real_capitalformation_growth_quarterly", "compensation_employees", "gva_deflator_growth", "imports_deflator_quarterly", "real_household_consumption_growth_quarterly", "gdp_deflator_growth_quarterly", "nominal_gdp_quarterly", "exports_deflator_growth_quarterly", "government_consumption_deflator_growth_quarterly", "exports_deflator_quarterly", "real_exports_growth_quarterly", "wages", "nominal_nace10_gva", "gdp_deflator", "household_consumption_deflator_growth", "nominal_nace10_gva_growth", "nominal_gdp_growth", "nominal_household_consumption", "fixed_capitalformation_deflator_quarterly", "nominal_exports_growth_quarterly", "wages_quarterly", "nominal_exports_growth", "euribor", "years_num", "real_final_consumption_quarterly", "nominal_gva_quarterly", "quarters_num", "real_capitalformation", "nominal_government_consumption_growth", "real_final_consumption_growth", "nominal_imports_growth", "nominal_government_consumption", "imports_deflator_growth", "nominal_fixed_capitalformation_quarterly", "real_nace10_gva_quarterly", "nominal_final_consumption_quarterly", "compensation_employees_quarterly", "nominal_fixed_capitalformation_growth_quarterly", "real_gdp_growth", "real_government_consumption", "exports_deflator_growth", "nominal_gdp", "imports_deflator_growth_quarterly", "real_nace10_gva", "real_exports_quarterly", "government_consumption_deflator_growth", "real_fixed_capitalformation_growth_quarterly", "nominal_capitalformation_quarterly", "nominal_gdp_growth_quarterly", "employed", "imports_deflator", "euribor_yearly", "fixed_capitalformation_deflator_growth_quarterly", "real_imports", "real_final_consumption_growth_quarterly", "nominal_household_consumption_quarterly", "real_fixed_capitalformation", "household_consumption_deflator_growth_quarterly", "nominal_fixed_capitalformation_growth", "gva_deflator_growth_quarterly", "final_consumption_deflator_growth_quarterly", "nominal_gva_growth_quarterly", "nominal_government_consumption_growth_quarterly", "final_consumption_deflator_quarterly", "real_gva_growth", "government_consumption_deflator_quarterly", "real_gdp_growth_quarterly", "exports_deflator", "real_gdp_quarterly", "final_consumption_deflator_growth", "capitalformation_deflator_growth_quarterly", "real_fixed_capitalformation_quarterly", "real_gdp", "nominal_fixed_capitalformation", "real_nace10_gva_growth_quarterly", "nace10_gva_deflator_growth_quarterly", "real_government_consumption_quarterly", "government_consumption_deflator", "nominal_gva_growth", "household_consumption_deflator_quarterly", "real_household_consumption_quarterly", "capitalformation_deflator", "nominal_capitalformation", "operating_surplus_quarterly", "nominal_imports_growth_quarterly", "gva_deflator", "nominal_final_consumption_growth", "real_gva_quarterly", "nominal_gva", "real_imports_growth_quarterly", "real_exports"]
The object also contains two time variables related to the data
println(cal.max_calibration_date)
println(cal.estimation_date)
2016-12-31T00:00:00
1996-12-31T00:00:00
We can calibrate the model on a specific quarter as follows
calibration_date = DateTime(2010, 03, 31)
parameters, initial_conditions = Bit.get_params_and_initial_conditions(cal, calibration_date; scale = 0.01)
(Dict{String, Any}("c_E_g" => [0.012978039260418142; 0.0003985263617433437; … ; 0.000643428033368059; 0.00041407867494824005;;], "T" => 12, "C" => [4.382915017591486e-5 0.00015893321363429536 0.000105021103952446; 0.00015893321363429536 0.0007927471570728018 0.0005507616320609938; 0.000105021103952446 0.0005507616320609938 0.0005321192085097472], "xi_pi" => 0.3251309110739481, "L" => 23300.0, "sigma_E" => 0.028155765964945827, "H_act" => 233910.0, "beta_I" => 0.7789361541128298, "theta" => 0.05, "tau_SIW" => 0.12024155738392799…), Dict{String, Any}("sb_inact" => 0.14744411918306372, "K_H" => 2.5717239e6, "E_CB" => 1.4744936e6, "L_G" => 1.8761466e6, "C_G" => [69620.85113236064; 69628.26021546753; … ; 79003.25341430637; 79057.21957369309;;], "w_UB" => 0.2541856600766616, "pi" => [0.01552341251616679, 0.007364847580140943, -0.0014413096223191424, 0.012659687617788129, -0.00543339680120708, 0.0031342727675487403, 0.008259917102933556, 0.0024505137911164376, 0.015517671905839303, -0.00045722860474695093 … 0.018003552480356795, -0.005662735440323672, 0.011943008727627318, 0.0007471090186489046, 0.0028493451107789447, 0.010472796408025353, 0.0006497589705015978, -0.0008405102979527736, 0.0020667266123554308, -0.0017542487268334779], "sb_other" => 0.029680028251561474, "D_RoW" => 0.0, "Y" => [700366.7682404903, 702852.9431179384, 712326.5572179743, 717255.0622122796, 730150.7303844376, 724630.8126553469, 728866.255851075, 729869.1801729307, 725864.7575767279, 730869.7451354718 … 829111.1076237835, 838773.0772424113, 830807.0937442158, 820293.7886396763, 797832.2947409481, 777930.7056982402, 774054.868184667, 778964.3016911814, 781534.6270508397, 784197.3606503082]…))
In sgeneral, we might want to repeat this operation for multiple quarters. In the following, we loop over all quarters from 2010Q1 to 2019Q4 and save the parameters and initial conditions in separate files. We can then load these files later to run the model for each quarter.
start_calibration_date = DateTime(2010, 03, 31)
end_calibration_date = DateTime(2019, 12, 31)
for calibration_date in collect(start_calibration_date:Dates.Month(3):end_calibration_date)
params, init_conds = Bit.get_params_and_initial_conditions(cal, calibration_date; scale = 0.0005)
save(
"data/" *
"italy/" *
"/parameters/" *
string(year(calibration_date)) *
"Q" *
string(Dates.quarterofyear(calibration_date)) *
".jld2",
params,
)
save(
"data/" *
"italy/" *
"/initial_conditions/" *
string(year(calibration_date)) *
"Q" *
string(Dates.quarterofyear(calibration_date)) *
".jld2",
init_conds,
)
end