' replicate impulse response graph
' from long-run restriction (Blanchard-Quah 1989)
' for version 4
' 11/12/99 h
' last checked 10/27/2000 h

' include subroutine
include sub_rmaxdiff.prg

' create workfile
workfile blanquah q 1948:1 1987:4

' fetch data from database (already demeaned)
fetch(d=data_svar) dy u

' change to percentage
dy = 100*dy

' estimate VAR (no constant)
var var1.ls 1 8 dy u @ 

' impose long-run restrictions
' @u1 = aggregate demand shock
' @u2 = aggregate supply shock
var1.cleartext(svar)
var1.append(svar) @lr1(@u1)=0

' estimate factorization
freeze(tab1) var1.svar(rtype=text,conv=1e-5)

' set response horizon
!hrz = 40

' replicate Figures 3-4 (p.662)
' accumulate to get level response of output
freeze(fig3) var1.impulse(!hrz,imp=struct,se=a,a,matbys=rsp_acc) dy @ 1
freeze(fig4) var1.impulse(!hrz,imp=struct,se=a,a) dy @ 2
freeze(fig34) fig3 fig4
show fig34

' replicate Figures 5-6
freeze(fig5) var1.impulse(!hrz,imp=struct,se=a,matbys=rsp_lvl) u @ 1
freeze(fig6) var1.impulse(!hrz,imp=struct,se=a) u @ 2
freeze(fig56) fig5 fig6
show fig56

' replicate Figure 1
matrix(!hrz,2) mtmp
' get accumulated output response
vector v = @columnextract(rsp_acc,1)
colplace(mtmp,v,1)
' get level unemployment response
v = @columnextract(rsp_lvl,2)
colplace(mtmp,v,2)

freeze(fig1) mtmp.line
fig1.draw(line,left) 0
fig1.elem(1) legend(Output response to demand)
fig1.elem(2) legend(Unemployment response to demand)
show fig1

' replicate Figure 2
' get accumulated output response
vector v = @columnextract(rsp_acc,3)
colplace(mtmp,v,1)
' get level unemployment response
v = @columnextract(rsp_lvl,4)
colplace(mtmp,v,2)

freeze(fig2) mtmp.line
fig2.draw(line,left) 0
fig2.elem(1) legend(Output response to supply)
fig2.elem(2) legend(Unemployment response to supply)
show fig2

