close all
clear
clc
%% 

dynare rbc_comp_e_notaxVF_NEW
res1=oo_;
save res1


dynare rbc_comp_e_withtaxVF_NEW
res2=oo_;
save res2

load res1
load res2


%% res1 - results rbc model Laissez-Faire Tax Rule (no_tax)
%% res2 - results rbc model Pigouvian Tax Rule (with_tax)
%% e - TFP Shock
%% f - Price Schock

C_e=[res1.irfs.C_e; res2.irfs.C_e];
Y_e=[res1.irfs.Y_e; res2.irfs.Y_e];
K_e=[res1.irfs.K_e; res2.irfs.K_e];
N_e=[res1.irfs.N_e; res2.irfs.N_e];
R_e=[res1.irfs.R_e; res2.irfs.R_e];
X_e=[res1.irfs.X_e; res2.irfs.X_e];
P_e=[res1.irfs.X_e; res2.irfs.X_e];
Lambda_e=[res1.irfs.Lambda_e; res2.irfs.Lambda_e];
Tau_e=[res1.irfs.Lambda_e; res2.irfs.Lambda_e];
C_f=[res1.irfs.C_f; res2.irfs.C_f];
Y_f=[res1.irfs.Y_f; res2.irfs.Y_f];
K_f=[res1.irfs.K_f; res2.irfs.K_f];
N_f=[res1.irfs.N_f; res2.irfs.N_f];
R_f=[res1.irfs.R_f; res2.irfs.R_f];
X_f=[res1.irfs.X_f; res2.irfs.X_f];
P_f=[res1.irfs.X_f; res2.irfs.X_f];
Lambda_f=[res1.irfs.Lambda_f; res2.irfs.Lambda_f];
Tau_f=[res1.irfs.Lambda_f; res2.irfs.Lambda_f];

figure;
subplot(3,3,1)
plot(C_e(1,:),'Color','k'), hold on, plot(C_e(2,:),'Color','k','LineStyle','--');
title('C - TFP Shock'), legend('Laissez-Fare tax Rule','Pigouvian tax rule ');
subplot(3,3,2)
plot(Y_e(1,:),'Color','k'), hold on, plot(Y_e(2,:),'Color','k','LineStyle','--');
title('Y - TFP Shock');
subplot(3,3,3)
plot(K_e(1,:),'Color','k'), hold on, plot(K_e(2,:),'Color','k','LineStyle','--');
title('K - TFP Shock');
subplot(3,3,4)
plot(N_e(1,:),'Color','k'), hold on, plot(N_e(2,:),'Color','k','LineStyle','--');
title('N - TFP Shock');
subplot(3,3,5)
plot(R_e(1,:),'Color','k'), hold on, plot(R_e(2,:),'Color','k','LineStyle','--');
title('R - TFP Shock');
subplot(3,3,6)
plot(X_e(1,:),'Color','k'), hold on, plot(X_e(2,:),'Color','k','LineStyle','--');
title('X - TFP Shock');
subplot(3,3,7)
plot(P_e(1,:),'Color','k'), hold on, plot(P_e(2,:),'Color','k','LineStyle','--');
title('Price - TFP Shock');
subplot(3,3,8)
plot(Lambda_e(1,:),'Color','k'), hold on, plot(Lambda_e(2,:),'Color','k','LineStyle','--');
title('Lambda - TFP Shock');

figure;
subplot(3,3,1)
plot(C_f(1,:),'Color','k'), hold on, plot(C_f(2,:),'Color','k','LineStyle','--');
title('C - Price Shock'), legend('Laissez-Faire tax rule','Pigouvian tax rule');
subplot(3,3,2)
plot(Y_f(1,:),'Color','k'), hold on, plot(Y_f(2,:),'Color','k','LineStyle','--');
title('Y - Price Shock');
subplot(3,3,3)
plot(K_f(1,:),'Color','k'), hold on, plot(K_f(2,:),'Color','k','LineStyle','--');
title('K - Price Shock');
subplot(3,3,4)
plot(N_f(1,:),'Color','k'), hold on, plot(N_f(2,:),'Color','k','LineStyle','--');
title('N - Price Shock');
subplot(3,3,5)
plot(R_f(1,:),'Color','k'), hold on, plot(R_f(2,:),'Color','k','LineStyle','--');
title('R - Price Shock');
subplot(3,3,6)
plot(X_f(1,:),'Color','k'), hold on, plot(X_f(2,:),'Color','k','LineStyle','--');
title('X - Price Shock');
subplot(3,3,7)
plot(P_f(1,:),'Color','k'), hold on, plot(P_f(2,:),'Color','k','LineStyle','--');
title('Price - Price Shock');
subplot(3,3,8)
plot(Lambda_e(1,:),'Color','k'), hold on, plot(Lambda_e(2,:),'Color','k','LineStyle','--');
title('Lambda - Price Shock');
subplot(3,3,9)
plot(Tau_f(1,:),'Color','k'), hold on, plot(Tau_f(2,:),'Color','k','LineStyle','--');
title('Tau - Price Shock');

%% Robustness Check - A

parr_A = [1.3;1.5;2.0;2.5;3.0];

for i=1:length(parr_A)
    par_A = parr_A(i);
    save parameterfile par_A
    dynare rbc_comp_e_withtaxVF_NEW_Arob
    IRF_{i} = oo_.irfs;
end

%% TFP

% Add zero

var_list={'C_e','Y_e','K_e','N_e','R_e','X_e','P_e','Lambda_e','Tau_e'};

for i = 1:numel(var_list)
    aux = var_list{i};
    for ii = 1:5                 %must be changed with the number of parameter values
        IRF_{1,ii}.(aux) = [0,IRF_{1,ii}.(aux)];
    end
end

save('IRF_.mat','IRF_')

% Loop for subplots

var_list={'C_e','Y_e','K_e','N_e','R_e','X_e','P_e','Lambda_e','Tau_e'};
Title_list={'C - TFP Shock','Y - TFP Shock','K - TFP Shock','N - TFP Shock','R - TFP Shock','X - TFP Shock','P - TFP Shock','Lambda - TFP Shock','Tau - TFP Shock'};

    
TMax=41;                   % Maximum period on the irf charts (number of irf + 1)
t=1:TMax;                   % Auxiliar vector to X axis 
Numb_sim = 5; %just input how many simulations we did on dynare

figure(1);
set(1,'Color','w')

for v = 1:numel(var_list)
    subplot(3,3,v)
    variable = var_list{v};
    plot(t,IRF_{1,1}.(variable),'LineWidth',1.0);
    title(Title_list{v})
    hold on
        for i=2:Numb_sim
            plot(t,IRF_{1,i}.(variable),'LineWidth',1.0);
        end 
    hold off
    set(gca,'fontsize',10)
    xlim([-inf inf])
    ylim([-inf inf])
    line([1 40], [0 0],'Color','k','LineStyle','-') % change for dimension of xlim
    xlabel('Periods','FontSize',10)
end 

x0=10;
y0=10;
width=1300;
height=600;
set(1,'position',[x0,y0,width,height]);
legend({'A = 1.3','A = 1.5','A = 2.0','A = 2.5','A = 3.0',},'FontSize',12);

%% Price
% Add zero

var_list={'C_f','Y_f','K_f','N_f','R_f','X_f','P_f','Lambda_f','Tau_f'};

for i = 1:numel(var_list)
    aux = var_list{i};
    for ii = 1:5                 %must be changed with the number of parameter values
        IRF_{1,ii}.(aux) = [0,IRF_{1,ii}.(aux)];
    end
end

save('IRF_.mat','IRF_')

% Loop for subplots

var_list={'C_f','Y_f','K_f','N_f','R_f','X_f','P_f','Lambda_f','Tau_f'};
Title_list={'C - Price Shock','Y - Price Shock','K - Price Shock','N - Price Shock','R - Price Shock','X - Price Shock','P - Price Shock','Lambda - Price Shock','Tau - Price Shock'};

    
TMax=41;                   % Maximum period on the irf charts (number of irf + 1)
t=1:TMax;                   % Auxiliar vector to X axis 
Numb_sim = 5; %just input how many simulations we did on dynare

figure(1);
set(1,'Color','w')

for v = 1:numel(var_list)
    subplot(3,3,v)
    variable = var_list{v};
    plot(t,IRF_{1,1}.(variable),'LineWidth',1.0);
    title(Title_list{v})
    hold on
        for i=2:Numb_sim
            plot(t,IRF_{1,i}.(variable),'LineWidth',1.0);
        end 
    hold off
    set(gca,'fontsize',10)
    xlim([-inf inf])
    ylim([-inf inf])
    line([1 40], [0 0],'Color','k','LineStyle','-') % change for dimension of xlim
    xlabel('Periods','FontSize',10)
end 

x0=10;
y0=10;
width=1300;
height=600;
set(1,'position',[x0,y0,width,height]);
legend({'A = 1.3','A = 1.5','A = 2.0','A = 2.5','A = 3.0',},'FontSize',12);

%% Robustness Check - Gamma
clear all
clc

parr_gama = [0.04;0.05;0.06;0.07;0.08];

for i=1:length(parr_gama)
    par_gama = parr_gama(i);
    save parameterfile par_gama
    dynare rbc_comp_e_withtaxVF_NEW_gamarob
    IRF_{i} = oo_.irfs;
end

%% TFP

% Add zero

var_list={'C_e','Y_e','K_e','N_e','R_e','X_e','P_e','Lambda_e','Tau_e'};

for i = 1:numel(var_list)
    aux = var_list{i};
    for ii = 1:5                 %must be changed with the number of parameter values
        IRF_{1,ii}.(aux) = [0,IRF_{1,ii}.(aux)];
    end
end

save('IRF_.mat','IRF_')

% Loop for subplots

var_list={'C_e','Y_e','K_e','N_e','R_e','X_e','P_e','Lambda_e','Tau_e'};
Title_list={'C - TFP Shock','Y - TFP Shock','K - TFP Shock','N - TFP Shock','R - TFP Shock','X - TFP Shock','P - TFP Shock','Lambda - TFP Shock','Tau - TFP Shock'};

    
TMax=41;                   % Maximum period on the irf charts (number of irf + 1)
t=1:TMax;                   % Auxiliar vector to X axis 
Numb_sim = 5; %just input how many simulations we did on dynare

figure(1);
set(1,'Color','w')

for v = 1:numel(var_list)
    subplot(3,3,v)
    variable = var_list{v};
    plot(t,IRF_{1,1}.(variable),'LineWidth',1.0);
    title(Title_list{v})
    hold on
        for i=2:Numb_sim
            plot(t,IRF_{1,i}.(variable),'LineWidth',1.0);
        end 
    hold off
    set(gca,'fontsize',10)
    xlim([-inf inf])
    ylim([-inf inf])
    line([1 40], [0 0],'Color','k','LineStyle','-') % change for dimension of xlim
    xlabel('Periods','FontSize',10)
end 

x0=10;
y0=10;
width=1300;
height=600;
set(1,'position',[x0,y0,width,height]);
legend({'Gamma = 0.04','Gamma = 0.05','Gamma = 0.06','Gamma = 0.07','Gamma = 0.08',},'FontSize',12);

%% Price
% Add zero

var_list={'C_f','Y_f','K_f','N_f','R_f','X_f','P_f','Lambda_f','Tau_f'};

for i = 1:numel(var_list)
    aux = var_list{i};
    for ii = 1:5                 %must be changed with the number of parameter values
        IRF_{1,ii}.(aux) = [0,IRF_{1,ii}.(aux)];
    end
end

save('IRF_.mat','IRF_')

% Loop for subplots

var_list={'C_f','Y_f','K_f','N_f','R_f','X_f','P_f','Lambda_f','Tau_f'};
Title_list={'C - Price Shock','Y - Price Shock','K - Price Shock','N - Price Shock','R - Price Shock','X - Price Shock','P - Price Shock','Lambda - Price Shock','Tau - Price Shock'};

    
TMax=41;                   % Maximum period on the irf charts (number of irf + 1)
t=1:TMax;                   % Auxiliar vector to X axis 
Numb_sim = 5; %just input how many simulations we did on dynare

figure(1);
set(1,'Color','w')

for v = 1:numel(var_list)
    subplot(3,3,v)
    variable = var_list{v};
    plot(t,IRF_{1,1}.(variable),'LineWidth',1.0);
    title(Title_list{v})
    hold on
        for i=2:Numb_sim
            plot(t,IRF_{1,i}.(variable),'LineWidth',1.0);
        end 
    hold off
    set(gca,'fontsize',10)
    xlim([-inf inf])
    ylim([-inf inf])
    line([1 40], [0 0],'Color','k','LineStyle','-') % change for dimension of xlim
    xlabel('Periods','FontSize',10)
end 

x0=10;
y0=10;
width=1300;
height=600;
set(1,'position',[x0,y0,width,height]);
legend({'Gamma = 0.04','Gamma = 0.05','Gamma = 0.06','Gamma = 0.07','Gamma = 0.08',},'FontSize',12);