Commit 55b631e7 authored by Thomas Brand's avatar Thomas Brand

Add conditional forecast scenario.

parent ed78a0b8
......@@ -386,6 +386,8 @@ dataFR_forecast2 <-
dataFR_forecast %>%
mutate(period=gsub(" ", "", as.yearqtr(period)))
dataFR_forecast2[is.na(dataFR_forecast2)] <- NaN
write_csv(dataFR_forecast2,"dataFR_forecast.csv")
```
......
// Load data in levels.
dataFRlevels = dseries('../../data/dataFR_forecast.csv');
// Remove the first observations (same starting date as in CMR) and rename the dseries object.
dataFR=dataFRlevels(1995Q1:dataFRlevels.dates(end));
// Compute quaterly growth factors.
dataFR{'[^(?!.*creditspread|re|debt|hours_pc).*$]'} = 1+dataFR{'[^(?!.*creditspread|re|debt|hours_pc).*$]'}.qgrowth() ;
// Compute quarterly rates.
dataFR{'@creditspread,re@'} = (1+dataFR{'@creditspread,re@'})^0.25 ;
// Rename the observed variables
dataFR = dataFR.rename('gdp_rpc', 'GDP_OBS');
dataFR = dataFR.rename('conso_rpc', 'CONSUMPTION_OBS');
dataFR = dataFR.rename('inves_rpc', 'INVESTMENT_OBS');
dataFR = dataFR.rename('defgdp', 'INFLATION_OBS');
dataFR = dataFR.rename('pinves_defl', 'PINVEST_OBS');
dataFR = dataFR.rename('hours_pc', 'HOURS_OBS');
dataFR = dataFR.rename('wage_rph', 'WAGE_OBS');
dataFR = dataFR.rename('re', 'RE_OBS');
dataFR = dataFR.rename('pubcons_rpc', 'GC_OBS');
dataFR = dataFR.rename('pubinves_rpc', 'GI_OBS');
dataFR = dataFR.rename('tfs_rpc', 'T_OBS');
dataFR = dataFR.rename('othgov_rpc', 'OTHGOV_OBS');
dataFR = dataFR.rename('debt', 'B_OBS');
dataFR = dataFR.rename('creditspread', 'CREDITSPREAD_OBS');
dataFR = dataFR.rename('loans_nfc_rpc', 'CREDIT_OBS');
dataFR = dataFR.rename('networth_rpc', 'NETWORTH_OBS');
dataFR = dataFR.rename('world_demand', 'YWORLD_OBS');
dataFR = dataFR.rename('oil_prices', 'POIL_OBS');
// Set subsample used to demean the dataFR
range = 1995Q2:2016Q4;
// Save the mean growth rate of raw dataFR
data_mean = struct;
data_mean.name = dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'}.name;
data_mean.name = [data_mean.name; 'B_OBS'];
data_mean.name = [data_mean.name; 'HOURS_OBS'];
data_mean.name = [data_mean.name; 'TAUC_OBS'];
data_mean.name = [data_mean.name; 'TAUN_OBS'];
data_mean.name = [data_mean.name; 'TAUWF_OBS'];
data_mean.name = [data_mean.name; 'TAUWH_OBS'];
data_mean.values = dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'}(range).mean(true)';
data_mean.values = [data_mean.values; dataFR{'B_OBS'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFR{'HOURS_OBS'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauc'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'taun'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauwf'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauwh'}(range).mean(false)];
save('mean.mat', 'data_mean');
// Center the dataFR (with geometric mean for all variables except B_OBS and HOURS_OBS)
dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'} = dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'}/dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'}(range).mean(true);
// Compute factor deviation to the arithmetic mean
dataFR{'B_OBS'} = dataFR{'B_OBS'}-2.20;
dataFR{'HOURS_OBS'} = dataFR{'HOURS_OBS'}/dataFR{'HOURS_OBS'}(range).mean(false);
dataFR{'TAUC_OBS'} = dataFRlevels{'tauc'};
dataFR{'TAUN_OBS'} = dataFRlevels{'taun'};
dataFR{'TAUWF_OBS'} = dataFRlevels{'tauwf'};
dataFR{'TAUWH_OBS'} = dataFRlevels{'tauwh'};
// Declare dataFR dseries as the sample for estimation
data(series=dataFR, first_obs=1995Q2, last_obs=2018Q1);
@#includepath "../common"
@#include "parameters.inc"
@#include "endogenous-variables.inc"
@#include "exogenous-variables.inc"
@#include "calibration.inc"
@#include "values-for-estimated-parameters.inc"
model;
@#include "model.inc"
end;
install_steadystate_file('../common/');
steady;
@#include "calibrated-shocks.inc"
@#include "load-data-forecast.inc"
varobs
@#include "varobs.inc"
;
estimated_params;
@#include "estimated-parameters.inc"
end;
estimated_params_init;
@#include "initial-values.inc"
end;
estimation(presample=12, lyapunov=doubling, mode_compute=0, mh_replic=0, kalman_algo=2, consider_only_observed,mode_file=mars_mode,plot_priors = 0,nograph);
rawdataset = struct(dataset_);
rawdatatime = struct(rawdataset.dates);
save rawdataset.mat rawdataset;
save rawdatatime.mat rawdatatime;
dataForecast = dataFR(2018Q2:2022Q4);
//constrained_vars = {'CONSUMPTION_OBS'; 'B_OBS'; 'INFLATION_OBS'; 'GDP_OBS'; 'INVESTMENT_OBS'; 'POIL_OBS'; ...
// 'OTHGOV_OBS'; 'PINVEST_OBS'; 'GC_OBS'; 'GI_OBS'; 'RE_OBS'; 'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'T_OBS'; 'WAGE_OBS'; 'YWORLD_OBS'};
constrained_vars = {'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'YWORLD_OBS'; 'POIL_OBS'; 'RE_OBS'};
[~, constrained_vars_id] = ismember(constrained_vars, M_.endo_names);
dataForecast = dataForecast{constrained_vars{:}};
verbatim;
conditional_forecast.replic = 20000;
conditional_forecast.parameter_set = 'posterior_mode';
conditional_forecast.conf_sig = .9;
conditional_forecast.controlled_varexo = {'TAUC_EXO'; 'TAUN_EXO'; 'TAUWF_EXO'; 'TAUWH_EXO'; 'YW_EXO'; 'POIL_EXO'; 'R_EXO'};
options_.conditional_forecast = conditional_forecast;
end;
imcforecast(dataForecast.data', constrained_vars_id, conditional_forecast);
plot_icforecast(constrained_vars, 40, options_);
plot_icforecast({'GDP_OBS'}, 40, options_);
hold on
plot(dataFR(2018Q1:2022Q4).GDP_OBS.data,'-r','linewidth',2)
hold off
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment