%% Preparations

lagrule = 1;%1;
pl_periods =300;

%First Scenario (Country-Variable-Scenario) 
G_Y_2   = 100*oo_.endo_simul((strmatch('dgdp_a_t',M_.endo_names,'exact')),lagrule:pl_periods)';
G_C_2   = 100*oo_.endo_simul((strmatch('c_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_Pi_2  = 100*oo_.endo_simul((strmatch('pi_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_B_2   = 100*oo_.endo_simul((strmatch('BG_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_R_2   = 100*oo_.endo_simul((strmatch('i_EMU_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_In_2  = 100*oo_.endo_simul((strmatch('in_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_U_2   = 100*oo_.endo_simul((strmatch('ur_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_W_2   = 100*oo_.endo_simul((strmatch('wr_a_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
G_RER_2 = 100*oo_.endo_simul((strmatch('rer_ba_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_Y_2  = 100*oo_.endo_simul((strmatch('dgdp_b_t',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_C_2  = 100*oo_.endo_simul((strmatch('c_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_Pi_2 = 100*oo_.endo_simul((strmatch('pi_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_B_2  = 100*oo_.endo_simul((strmatch('BG_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_In_2 = 100*oo_.endo_simul((strmatch('in_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_U_2  = 100*oo_.endo_simul((strmatch('ur_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';
Eu_W_2  = 100*oo_.endo_simul((strmatch('wr_b_obs',M_.endo_names,'exact')),lagrule:pl_periods)';

% Fiscal variables
G_tauw_2    = (oo_.endo_simul((strmatch('tauw_a_t',M_.endo_names,'exact')),lagrule:20)'-tauw_a)*100;
G_tausc_2   = (oo_.endo_simul((strmatch('tausc_a_t',M_.endo_names,'exact')),lagrule:20)'-tausc_a)*100;
G_tauk_2    = (oo_.endo_simul((strmatch('tauk_a_t',M_.endo_names,'exact')),lagrule:20)'-tauk_a)*100;
G_tauc_2    = (oo_.endo_simul((strmatch('tauc_a_t',M_.endo_names,'exact')),lagrule:20)'-tauc_a)*100;
G_T_2       = (oo_.endo_simul((strmatch('T_a_t',M_.endo_names,'exact')),lagrule:20)'-T_a_ts)/T_a_ts*100;
Eu_tauw_2   = (oo_.endo_simul((strmatch('tauw_b_t',M_.endo_names,'exact')),lagrule:20)'-tauw_b)*100;
Eu_tausc_2  = (oo_.endo_simul((strmatch('tausc_b_t',M_.endo_names,'exact')),lagrule:20)'-tausc_b)*100;
Eu_tauk_2   = (oo_.endo_simul((strmatch('tauk_b_t',M_.endo_names,'exact')),lagrule:20)'-tauk_b)*100;
Eu_tauc_2   = (oo_.endo_simul((strmatch('tauc_b_t',M_.endo_names,'exact')),lagrule:20)'-tauc_b)*100;
Eu_T_2      = (oo_.endo_simul((strmatch('T_b_t',M_.endo_names,'exact')),lagrule:20)'-T_b_ts)/T_b_ts*100;

G_cG_2    = (oo_.endo_simul((strmatch('cG_a_t',M_.endo_names,'exact')),lagrule:20)'-cG_a_ts)/cG_a_ts*100;
G_inG_2   = (oo_.endo_simul((strmatch('inG_a_t',M_.endo_names,'exact')),lagrule:20)'-inG_a_ts)/inG_a_ts*100;
G_N_2     = (oo_.endo_simul((strmatch('nG_a_t',M_.endo_names,'exact')),lagrule:20)'-nG_a_ts)*100;
G_TR_r_2  = (oo_.endo_simul((strmatch('TR_r_a_t',M_.endo_names,'exact')),lagrule:20)'-TR_r_a_ts)/TR_r_a_ts*100;
G_TR_o_2  = (oo_.endo_simul((strmatch('TR_o_a_t',M_.endo_names,'exact')),lagrule:20)'-TR_o_a_ts)/TR_o_a_ts*100;
G_TR_2    = (oo_.endo_simul((strmatch('TR_a_t',M_.endo_names,'exact')),lagrule:20)'-TR_a_ts)/TR_a_ts*100;
Eu_cG_2   = (oo_.endo_simul((strmatch('cG_b_t',M_.endo_names,'exact')),lagrule:20)'-cG_b_ts)/cG_b_ts*100;
Eu_inG_2  = (oo_.endo_simul((strmatch('inG_b_t',M_.endo_names,'exact')),lagrule:20)'-inG_b_ts)/inG_b_ts*100;
Eu_N_2    = (oo_.endo_simul((strmatch('nG_b_t',M_.endo_names,'exact')),lagrule:20)'-nG_b_ts)*100;
Eu_TR_r_2 = (oo_.endo_simul((strmatch('TR_r_b_t',M_.endo_names,'exact')),lagrule:20)'-TR_r_b_ts)/TR_r_b_ts*100;
Eu_TR_o_2 = (oo_.endo_simul((strmatch('TR_o_b_t',M_.endo_names,'exact')),lagrule:20)'-TR_o_b_ts)/TR_o_b_ts*100;
Eu_TR_2   = (oo_.endo_simul((strmatch('TR_b_t',M_.endo_names,'exact')),lagrule:20)'-TR_b_ts)/TR_b_ts*100;

load TransEq;
load TransTH;

%% Plot macro variables

% Figure with Impulse Responses after a technology shock
% T=size(G_Y_1,2);
t=lagrule:pl_periods;
Zeroline=zeros(size(t,2),1);
f = figure;
set(f,'InvertHardcopy','off','Color',[1 1 1],'Position',[1 1 800 1000]);
subplot (4,4,1);
   plot(t,G_Y_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_Y_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_Y_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Output','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
   axis tight
 subplot (4,4,2); 
   plot(t,G_C_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_C_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_C_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Consumption','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,3);
   plot(t,G_In_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_In_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_In_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Investment','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,4);
   plot(t,G_Pi_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_Pi_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_Pi_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Inflation','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,5);
   plot(t,G_U_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_U_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_U_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Unemployment','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,6);
   plot(t,G_W_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_W_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_W_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Real Wage','FontSize',11,'FontWeight','Bold');
   xlabel ('time');  
    axis tight
subplot (4,4,7); 
   plot(t,G_B_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_B_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_B_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('GE Debt','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,8);
   plot(t,Eu_B_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_B_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_B_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Debt','FontSize',11,'FontWeight','Bold');
   xlabel ('time'); 
    axis tight
subplot (4,4,9); 
   plot(t,Eu_Y_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_Y_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_Y_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Output','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,10); 
   plot(t,Eu_C_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_C_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_C_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Consumption','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,11); 
   plot(t,Eu_In_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_In_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_In_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Investment','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,12); 
   plot(t,Eu_Pi_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_Pi_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_Pi_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Inflation','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,13); 
   plot(t,Eu_U_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_U_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_U_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Unemployment','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,14); 
   plot(t,Eu_W_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_W_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Eu_W_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE Real Wage','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,15);
   plot(t,G_RER_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_RER_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_RER_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('RoE ToT to Germany','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
subplot (4,4,16);
   plot(t,G_R_1,'r-*','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_R_2,'g-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,G_R_3,'b-+','LineWidth',1.5,'Markersize',2);
   hold on
   plot(t,Zeroline,'k','LineWidth',1);
   title('Interest Rate','FontSize',11,'FontWeight','Bold');
   xlabel ('time');
    axis tight
h_legend=legend('SQ to RE','SQ to CA','SQ to TH','Orientation','horizontal','Location','SouthOutside');
%    legend('boxoff');
    pos = get(h_legend,'Position');
    pos(1) = 0.253;
    
    pos(2) = 0.038;
    pos(3) = 0.53;
    pos(4) = 0.033;
    set(h_legend,'Position',pos);
    set(h_legend,'FontSize',13,'FontWeight','Bold');
%saveas(gcf,'R:\Zentrale\ZB-Vo\Daten\Vo2_Gesamt\Hollmayr_Staehler_gemeinsame_Projekte\Fiscal_Union\New_Code\Tech_home.eps','epsc') 

%% Plot fiscal variables


% % Figure with Impulse Responses after a technology shock
% % T=size(G_Y_1,2);
% t=lagrule:pl_periods;
% Zeroline=zeros(size(t,2),1);
% f = figure;
% set(f,'InvertHardcopy','off','Color',[1 1 1],'Position',[1 1 800 1000]);
% subplot (4,4,1);
%    plot(t,G_tauw_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_tauw_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE labor tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
%  subplot (4,4,2); 
%    plot(t,G_tausc_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_tausc_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE social security','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,3);
%    plot(t,G_tauc_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_tauc_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE consumption tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');   
% subplot (4,4,4);
%    plot(t,G_tauk_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_tauk_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE capital tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,5);
%    plot(t,G_cG_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_cG_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE public purchases','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,6);
%    plot(t,G_inG_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_inG_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE public investment','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');   
% subplot (4,4,7); 
%    plot(t,G_N_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_N_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE public employment','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,8);
%    plot(t,G_TR_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,G_TR_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('GE public transfers','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');   
% subplot (4,4,9); 
%    plot(t,Eu_tauw_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_tauw_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE labor tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,10); 
%    plot(t,Eu_tausc_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_tausc_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE social security','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,11); 
%    plot(t,Eu_tauc_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_tauc_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE consumption tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,12); 
%    plot(t,Eu_tauk_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_tauk_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE capital tax rate','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,13); 
%    plot(t,Eu_cG_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_cG_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE public purchases','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,14); 
%    plot(t,Eu_inG_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_inG_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE public investment','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,15);
%    plot(t,Eu_N_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_N_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE public employment','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% subplot (4,4,16);
%    plot(t,Eu_TR_3,'b-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Eu_TR_2,'g-+','LineWidth',1.5,'Markersize',2);
%    hold on
%    plot(t,Zeroline,'k','LineWidth',1);
%    title('RoE public transfers','FontSize',11,'FontWeight','Bold');
%    xlabel ('time');
% h_legend=legend('SQ to TH','SQ to CA','Orientation','horizontal','Location','SouthOutside');
% %    legend('boxoff');
%     pos = get(h_legend,'Position');
%     pos(1) = 0.253;
%     pos(2) = 0.038;
%     pos(3) = 0.53;
%     pos(4) = 0.033;
%     set(h_legend,'Position',pos);
%     set(h_legend,'FontSize',13,'FontWeight','Bold');
% %saveas(gcf,'R:\Zentrale\ZB-Vo\Daten\Vo2_Gesamt\Hollmayr_Staehler_gemeinsame_Projekte\Fiscal_Union\New_Code\Tech_home.eps','epsc') 