'open the workfile data wfopen .\bootsvar_example_data 'draw figure-1 group vars.add @pcy(gdp) @pcy(tucpi) freeze(mode=overwrite,figure1) vars.line figure1.axis dual figure1.legend columns(2) figure1.setelem(1) legend(Output growth) figure1.setelem(2) legend(Inflation rate) 'input variables !alpha = 0.05 'significance level !lags = 4 'number of lags !impulse = 1 'type of impulse-response (i.e. ordinary) !horizon = 20 'horizon of impulse-response !nboot = 10000 'number of bootstrap draws %output = "outfull" 'name of the output matrix to contain bootstrapped IRF values %pairs = "2 1 2 2" 'Impulse-response pairs of interest %outnew = %output+"_pairs" 'name of the output matrix containing IRF values of selected pairs 'estimate the VAR model (optimal lag length is 1) smpl 2005q1 2025q3 var vareq.ls 1 !lags dlog(gdp)*100 d(dlog(tucpi)*100) !nvars = vareq.@neqn 'number of endogenous variables 'write restrictions in a string vector svector restrict = "@VEC(F) = NA, NA, 0, NA" 'define a sign vector vector signvec = @zeros(!nvars) signvec(1) = 1 'impact of supply (first) shock is positive on GDP signvec(2) = -2 'impact of monetary (second) shock is negative on inflation 'run the add-in bootsvar(vareq=vareq,svar=restrict,sign=signvec,impulse=!impulse,horizon=!horizon,response=%pairs,nboot=!nboot,output={%output},accum) 'IRF of second shock to quarterly GDP growth vector irf21_m = @cquantile(@subextract({%outnew},1,1,!nboot,!horizon),0.5) vector irf21_l= @cquantile(@subextract({%outnew},1,1,!nboot,!horizon),!alpha/2) vector irf21_u = @cquantile(@subextract({%outnew},1,1,!nboot,!horizon),1-!alpha/2) matrix irf21 = @hcat(irf21_m,irf21_l) irf21 = @hcat(irf21,irf21_u) freeze(mode=overwrite,figure3a) irf21.line figure3a.setelem(2) linepattern(DASH1) linecolor(@rgb(0,0,0)) figure3a.setelem(3) linepattern(DASH1) linecolor(@rgb(0,0,0)) figure3a.options linepat figure3a.legend -display 'IRF of second shock to quarterly CPI inflation vector irf22_m = @cquantile(@subextract({%outnew},1,!horizon+1,!nboot,!horizon*2),0.5) vector irf22_l= @cquantile(@subextract({%outnew},1,!horizon+1,!nboot,!horizon*2),!alpha/2) vector irf22_u = @cquantile(@subextract({%outnew},1,!horizon+1,!nboot,!horizon*2),1-!alpha/2) matrix irf22 = @hcat(irf22_m,irf22_l) irf22 = @hcat(irf22,irf22_u) freeze(mode=overwrite,figure3b) irf22.line figure3b.setelem(2) linepattern(DASH1) linecolor(@rgb(0,0,0)) figure3b.setelem(3) linepattern(DASH1) linecolor(@rgb(0,0,0)) figure3b.options linepat figure3b.legend -display 'bootstrapped values of sacrifice ratios vector sacrifice = @ediv((@csum(@transpose(@subextract({%outnew},1,1,!nboot,!horizon)))),@columnextract({%outnew},!horizon*2)) freeze(mode,overwrite,figure4) sacrifice.distplot hist(anchor=0, scale=dens) theory(lgnd=detail)