\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 0. PRELIMINARIES }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------ }\\ 
\hspace{1mm}clear; close all; clc \\ 
\hspace{1mm}warning off all \\ 
\hspace{1mm}format short g \\ 
\hspace{1mm}addpath(genpath(\textcolor{matlabpurple}{'/Users/jambro/GDrive/VAR-Toolbox/v3dot0'})) \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 1. LOAD AND STORE DATA }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%******************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Loads some US macro data to be used in the first example. The data is  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% stored in the structure DATA }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------ }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Load data from US macro data set }\\ 
\hspace{1mm}[xlsdata, xlstext] = xlsread(\textcolor{matlabpurple}{'data/Simple\_Data.xlsx'},\textcolor{matlabpurple}{'Sheet1'}); \\ 
\hspace{1mm}dates = xlstext(3:end,1);       \textcolor{matlabgreen}{\% vector of dates in string format }\\ 
\hspace{1mm}datesnum = Date2Num(dates);     \textcolor{matlabgreen}{\% vector of dates in numeric format }\\ 
\hspace{1mm}vnames\_long = xlstext(1,2:end); \textcolor{matlabgreen}{\% full variable names  }\\ 
\hspace{1mm}vnames = xlstext(2,2:end);      \textcolor{matlabgreen}{\% variable mnemonic  }\\ 
\hspace{1mm}nvar = length(vnames);          \textcolor{matlabgreen}{\% number of variables in spreadsheet }\\ 
\hspace{1mm}data   = Num2NaN(xlsdata);      \textcolor{matlabgreen}{\% matrix of data in spreadsheet }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Store variables in the structure DATA }\\ 
\hspace{1mm}\textcolor{matlabblue}{for} ii=1:length(vnames) \\ 
\hspace{1mm}\hspace{5mm} DATA.(vnames\{ii\}) = data(:,ii); \\ 
\hspace{1mm}\textcolor{matlabblue}{end} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Observations }\\ 
\hspace{1mm}nobs = size(data,1); \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 2. TREAT DATA }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%******************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Computes the growth rate of real GDP and CPI index and the first  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% difference of the 1-year Treasury Bill yield }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------ }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Select variables to treat }\\ 
\hspace{1mm}tempnames = \{\textcolor{matlabpurple}{'gdp'},\textcolor{matlabpurple}{'cpi'},\textcolor{matlabpurple}{'i1yr'}\};         \textcolor{matlabgreen}{\% variable mnemonics }\\ 
\hspace{1mm}temptreat = \{\textcolor{matlabpurple}{'logdiff'},\textcolor{matlabpurple}{'logdiff'},\textcolor{matlabpurple}{'diff'}\}; \textcolor{matlabgreen}{\% type of transformation }\\ 
\hspace{1mm}tempscale = [100 100 1];                  \textcolor{matlabgreen}{\% rescaling (if needed) }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Treat and add to DATA structure }\\ 
\hspace{1mm}\textcolor{matlabblue}{for} ii=1:length(tempnames) \\ 
\hspace{1mm}\hspace{5mm} aux = \{[\textcolor{matlabpurple}{'d'} tempnames\{ii\}]\}; \\ 
\hspace{1mm}\hspace{5mm} DATA.(aux\{1\}) = tempscale(ii)*... \\ 
\hspace{1mm}\hspace{5mm} XoX(DATA.(tempnames\{ii\}),1,temptreat\{ii\}); \\ 
\hspace{1mm}\textcolor{matlabblue}{end} \\ 
\hspace{1mm}delete temp* \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 3. VAR ESTIMATION }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%******************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% VAR estimation is achieved in two steps. First, select list of  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% endogenous variables (these will be pulled from the structure DATA,  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% where all data is stored). Second, set desired number of lags and  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% deterministic variables and run the VARmodel function. }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------ }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Select the list of endogenous variables... }\\ 
\hspace{1mm}Xvnames = \{\textcolor{matlabpurple}{'dgdp'},\textcolor{matlabpurple}{'i1yr'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% ... and corresponding labels to be used in plots }\\ 
\hspace{1mm}Xvnames\_long = \{\textcolor{matlabpurple}{'Real GDP Growth'},\textcolor{matlabpurple}{'1-year Int. Rate'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Number of endo variables }\\ 
\hspace{1mm}Xnvar = length(Xvnames); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Create matrix X of variables to be used in the VAR }\\ 
\hspace{1mm}X = nan(nobs,Xnvar); \\ 
\hspace{1mm}\textcolor{matlabblue}{for} ii=1:Xnvar \\ 
\hspace{1mm}\hspace{5mm} X(:,ii) = DATA.(Xvnames\{ii\}); \\ 
\hspace{1mm}\textcolor{matlabblue}{end} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Open a figure of the desired size and plot the selected variables }\\ 
\hspace{1mm}FigSize(26,8) \\ 
\hspace{1mm}\textcolor{matlabblue}{for} ii=1:Xnvar \\ 
\hspace{1mm}\hspace{5mm} subplot(1,2,ii) \\ 
\hspace{1mm}\hspace{5mm} H(ii) = plot(X(:,ii),\textcolor{matlabpurple}{'LineWidth'},3,\textcolor{matlabpurple}{'Color'},cmap(1)); \\ 
\hspace{1mm}\hspace{5mm} title(Xvnames\_long(ii));  \\ 
\hspace{1mm}\hspace{5mm} DatesPlot(datesnum(1),nobs,6,\textcolor{matlabpurple}{'q'}) \textcolor{matlabgreen}{\% Set the x-axis labels }\\ 
\hspace{1mm}\hspace{5mm} grid on;  \\ 
\hspace{1mm}\textcolor{matlabblue}{end} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Save figure }\\ 
\hspace{1mm}SaveFigure(\textcolor{matlabpurple}{'graphics/BIV\_DATA'},2) \\ 
\hspace{1mm}clf(\textcolor{matlabpurple}{'reset'}) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Make a common sample by removing NaNs }\\ 
\hspace{1mm}[X, fo, lo] = CommonSample(X); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Set the deterministic variable in the VAR (1=constant, 2=trend) }\\ 
\hspace{1mm}det = 1; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Set number of lags }\\ 
\hspace{1mm}nlags = 1; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Estimate VAR by OLS }\\ 
\hspace{1mm}[VAR, VARopt] = VARmodel(X,nlags,det); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Print at screen the outputs of the VARmodel estimation }\\ 
\hspace{1mm}format short \\ 
\hspace{1mm}disp(VAR) \\ 
\hspace{1mm}disp(VAR.F) \\ 
\hspace{1mm}disp(VAR.sigma) \\ 
\hspace{1mm}disp(VARopt) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with additional details }\\ 
\hspace{1mm}VARopt.vnames = Xvnames\_long; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Print at screen VAR coefficients and create table  }\\ 
\hspace{1mm}[TABLE, beta] = VARprint(VAR,VARopt,2); \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 4. IDENTIFICATION WITH ZERO CONTEMPORANEOUS RESTRICTIONS  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%******************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Identification with zero contemporaneous restrictions is achieved in two  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% steps: (1) set the identification scheme mnemonic in the structure  }\\ 
\hspace{1mm}\textcolor{matlabblue}{case} "short"; (2) run VARir, VARvd or }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% VARhd functions.  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure to select zero short-run restrictions  }\\ 
\hspace{1mm}VARopt.ident = \textcolor{matlabpurple}{'short'}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with additional details  }\\ 
\hspace{1mm}VARopt.vnames = Xvnames\_long;            \textcolor{matlabgreen}{\% variable names in plots }\\ 
\hspace{1mm}VARopt.nsteps = 12;                      \textcolor{matlabgreen}{\% max horizon of IRF }\\ 
\hspace{1mm}VARopt.FigSize = [26,12];                \textcolor{matlabgreen}{\% size of window (figures) }\\ 
\hspace{1mm}VARopt.firstdate = datesnum(1);          \textcolor{matlabgreen}{\% first date in plots }\\ 
\hspace{1mm}VARopt.frequency = \textcolor{matlabpurple}{'q'};                  \textcolor{matlabgreen}{\% frequency of the data }\\ 
\hspace{1mm}VARopt.snames = \{\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Demand\}'},... \textcolor{matlabgreen}{\% shock names }\\ 
\hspace{1mm}\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{MonPol\}'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute impulse response }\\ 
\hspace{1mm}[IR, VAR] = VARir(VAR,VARopt); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Print at screen  }\\ 
\hspace{1mm}format short \\ 
\hspace{1mm}disp(VAR.B) \\ 
\hspace{1mm}disp(IR(1:4,:,2)) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute structural shocks (Tx2) }\\ 
\hspace{1mm}eps\_short = (VAR.B$\backslash$VAR.resid')'; \\ 
\hspace{1mm}disp(corr(eps\_short)) \\ 
\hspace{1mm} \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 5. IDENTIFICATION WITH ZERO LONG-RUN RESTRICTIONS  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%**************************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Identification with zero long-run restrictions is achieved in two  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% steps: (1) set the identification scheme mnemonic in the structure  }\\ 
\hspace{1mm}\textcolor{matlabblue}{case} "long"; (2) run VARir, VARvd or }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% VARhd functions.  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure to select zero long-run restrictions  }\\ 
\hspace{1mm}VARopt.ident = \textcolor{matlabpurple}{'long'}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with additional details  }\\ 
\hspace{1mm}VARopt.snames = \{\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Supply\}'},... \textcolor{matlabgreen}{\% shocks names }\\ 
\hspace{1mm}\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Demand\}'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute impulse responses }\\ 
\hspace{1mm}[IR, VAR] = VARir(VAR,VARopt); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Print at screen  }\\ 
\hspace{1mm}format short \\ 
\hspace{1mm}disp(VAR.B) \\ 
\hspace{1mm}disp((eye(2)-VAR.Fcomp)$\backslash$VAR.B) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute impulse responses in the very long-run and plot }\\ 
\hspace{1mm}VARopt.nsteps = 150; \\ 
\hspace{1mm}[IR, VAR] = VARir(VAR,VARopt); \\ 
\hspace{1mm}FigSize(26,8) \\ 
\hspace{1mm}subplot(1,2,1) \\ 
\hspace{1mm}plot(cumsum(IR(:,1,2)),\textcolor{matlabpurple}{'LineWidth'},2,\textcolor{matlabpurple}{'Marker'},\textcolor{matlabpurple}{'*'},\textcolor{matlabpurple}{'Color'},cmap(1)); hold on \\ 
\hspace{1mm}plot(zeros(VARopt.nsteps),\textcolor{matlabpurple}{'--k'},\textcolor{matlabpurple}{'LineWidth'},0.5); hold on \\ 
\hspace{1mm}xlim([1 VARopt.nsteps]); \\ 
\hspace{1mm}title(\textcolor{matlabpurple}{'Cumulative response of GDP growth'}) \\ 
\hspace{1mm}subplot(1,2,2) \\ 
\hspace{1mm}plot(cumsum(IR(:,2,2)),\textcolor{matlabpurple}{'LineWidth'},2,\textcolor{matlabpurple}{'Marker'},\textcolor{matlabpurple}{'*'},\textcolor{matlabpurple}{'Color'},cmap(1)); hold on \\ 
\hspace{1mm}plot(zeros(VARopt.nsteps),\textcolor{matlabpurple}{'--k'},\textcolor{matlabpurple}{'LineWidth'},0.5); hold on \\ 
\hspace{1mm}xlim([1 VARopt.nsteps]); \\ 
\hspace{1mm}title(\textcolor{matlabpurple}{'Cumulative response of the 1-year rate'}) \\ 
\hspace{1mm}SaveFigure(\textcolor{matlabpurple}{'graphics/longCum\_'},2); \\ 
\hspace{1mm}clf(\textcolor{matlabpurple}{'reset'}) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute structural shocks (Tx2) }\\ 
\hspace{1mm}eps\_long = (VAR.B$\backslash$VAR.resid')'; \\ 
\hspace{1mm} \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 6. IDENTIFICATION WITH SIGN RESTRICTIONS  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%**************************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Identification with sign restrictions is achieved in two steps: (1) }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% define a matrix with the sign restrictions that the impulse responses  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% have to satisfy; (2) run the SR function.  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%------------------------------------------------------------------  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Define sign restrictions }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Positive 1, Negative -1, Unrestricted 0: }\\ 
\hspace{1mm}SIGN = [ 1, 1;  \textcolor{matlabgreen}{\% Real GDP }\\ 
\hspace{1mm}1,-1]; \textcolor{matlabgreen}{\% 1-year rate  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with inputs to the sign restriction routine }\\ 
\hspace{1mm}VARopt.ndraws = 500; \\ 
\hspace{1mm}VARopt.sr\_hor = 1; \\ 
\hspace{1mm}VARopt.pctg = 68;  \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with additional details  }\\ 
\hspace{1mm}VARopt.nsteps = 12;                      \textcolor{matlabgreen}{\% horizon of impulse responses }\\ 
\hspace{1mm}VARopt.figname= \textcolor{matlabpurple}{'graphics/sign\_'};        \textcolor{matlabgreen}{\% folder and file prefix }\\ 
\hspace{1mm}VARopt.FigSize = [26 8];                 \textcolor{matlabgreen}{\% size of window (figures) }\\ 
\hspace{1mm}VARopt.quality = 2;                 \textcolor{matlabgreen}{\% size of window (figures) }\\ 
\hspace{1mm}VARopt.snames = \{\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Demand\}'},... \textcolor{matlabgreen}{\% shocks names }\\ 
\hspace{1mm}\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{MonPol\}'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Implement sign restrictions identification with SR routine }\\ 
\hspace{1mm}SRout = SR(VAR,SIGN,VARopt); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Plot all Btilde }\\ 
\hspace{1mm}FigSize(26,8) \\ 
\hspace{1mm}subplot(1,2,1) \\ 
\hspace{1mm}plot(squeeze(SRout.IRall(:,1,2,:))); hold on \\ 
\hspace{1mm}plot(zeros(VARopt.nsteps),\textcolor{matlabpurple}{'--k'},\textcolor{matlabpurple}{'LineWidth'},0.5); hold on \\ 
\hspace{1mm}xlim([1 VARopt.nsteps]); \\ 
\hspace{1mm}title(\textcolor{matlabpurple}{'Response of GDP growth to $\backslash$epsilon\texttt{\^}\{MonPol\}'}) \\ 
\hspace{1mm}subplot(1,2,2) \\ 
\hspace{1mm}plot(squeeze(SRout.IRall(:,2,2,:))); hold on \\ 
\hspace{1mm}plot(zeros(VARopt.nsteps),\textcolor{matlabpurple}{'--k'},\textcolor{matlabpurple}{'LineWidth'},0.5); hold on \\ 
\hspace{1mm}xlim([1 VARopt.nsteps]); \\ 
\hspace{1mm}title(\textcolor{matlabpurple}{'Response of 1-year rate to $\backslash$epsilon\texttt{\^}\{MonPol\}'}) \\ 
\hspace{1mm}SaveFigure(\textcolor{matlabpurple}{'graphics/signAll\_'},2); \\ 
\hspace{1mm}clf(\textcolor{matlabpurple}{'reset'}) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Plot credible intervals }\\ 
\hspace{1mm}VARirplot(SRout.IRmed,VARopt,SRout.IRinf,SRout.IRsup) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute structural shocks (Tx2) }\\ 
\hspace{1mm}eps\_sign = (SRout.B$\backslash$VAR.resid')'; \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 7. IDENTIFICATION WITH EXTERNAL INSTRUMENTS }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%**************************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Identification with external instruments is achieved in three steps: (1)  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% update the VAR structure with the external instrument to be used in the  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% first stage; (2) set the identification scheme mnemonic in the structure  }\\ 
\hspace{1mm}\textcolor{matlabblue}{case} "iv"; (3) run the VARir \textcolor{matlabblue}{function} }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%--------------------------------------------------------------------------  }\\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Create artificial instrument (demand shock from eps\_short + noise) }\\ 
\hspace{1mm}rng(1);  \\ 
\hspace{1mm}noise = randn(nobs,1);              \textcolor{matlabgreen}{\% random vector from N(0,1)  }\\ 
\hspace{1mm}noise = noise(1+fo:end-lo);         \textcolor{matlabgreen}{\% adjust to common sample }\\ 
\hspace{1mm}iv = [NaN; eps\_short(:,1)] + noise; \textcolor{matlabgreen}{\% add noise to demand shock (eps\_short) }\\ 
\hspace{1mm}VAR.IV = iv;                        \textcolor{matlabgreen}{\% update VAR structure }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the options in VARopt }\\ 
\hspace{1mm}VARopt.ident = \textcolor{matlabpurple}{'iv'}; \\ 
\hspace{1mm}VARopt.snames = \{\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Demand\}'},\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Other\}'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Compute impulse responses }\\ 
\hspace{1mm}[IR, VAR] = VARir(VAR,VARopt); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Plot impulse responses }\\ 
\hspace{1mm}FigSize(26,8) \\ 
\hspace{1mm}\textcolor{matlabblue}{for} ii=1:Xnvar \\ 
\hspace{1mm}\hspace{5mm} subplot(1,2,ii); \\ 
\hspace{1mm}\hspace{5mm} 	plot(IR(:,ii),\textcolor{matlabpurple}{'LineWidth'},2,\textcolor{matlabpurple}{'Marker'},\textcolor{matlabpurple}{'*'},\textcolor{matlabpurple}{'Color'},cmap(1)); hold on; \\ 
\hspace{1mm}\hspace{5mm} plot(zeros(1,VARopt.nsteps),\textcolor{matlabpurple}{'--k'},\textcolor{matlabpurple}{'LineWidth'},0.5); hold on \\ 
\hspace{1mm}\hspace{5mm} plot(1,IR(1,ii),\textcolor{matlabpurple}{'LineStyle'},\textcolor{matlabpurple}{'-'},\textcolor{matlabpurple}{'Color'},cmap(5),\textcolor{matlabpurple}{'LineWidth'},2,... \\ 
\hspace{1mm}\hspace{5mm} \textcolor{matlabpurple}{'Marker'},\textcolor{matlabpurple}{'p'},\textcolor{matlabpurple}{'MarkerSize'},20,\textcolor{matlabpurple}{'MarkerFaceColor'},cmap(5)); hold on \\ 
\hspace{1mm}\hspace{5mm} xlim([1 VARopt.nsteps]); \\ 
\hspace{1mm}\hspace{5mm} title([Xvnames\_long\{ii\} \textcolor{matlabpurple}{' to '} VARopt.snames\{1\}],\textcolor{matlabpurple}{'FontWeight'},\textcolor{matlabpurple}{'bold'},\textcolor{matlabpurple}{'FontSize'},10);  \\ 
\hspace{1mm}\hspace{5mm} set(gca, \textcolor{matlabpurple}{'Layer'}, \textcolor{matlabpurple}{'top'}); \\ 
\hspace{1mm}\textcolor{matlabblue}{end} \\ 
\hspace{1mm}SaveFigure(\textcolor{matlabpurple}{'graphics/iv\_'},2) \\ 
\hspace{1mm}clf(\textcolor{matlabpurple}{'reset'}); \\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\%}\textcolor{matlabgreen}{\% 8. IDENTIFICATION WITH EXTERNAL INSTRUMENTS AND SIGN RESTRICTIONS }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%**************************************************************************  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Identification with external instruments and sign restrictions is  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% achieved in five steps: (1) update the VAR structure with the external  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% instrument to be used in the first stage; (2) set the identification  }\\ 
\hspace{1mm}\textcolor{matlabblue}{case}  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% "iv"; (3) run the VARir \textcolor{matlabblue}{function} to get an estimate of Biv; (4) define a  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% matrix with the sign restrictions that the IRs have to satisfy, excluding }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% the first shock identified with external instruments; (5) run the SR  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% function.  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\%--------------------------------------------------------------------------  }\\ 
\hspace{1mm} \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% VAR structure has already been updated to include the first column of  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% the B matrix that we identified with the instrument in the previous }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% section: }\\ 
\hspace{1mm}disp(VAR.Biv) \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Define sign restrictions to identify monetary policy shock }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Positive 1, Negative -1, Unrestricted 0: }\\ 
\hspace{1mm}SIGN = [ 1;  \textcolor{matlabgreen}{\% Real GDP }\\ 
\hspace{1mm}-1]; \textcolor{matlabgreen}{\% 1-year rate  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Update the VARopt structure with additional details  }\\ 
\hspace{1mm}VARopt.figname= \textcolor{matlabpurple}{'graphics/iv\_sign\_'};       \\ 
\hspace{1mm}VARopt.snames = \{\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{Demand\}'},\textcolor{matlabpurple}{'$\backslash$epsilon\texttt{\^}\{MonPol\}'}\}; \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Implement sign restrictions identification with SR routine  }\\ 
\hspace{1mm}\textcolor{matlabgreen}{\% conditional on VAR.Biv being already identified  }\\ 
\hspace{1mm}SRIVout = SR(VAR,SIGN,VARopt); \\ 
\hspace{1mm}\textcolor{matlabgreen}{\% Plot impulse responses }\\ 
\hspace{1mm}VARirplot(SRIVout.IRmed,VARopt,SRIVout.IRinf,SRIVout.IRsup); \\ 
\hspace{1mm} \\ 
\hspace{1mm}m2tex(\textcolor{matlabpurple}{'VARToolbox\_Primer\_v1.m'}) \\ 
\hspace{1mm} \\ 
\hspace{1mm}close all \\ 
\hspace{1mm} \\ 
\hspace{1mm} \\ 
