% ===========================================================================================
% Replication: Barigozzi, Lissona & Tonni (2026) - "Large datasets for the Euro Area and its
% member countries and the dynamic effects of the common monetary policy"
%
% Estimates the Country-Common VAR (CC-VAR) identified with an external instrument (IV) for
% the Euro Area and its member countries, and produces the paper's main results (Tables 3-4
% and Figures 1-3). Impulse responses and bootstrap confidence bands are saved to
% outputs/ccvar_monthly_iv/Results.mat.
% -------------------------------------------------------------------------------------------
% Author: Lorenzo Tonni (lorenzo.tonni@unimi.it)
% Last update: 09/Jun/2026
% Version: MATLAB 2026a
% -------------------------------------------------------------------------------------------

%% Settings and data import
clear; clear session; close all; clc;
warning off all

restoredefaultpath
project_root = fileparts(mfilename('fullpath'));
if isempty(project_root)
    project_root = pwd;
end

% ===============|| Set Output Folder ||============= %
Folder_output = fullfile(project_root, 'outputs', 'ccvar_monthly_iv');
if ~isfolder(Folder_output)
    mkdir(Folder_output);
end


% ===============|| Set Figures Folder ||============= %
folder_fig = fullfile(project_root, 'Figures');

% ===============|| Set Instruments Path ||============= %
addpath(fullfile(project_root, 'data', 'Instruments'))
addpath(fullfile(project_root, 'data', 'monthly'))

% ===============|| SetFunctions Path ||============= %
addpath(fullfile(project_root, 'Functions'))

%% ====================== %%
% Confidence bands option
% ======================= %%

conf = 1; % (0) do not estimate confidence bands (about 1 minute)
          % (1) estimate confidence bands (about 40 minutes on a 2021 MacBook Pro)

%===============================================%
%  Generate IRFs for CC-VAR identified with IV  %
%===============================================%

% Process data
[DATA, HEADER, DATES, ID] = process_data_M;
policy_instrument = DATA.policy;
mpi = DATA.MPI;

% Estimate model
results = loop_ccvar(conf, DATA, HEADER, DATES, ID, policy_instrument, mpi);

% Save 
filename = 'Results.mat';
save(fullfile(Folder_output, filename), 'results');


                            
                       
              
          


                               