% Note: The chain provided with the code in mhall_RBC.mat has 25000 draws for file size considerations. 
% To produce the full posterior distribution the chain length should be set to S_.Options.EST.N = 750000 
% in line 20 of run_mcmc.m

addpath functions

%% Load estimation results
load mhall_RBC.mat

%% Setup
aus_data;

% Variable and dimensions

v_ = var_dim ;

n     = v_.dim.n    ;
n_    = v_.dim.n_    ;
ns    = v_.dim.ns    ;

%% Run fiscal cases at mode

x_ = params_xx_mode;

Tz = params_T_out_mode(1);
Tsig = params_T_out_mode(2);
T_ = [Tz, Tsig];

S_.param = param_func(x_);

S_.options.fiscal = 'gss_b';
y_non_gss_b_mode = fiscal_reaction(x_,T_,S_);

x_(S_.param.order.gam_gb) = 2*x_(S_.param.order.gam_gb);
x_(S_.param.order.gam_cb) = 2*x_(S_.param.order.gam_cb);
x_(S_.param.order.gam_wb) = 2*x_(S_.param.order.gam_wb);
x_(S_.param.order.gam_Kb) = 2*x_(S_.param.order.gam_Kb);
x_(S_.param.order.gam_taub) = 2*x_(S_.param.order.gam_taub);

x_(S_.param.order.rho_g) = 0.5*x_(S_.param.order.rho_g);
x_(S_.param.order.rho_c) = 0.5*x_(S_.param.order.rho_c);
x_(S_.param.order.rho_w) = 0.5*x_(S_.param.order.rho_w);
x_(S_.param.order.rho_K) = 0.5*x_(S_.param.order.rho_K);
x_(S_.param.order.rho_tau) = 0.5*x_(S_.param.order.rho_tau);

x_(S_.param.order.rho2_g) = 0.5*x_(S_.param.order.rho2_g);
x_(S_.param.order.rho2_c) = 0.5*x_(S_.param.order.rho2_c);
x_(S_.param.order.rho2_w) = 0.5*x_(S_.param.order.rho2_w);
x_(S_.param.order.rho2_K) = 0.5*x_(S_.param.order.rho2_K);
x_(S_.param.order.rho2_tau) = 0.5*x_(S_.param.order.rho2_tau);

S_.param = param_func(x_);

S_.options.fiscal = 'gss_b';
y_non_gss_b_mode_faster = fiscal_reaction(x_,T_,S_);

%% Figure

t_ = 1983:0.25:2018+200/4;

from = 2000;
up_to = 2040;

T = 341;

figure('Name', "g_ss Speed Case", 'Position', [1 1 600 500])
set(0,'defaulttextinterpreter','latex')
subplot(2,2,1)
plot(t_,100*exp(y_non_gss_b_mode(v_.gy_obs,:)), 'Color', 'k', 'LineWidth',2)
hold on
plot(t_,100*exp(y_non_gss_b_mode_faster(v_.gy_obs,:)),'--','Color', [0.6 0.6 0.6], 'LineWidth',2)
title('Government Spending to Output Ratio')
xlim([from up_to])
%ylim([22.5 24])
set(gca, 'Box', 'off', 'TickDir', 'in', 'TickLabelInterpreter','latex')
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
ylabel('\%', 'FontWeight', 'Normal')

subplot(2,2,2)
plot(t_,100*(y_non_gss_b_mode(v_.by_obs,:))./4,   'Color', 'k', 'LineWidth',2)
hold on
plot(t_,100*(y_non_gss_b_mode_faster(v_.by_obs,:))./4, '--','Color', [0.6 0.6 0.6], 'LineWidth',2)
title('Public Debt to Output Ratio')
xlim([from up_to])
%ylim([6 65])
set(gca, 'Box', 'off', 'TickDir', 'in', 'TickLabelInterpreter','latex')
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
ylabel('\%', 'FontWeight', 'Normal')

subplot(2,2,3)
plot(t_,100*exp(y_non_gss_b_mode(v_.tax,:))./exp(y_non_gss_b_mode(v_.y,:)),   'Color', 'k', 'LineWidth',2)
hold on
plot(t_,100*exp(y_non_gss_b_mode_faster(v_.tax,:))./exp(y_non_gss_b_mode_faster(v_.y,:)), '--','Color', [0.6 0.6 0.6], 'LineWidth',2)
title('Tax Revenue to Output Ratio')
xlim([from up_to])
%ylim([19 24.5])
set(gca, 'Box', 'off', 'TickDir', 'in', 'TickLabelInterpreter','latex')
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
ylabel('\%', 'FontWeight', 'Normal')

subplot(2,2,4)
debt = plot(t_,100*(y_non_gss_b_mode(v_.s,:))./exp(y_non_gss_b_mode(v_.y,:)),   'Color', 'k', 'LineWidth',2);
hold on
debt_faster = plot(t_,100*(y_non_gss_b_mode_faster(v_.s,:))./exp(y_non_gss_b_mode_faster(v_.y,:)), '--','Color', [0.6 0.6 0.6], 'LineWidth',2);
title('Primary Surplus to Output Ratio')
xlim([from up_to])
%ylim([-6 2])
set(gca, 'Box', 'off', 'TickDir', 'in', 'TickLabelInterpreter','latex')
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
ylabel('\%', 'FontWeight', 'Normal')

lgnd = legend([debt_faster,debt], {'More Responsive Fiscal Rules', 'Estimated Fiscal Rules'});
set(lgnd,'Box','off', 'Interpreter','latex', 'NumColumns',2)
lgnd.Position(1) = 0.1;
lgnd.Position(2) = 0.01;
lgnd.Position(3) = 0.8;

set(gcf,'Color','w')
set(findall(gcf,'-property','FontSize'),'FontSize',12);
print -depsc '-r600' Figure_10.eps