Impulse Response

## Impulse response plots I (accumulated and long-run responses)

The following program estimates an unrestricted VAR and obtains various plots of impulse response functions. Note (1) how we can store the responses in a named matrix and (2) how we can plot the accumulated responses together with the long-run response.

    ' impulse response functions
    ' replicates Lutkepohl (1991) pp.105-113
    ' 1/7/2000 h
    ' last checked 10/27/2000 h

    'change path to program path
    %path = @runpath
    cd "{%path}"

    ' load workfile
    load lut1

    ' estimate VAR
    smpl 1960:1 1978:4
    var1.ls 1 2 y1 y2 y3 @ c

    '--------------------------------------------------------------
    ' unit impulse
    '--------------------------------------------------------------
    ' Fig 3.4 (p.107)
    freeze(fig34) var1.impulse(m,imp=unit,matbys=tab33_1) y3 @ y2

    ' Fig 3.5 (p.107)
    freeze(fig35) var1.impulse(m,imp=unit) y1 @ y3

    ' combine two graphs into one
    freeze(fig_p107) fig34 fig35
    show fig_p107

    '--------------------------------------------------------------
    ' accumulated response to unit impulse
    '--------------------------------------------------------------
    ' Fig 3.6 (p.109)
    freeze(fig36) var1.impulse(m,a,imp=unit,matbys=tab33_2) y3 @ y2

    ' get long-run response (bottom right matrix in Table 3.3, p.106)
    matrix lrrsp33 = var1.@lrrsp

    ' add long-run response to impulse response graph
    !dtmp = lrrsp33(3,2)
    fig36.draw(dashline,left) !dtmp

    ' Fig 3.7 (p.109)
    freeze(fig37) var1.impulse(m,a,imp=unit) y1 @ y3
    ' add long-run response to impulse response graph
    !dtmp = lrrsp33(1,3)
    fig37.draw(dashline,left) !dtmp

    ' combine two graphs into one
    freeze(fig_p109) fig36 fig37
    show fig_p109

    '--------------------------------------------------------------
    ' cholesky impulse
    '--------------------------------------------------------------
    ' Fig 3.8 (p.112)
    freeze(fig38) var1.impulse(m,imp=chol,matbys=tab34_1) y3 @ y2

    ' Fig 3.9 (p.112)
    freeze(fig39) var1.impulse(m,a,imp=chol,matbys=tab34_2) y3 @ y2

    ' get long-run response (bottom right matrix in Table 3.4, p.111)
    matrix lrrsp34 = var1.@lrrsp

    ' add long-run response to impulse response graph
    !dtmp = lrrsp34(3,2)
    fig39.draw(dashline,left) !dtmp

    ' combine two graphs into one
    freeze(fig_p112) fig38 fig39
    show fig_p112

## Impulse response plots II (asymptotic and monte carlo standard errors)

The following program plots the impulse response analytic standard errors and the Monte Carlo standard errors in one graph. The program calls a subroutine sub_irfgraph() to do the job. This subroutine requires you to pass in the standard errors in a matrix as stored by the matbys= or matbyr= option of the impulse command (the standard errors are stored in a matrix with _se appended to the name you provided for the impulse responses).

    ' compare analytic and monte-carlo impulse response s.e.
    ' plots the two standard error bands in one graph
    ' version 4 beta
    ' 1/31/2000 h
    ' last checked 10/27/2000 h

    ' include subroutine
    include sub_irfgraph.prg

    'change path to program path
    %path = @runpath
    cd "{%path}"

    ' load workfile
    load lut1

    ' estimate VAR
    smpl 1960:1 1978:4
    var1.ls 1 2 y1 y2 y3 @ c

    !hrz = 10			' response periods
    !rep = 500			' monte carlo replications

    ' get analytic impulse response standard errors
    var1.impulse(m,imp=chol,se=a,matbyr=analyt)

    ' get monte carlo impulse response standard errors
    var1.impulse(m,imp=chol,se=mc,rep=!rep,matbyr=mcarlo)

    ' plot in one graph
    %gname = "fig1"
    call sub_irfgraph(analyt, analyt_se, mcarlo_se, %gname)
    ' add zero line to all graphs
    {%gname}.draw(line,left) 0
    ' add title to graph
    {%gname}.addtext(t) Comparison of Impulse Response Standard Errors (Analytic---Red vs Monte Carlo---Green)

    show {%gname}

The subroutine file sub_irfgraph.prg looks as follows:

    ' plot analytic and monte carlo standard errors in one graph
    ' need to pass results stored in a matrix using the
    ' matbys= option of impulse command
    ' version 4 beta
    ' 1/31/2000 h
    ' last revised and checked 9/19/2000 h

    ' rps = name of matrix specified by matbys = option
    ' se1 = name of matrix of standard errors returned by matbys = option (with _se post-fix)
    ' se2 = name of matrix of standard errors returned by matbys = option (with _se post-fix)
    ' %gname = name for final combined graph

    subroutine sub_irfgraph(matrix rsp, matrix se1, matrix se2, string %gname)

    !hrz = @rows(rsp)
    !k2 = @columns(rsp)

    vector v
    vector vbd
    matrix rspse1 = se1*2
    matrix rspse2 = se2*2

    matrix(!hrz,5) tmp

    ' plot each graph separately
    for !c=1 to !k2
    	' get point estimates
    	v = @columnextract(rsp,!c)
    	colplace(tmp,v,1)
    	' get bounds using first input
    	vbd = v + @columnextract(rspse1,!c)
    	colplace(tmp,vbd,2)
    	vbd = v - @columnextract(rspse1,!c)
    	colplace(tmp,vbd,3)
    	' get bounds using second input
    	vbd = v + @columnextract(rspse2,!c)
    	colplace(tmp,vbd,4)
    	vbd = v - @columnextract(rspse2,!c)
    	colplace(tmp,vbd,5)
    	freeze(tmp_graph{!c}) tmp.line
    	tmp_graph{!c}.elem(1) lcolor(blue) lpat(solid)
    	tmp_graph{!c}.elem(2) lcolor(red) lpat(dash1)
    	tmp_graph{!c}.elem(3) lcolor(red) lpat(dash1)
    	tmp_graph{!c}.elem(4) lcolor(green) lpat(dash2)
    	tmp_graph{!c}.elem(5) lcolor(green) lpat(dash2)
    	tmp_graph{!c}.option linepat	' need to set linepat
    	tmp_graph{!c}.legend(off)
    '	tmp_graph{!c}.legend -display
    	%namelist = %namelist + "tmp_graph" + @str(!c) + " "
    next

    ' combine graphs
    freeze({%gname}) {%namelist}

    delete v vbd rspse1 rspse2 {%namelist}

    endsub

## Variance decomposition Monte Carlo standard errors

The following program estimates an unrestricted VAR and computes variance decompositions with Monte Carlo standard errors (for 500 replications). The `matbyr=mat35` option stores the results in three matrices. MAT35 contains the variance decompositions, MAT35_FSE constains the forecast standard errors, and MAT35_SE contains the Monte Carlo decomposition standard errors. (Note that the results do not quite match those reported in Lutkepohl (1991) Table 3.5, p.113, which uses analytic standard errors.)

    ' variance decomposition
    ' replicates Lutkepohl (1991) pp.111-113
    ' version 4 beta
    ' 1/10/2000 h
    ' last checked 10/27/2000 h

    'change path to program path
    %path = @runpath
    cd "{%path}"

    ' load workfile
    load lut1

    ' estimate VAR
    smpl 1960:1 1978:4
    var1.ls 1 2 y1 y2 y3 @ c

    ' variance decomposition with Monte Carlo standard errors
    freeze(tab35) var1.decomp(t,imp=chol,se=mc,rep=500,matbyr=mat35) y1 y2 y3 @ @ y1 y2 y3
    show tab35