*
* VAR_6_3
* Vector Autoregressions
* Example 6.3
*
* Example of SVAR with SR and LR constraints with error bands. This is
* based upon Application 14.6.1 from Martin, Hurn and Harris, but adds
* the calculation of error bands.
*
open data peersman_data.dat
calendar(q) 1970:1
data(format=prn,nolabels,org=columns) 1970:01 2002:02 oilprice outputemu $
 cpiemu rateemu outputus cpius rateus
*
set groil = 100.0*(log(oilprice/oilprice{1}))
set grout = 100.0*(log(outputus/outputus{1}))
set grp   = 100.0*(log(cpius/cpius{1}))
set r     = rateus
*
set trend = t
*
system(model=peersman)
variables groil grout grp r
lags 1 2 3
det constant trend
end(system)
*
estimate(sigma) 1979:5 *
dec rect lr(4,4) sr(4,4)
*
* Shock order is oil, AS, AD, money
*
input lr
 . . . .
 . . 0 0
 . . . .
 . . . .
input sr
 . 0 0 0
 . . . 0
 . . . .
 . . . .
************************************************************************
*
* FLongShort is a function to compute a long-and-short-run factorization
* given the current draw for sigma and the coefficients of the model.
* Note that this recomputes the MA sums given the lag sums at the draw
* for the coefficients, not the lag sum at the OLS estimates.
*
function FLongShort sigma model
type rect      FLongShort
type symmetric sigma
type model     model
*
local rect MASums
local rect f
*
compute MASums=inv(%ModelLagSums(model))
@shortandlong(factor=f,lr=lr,sr=sr,masum=MASums) sigma
*
* The sign fixing will be specific to an application. Here this makes
* shock 1 positive on variable 1 (oil price) (when you read this, the
* row in F is the target variable and the column is the shock), shock 2
* positive on variable 2 (output), shock 3 positive on variable 2 and
* shock 4 positive on variable 4 (interest rates). Use a - in front of
* the %sign to force an impact to be negative.
*
compute FLongShort=%dmult(f,$
  ||%sign(f(1,1)),%sign(f(2,2)),%sign(f(2,3)),%sign(f(4,4))||)
end
************************************************************************
*
* All but the first interest rates (variable 4) are in growth rates so
* we accumulate the responses to get (log) level effects.
*
@MCVARDoDraws(model=peersman,ffunction=FLongShort,$
   draws=2000,steps=40,accum=||1,2,3||)
*
@MCGraphIRF(model=peersman,$
  shocks=||"Oil Price","Supply Shock","Demand Shock","Money Shock"||,$
  variables=||"Oil Price","Output","Price","Interest Rate"||)
