%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Value to be set%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

window_size_uncertainty = 0;        % 1= window_size_uncertainty; 0= estimation uncertainty
oo=1;                               % choose variable ordering

if window_size_uncertainty==0

    if oo==0
        shock_var =4;

        if shock_var==4
            titles = 'EPU';
        else
            titles = 'EPU ';
        end

        % Choose dates to plot IRF with confidence band
        time_of_response = char('01-Sep-2006', '01-Sep-2011', '01-Sep-2016');

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %                   Do not touch after this line                         %
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        % Define results matrices

        % fixed window size
        tvp_irf_median = zeros(nvar_help, nvar_help, hor, n_roll);
        tvp_irf_lb = zeros(nvar_help, nvar_help, hor, n_roll);
        tvp_irf_ub = zeros(nvar_help, nvar_help, hor, n_roll);

        tvp_irf_median(:,:,:,:) = squeeze(irf_median_win(:,:,:,:,1));
        tvp_irf_lb(:,:,:,:) = squeeze(irf_lb_win(:,:,:,:,1));
        tvp_irf_ub(:,:,:,:) = squeeze(irf_ub_win(:,:,:,:,1));


        % generate dates for meshc
        StartDate = datetime(2005,03,01);
        EndDate = datetime(2018,01,01);
        dates = datenum(StartDate:calmonths(1):EndDate);
        [XXX,YYY] = meshgrid(dates,1:hor);
        
        
        % Set time point for Confidence interval
        [time1]=strmatch(time_of_response(1,:), datestr(dates));
        [time2]=strmatch(time_of_response(2,:), datestr(dates));
        [time3]=strmatch(time_of_response(3,:), datestr(dates));

        time=[time1 time2 time3];

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Effect of uncertainty on
        % HCPI
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(1,shock_var,:,:)));
        zlim([-0.2 0.2])
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on HICP'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.2; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
        % HCPI
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(1,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.2 0.2])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on HCPI ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'HICP_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  

        % IPI
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(2,shock_var,:,:)));
        zlim([-1.5 1])
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on Industrial Production'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -1.5; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
         % IPI
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(2,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-1.5 1])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on IPI ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'IPI_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  

        % EONIA
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(3,shock_var,:,:)));
        zlim([-0.3 0.1])
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on EONIA'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.3; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
          % EONIA
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(3,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.3 0.1])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on EONIA ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'EONIA_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  

        % EPU
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(4,shock_var,:,:)));
        zlim([-0.2 0.3])
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on EPU'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.2; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
          % EPU Uncertainty
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(4,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.2 0.3])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on EPU ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end

        folder= ['pics'];
        temp=['pics\', dataset, 'Uncertainty_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')    
  

    else % if oo=1

            shock_var =1;

        if shock_var==1
             titles = 'EPU';
        else
            titles = 'EPU';
        end

        % Choose dates to plot IRF with confidence band
        time_of_response = char('01-Sep-2006', '01-Sep-2011', '01-Sep-2016');

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %                   Do not touch after this line                         %
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        % Define results matrices

        % fixed window size
        tvp_irf_median = zeros(nvar_help, nvar_help, hor, n_roll);
        tvp_irf_lb = zeros(nvar_help, nvar_help, hor, n_roll);
        tvp_irf_ub = zeros(nvar_help, nvar_help, hor, n_roll);

        tvp_irf_median(:,:,:,:) = squeeze(irf_median_win(:,:,:,:,1));
        tvp_irf_lb(:,:,:,:) = squeeze(irf_lb_win(:,:,:,:,1));
        tvp_irf_ub(:,:,:,:) = squeeze(irf_ub_win(:,:,:,:,1));


        % generate dates for meshc
        StartDate = datetime(2005,03,01);
        EndDate = datetime(2018,01,01);
        dates = datenum(StartDate:calmonths(1):EndDate);
        [XXX,YYY] = meshgrid(dates,1:hor);
        
        % Set time point for Confidence interval
        [time1]=strmatch(time_of_response(1,:), datestr(dates));
        [time2]=strmatch(time_of_response(2,:), datestr(dates));
        [time3]=strmatch(time_of_response(3,:), datestr(dates));

        time=[time1 time2 time3];

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Effect of uncertainty on
        
        % EPU
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(1,shock_var,:,:)));
        datetick('x','yy')
        zlim([-0.2 0.3])
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on EPU'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.2; % set the contour's Z position (default: hAxes.ZLim(1)=-10)

        % EPU
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(1,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(1,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.2 0.3])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on EPU ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'EPU_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  
        
        % HICP
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(2,shock_var,:,:)));
        datetick('x','yy')
        zlim([-0.2 0.2])
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on HICP'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.2; % set the contour's Z position (default: hAxes.ZLim(1)=-10)

        % HICP
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(2,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(2,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.2 0.2])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on HICP ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'HICP_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent') 
        
        % IPI
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(3,shock_var,:,:)));
        datetick('x','yy')
        zlim([-1.5 1])
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on IPI'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -1.5; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
        % IPI
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(3,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(3,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-1.5 1])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on IPI ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end

        folder= ['pics'];
        temp=['pics\', dataset, 'IPI_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent') 
        
        % EONIA
        subplot(1,4,1)
        handles = meshc(XXX,YYY,squeeze(tvp_irf_median(4,shock_var,:,:)));
        datetick('x','yy')
        zlim([-0.3 0.1])
        xlim([datenum(StartDate) datenum(EndDate)])
        title([titles ' on EONIA'])
        hContour = handles(2); % get the handle to the contour lines
        hContour.ContourZLevel = -0.3; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
        
        % EONIA
        for i=1:3
        subplot(1,4,i+1)
            a = median(squeeze(irf_all_win(4,shock_var,:,:,time(i))),2);
            b1 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.05,2);
            b2 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.16,2);
            b3 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.84,2);
            b4 = quantile(squeeze(irf_all_win(4,shock_var,:,:,time(i))),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            ylim([-0.3 0.1])
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            title([titles ' on EONIA ' datestr(time_of_response(i,:), 'mmm yyyy')])
            hold off
        end

        folder= ['pics'];
        temp=['pics\', dataset, 'EONIA_3D_2D.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  

    end
    
else % if window_size_uncertainty==1
    
    if oo==0
        shock_var =4;
    else
        shock_var =1;        
    end
    
        if shock_var==4
             titles = 'EPU';
        else
            titles = 'EPU';
        end

        % Choose dates to plot IRF with confidence band
        time_of_response = char('01-Sep-2007', '01-Sep-2011', '01-Sep-2016');
        
        StartDate = datetime(2007,03,01);
        EndDate = datetime(2018,01,01);
        dates = datenum(StartDate:calmonths(1):EndDate);
        [XXX,YYY] = meshgrid(dates,1:hor);
        
        % Set time point for Confidence interval
        
        [time1]=strmatch(time_of_response(1,:), datestr(dates));
        [time2]=strmatch(time_of_response(2,:), datestr(dates));
        [time3]=strmatch(time_of_response(3,:), datestr(dates));

        time=[time1 time2 time3];


        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %                   Do not touch after this line                         %
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Effect of uncertainty on
        subplot(2,2,1)
        mesh(XXX,YYY,squeeze(mean(irf_median_win(1,shock_var,:,:,:),5)));
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        if oo==0
        zlim([-0.05 0.1])
        title([titles ' on HICP'])
        else
        zlim([-0.1 0.3])
        title([titles ' on EPU'])    
        end

        subplot(2,2,2)
        mesh(XXX,YYY,squeeze(mean(irf_median_win(2,shock_var,:,:,:),5)))
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        if oo==0
        zlim([-1.5 0.5])
        title([titles ' on Industrial Production'])
        else
        zlim([-0.05 0.1])
        title([titles ' on HICP'])    
        end

        subplot(2,2,3)
        mesh(XXX,YYY,squeeze(mean(irf_median_win(3,shock_var,:,:,:),5)))
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        if oo==0
        zlim([-0.2 0.05])
        title([titles ' on EONIA'])
        else 
        zlim([-1.5 0.5])
        title([titles ' on Industrial Production'])  
        end

        subplot(2,2,4)
        mesh(XXX,YYY,squeeze(mean(irf_median_win(4,shock_var,:,:,:),5)))
        datetick('x','yy')
        xlim([datenum(StartDate) datenum(EndDate)])
        if oo==0
        zlim([-0.1 0.3])
        title([titles ' on EPU'])
        else
        zlim([-0.2 0.05])
        title([titles ' on EONIA'])    
        end

%         folder= ['pics'];
%         temp=['pics\', dataset, '_3D_window_size_uncertainty.pdf'];        
        % saveas(gcf,temp);

%         export_fig(temp, '-transparent')  
    
        %%% Effect of Uncertainty for several points in time with
        %%% window_size_uncertainty

        % HCPI
        for i=1:3
        subplot(4,3,i)
            a = mean(squeeze(irf_median_win(1,shock_var,:,time(i),:)),2);
            b1 = quantile(squeeze(irf_median_win(1,shock_var,:,time(i),:)),0.05,2);
            b2 = quantile(squeeze(irf_median_win(1,shock_var,:,time(i),:)),0.16,2);
            b3 = quantile(squeeze(irf_median_win(1,shock_var,:,time(i),:)),0.84,2);
            b4 = quantile(squeeze(irf_median_win(1,shock_var,:,time(i),:)),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            if oo==0
            ylim([-0.2 0.4])
            title([titles ' on HCPI ' datestr(time_of_response(i,:), 'mmm yyyy')])
            else
            ylim([-0.1 0.5])
            title([titles ' on EPU ' datestr(time_of_response(i,:), 'mmm yyyy')])    
            end
            hold off
        end

        % IPI
        for i=1:3
        subplot(4,3,i+3)
            a = mean(squeeze(irf_median_win(2,shock_var,:,time(i),:)),2);
            b1 = quantile(squeeze(irf_median_win(2,shock_var,:,time(i),:)),0.05,2);
            b2 = quantile(squeeze(irf_median_win(2,shock_var,:,time(i),:)),0.16,2);
            b3 = quantile(squeeze(irf_median_win(2,shock_var,:,time(i),:)),0.84,2);
            b4 = quantile(squeeze(irf_median_win(2,shock_var,:,time(i),:)),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            if oo==0
            ylim([-2 1])    
            title([titles ' on IPI ' datestr(time_of_response(i,:), 'mmm yyyy')])
            else
            ylim([-0.2 0.4])
            title([titles ' on HCPI ' datestr(time_of_response(i,:), 'mmm yyyy')])    
            end
            hold off
        end

        % EONIA
        for i=1:3
        subplot(4,3,i+6)
            a = mean(squeeze(irf_median_win(3,shock_var,:,time(i),:)),2);
            b1 = quantile(squeeze(irf_median_win(3,shock_var,:,time(i),:)),0.05,2);
            b2 = quantile(squeeze(irf_median_win(3,shock_var,:,time(i),:)),0.16,2);
            b3 = quantile(squeeze(irf_median_win(3,shock_var,:,time(i),:)),0.84,2);
            b4 = quantile(squeeze(irf_median_win(3,shock_var,:,time(i),:)),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            if oo==0
            ylim([-0.3 0.1])
            title([titles ' on EONIA ' datestr(time_of_response(i,:), 'mmm yyyy')])
            else
            ylim([-2 1])    
            title([titles ' on IPI ' datestr(time_of_response(i,:), 'mmm yyyy')])    
            end
            hold off
        end

        % ROE Uncertainty
        for i=1:3
        subplot(4,3,i+9)
            a = mean(squeeze(irf_median_win(4,shock_var,:,time(i),:)),2);
            b1 = quantile(squeeze(irf_median_win(4,shock_var,:,time(i),:)),0.05,2);
            b2 = quantile(squeeze(irf_median_win(4,shock_var,:,time(i),:)),0.16,2);
            b3 = quantile(squeeze(irf_median_win(4,shock_var,:,time(i),:)),0.84,2);
            b4 = quantile(squeeze(irf_median_win(4,shock_var,:,time(i),:)),0.95,2);
            %figure
            plot(1:hor,a,'Color', 'black')
            
            xlim([1,hor])
            hold on 
            plot(1:hor,b1,'Color','none')
            plot(1:hor,b2,'Color','none')
            plot(1:hor,b3,'Color','none')
            plot(1:hor,b4,'Color','none')
            plot(1:hor, zeros(1,size(1:hor,2)), 'Color', 'black')
            x_axis2 = [1:hor,  fliplr(1:hor)];
            inBetween = [a', fliplr(b2')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b2', fliplr(b1')];
            fill(x_axis2, inBetween,[0.9   0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            inBetween = [a', fliplr(b3')];
            fill(x_axis2, inBetween,[0.75    0.75    0.75],'LineStyle','none');
            inBetween = [b3', fliplr(b4')];
            fill(x_axis2, inBetween,[0.9    0.9   0.9],'LineStyle','none','FaceAlpha',.8);
            plot(1:hor,a,'Color', 'black')
            if oo==0
            ylim([-0.1 0.5])
            title([titles ' on EPU ' datestr(time_of_response(i,:), 'mmm yyyy')])
            else
            ylim([-0.3 0.1])
            title([titles ' on EONIA ' datestr(time_of_response(i,:), 'mmm yyyy')])    
            end
            hold off
        end
        
        folder= ['pics'];
        temp=['pics\', dataset, 'final_2D_window_size_uncertainty.png'];        
        % saveas(gcf,temp);

        export_fig(temp, '-transparent')  
    
end

