' replicate Sims (1986) with similar data 
' for version 4
' 1/12/2000 h
' last checked 10/27/2000 h

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

' create workfile											  
workfile sims1 q 1948:1 1979:3

' fetch data from database
fetch(d=data_svar) rgnp rinv pidgnp m1 tb3sec unemp

' transform series 
series lgnp = log(rgnp)
series linv = log(rinv)
series lprc = log(pidgnp)
series lm1 = log(m1)

'----------------------------------------------------------------------
' replicate Chart 1 (p.11) *no Bayesian priors imposed*
'----------------------------------------------------------------------

var var1.ls 1 4 lgnp linv lprc lm1 unemp tb3sec @ c
freeze(chart1) var1.impulse(32,m,imp=chol,se=a)
show chart1

' plot only some of money innovation responses
freeze(chart1a) var1.impulse(32,m,imp=chol,se=a) lgnp lprc tb3sec @ lm1 

'----------------------------------------------------------------------
' replicate Chart 2 (p.13)
'----------------------------------------------------------------------

' reorder VAR to confirm to Sims' (1986) ordering
var var1.ls 1 4 tb3sec lm1 lgnp lprc unemp linv @ c

' 1st identification restrictions (p.12 (12)-(17))
coef(6) b
var1.append(svar) @e1 = c(1)*@e2 + b(1)*@u1
var1.append(svar) @e2 = c(2)*@e3 + c(3)*@e4 + c(4)*@e1 + b(2)*@u2
var1.append(svar) @e3 = c(5)*@e1 + c(6)*@e6 + b(4)*@u4
var1.append(svar) @e4 = c(7)*@e1 + c(8)*@e3 + c(9)*@e6 + b(5)*@u5
var1.append(svar) @e5 = c(10)*@e1 + c(11)*@e3 + c(12)*@e6 + c(13)*@e4 + b(6)*@u6
var1.append(svar) @e6 = b(3)*@u3

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

' replicate Chart 2 (p.13)
freeze(chart2) var1.impulse(32,m,imp=struct,se=a) lgnp linv lprc lm1 unemp tb3sec @ 1 2 4 5 6 3
show chart2

' plot only some of money supply responses
freeze(chart2a) var1.impulse(32,m,imp=struct,se=a) lgnp lprc tb3sec @ 1 

'----------------------------------------------------------------------
' replicate Chart 3 (p.13)
'----------------------------------------------------------------------

' clear previous restrictions
var1.cleartext(svar)

' 2nd identification restrictions (p.14 (18)-(23))
var1.append(svar) @e1 = c(1)*@e2 + b(1)*@u1
var1.append(svar) @e2 = c(2)*@e3 + c(3)*@e6 + c(4)*@e4 + c(5)*@e1 + b(2)*@u2
var1.append(svar) @e3 = c(6)*@e1 + c(7)*@e6 + b(3)*@u3
var1.append(svar) @e4 = c(8)*@e1 + c(9)*@e3 + c(10)*@e2 + b(5)*@u5
var1.append(svar) @e5 = c(11)*@e1 + c(12)*@e3 + c(13)*@e4 + c(14)*@e6 + b(6)*@u6
var1.append(svar) @e6 = b(4)*@u4

' estimate structural factorization
' default starting value does not converge
rndseed 123456
freeze(svar2) var1.svar(rtype=text,conv=1e-5,f0=u)
show svar2

' replicate Chart 3 (p.13)
freeze(chart3) var1.impulse(32,m,imp=struct,se=a) lgnp linv lprc lm1 unemp tb3sec @ 1 2 3 5 6 4
show chart3

' plot only some of money supply responses
freeze(chart3a) var1.impulse(32,m,imp=struct,se=a) lgnp lprc tb3sec @ 1

