econdawg wrote:Hello,
RATS provides a code for replicating Uhlig(2005)'s paper which essentially identify VARs using sign restrictions.The code though allows for the identification of one shock. I was thinking about identifying more than one shock at the same time (say 2 shocks). i am kinda puzzled as to how to incorporate that in the code. Would identifying a second shock implies doing a second inner-loop subdraw for another vector over the unit sphere? That is i would still draw initially from the posterior of the VAR then compute impulse responses, but instead of doing one subdraw (and compute vector a) for each draw from the posterior, i would do two subdraws (and compute a and another vector--say b). Then i would be essentially be constructing 2 impulse vectors simultaneously and go from there to check sign restrictions to identify the two shocks of interests. Am i thinking right about this? it would be very helpful (if any of you have time) to maybe guide me as to how i would modify the code in order to identify that second shock. Thanks a lot.
do subdraws=1,n2
************************************************
* First Set of Restrictions - Unique Impulse Vector
************************************************
compute v1=%ran(1.0),v1=v1/sqrt(%normsqr(v1))
compute v=i1=p*v1
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(4)<0.or.ik(6)<0.or.ik(2)>0.or.ik(5)>0
branch 105
end do k
*
* Meets the first restriction
* Draw from the orthogonal complement of i1 (last five columns of the
* factor "f").
*
@forcedfactor(force=column) sigmad i1 f
compute v2=%ran(1.0),v2=v2/sqrt(%normsqr(v2))
compute v=i2=%xsubmat(f,1,6,2,6)*v2
*****************************************************
* Second Set of Restrictions - Demand Shock
*****************************************************
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(1)<0.or.ik(2)<0
branch 105
end do k
*
* Meets both restrictions
*
compute accept=accept+1
dim goodrespa(accept)(nstep,nvar)
dim goodresp(accept)(nstep,nvar)
ewise goodresp(accept)(i,j)=(ik=%xt(impulses,i)*i1),ik(j)
ewise goodrespa(accept)(i,j)=(ik=%xt(impulses,i)*i2),ik(j)
if accept>=1000
break
:105
end do subdrawscompute v2=%ranmat(6,1) ;* Draw a random 6-vector
compute v2(1)=0.0 ;* Zero the 1st component
compute v2=v2/sqrt(%normsqr(v2)) ;* Normalize to unit length
compute v=i2=f*v2 ;* Transform to impulse vector
*
* Replication File for Uhlig (2005), "What are the effects of monetary policy on output?
* Results from an agnostic identification procedure." Journal of Monetary Economics, 52, pp
* 381-419. Pure sign restriction approach
*
open data uhligdata.xls
calendar 1965 1 12
data(format=xls,org=columns) 1965:01 2003:12 gdpc1 gdpdef cprindex totresns bognonbr fedfunds
*
set gdpc1 = log(gdpc1)*100.0
set gdpdef = log(gdpdef)*100.0
set cprindex = log(cprindex)*100.0
set totresns = log(totresns)*100.0
set bognonbr = log(bognonbr)*100.0
*
system(model=varmodel)
variables gdpc1 gdpdef cprindex fedfunds bognonbr totresns
lags 1 to 12
end(system)
estimate(noprint)
*
dec vect[strings] vl(6)
compute vl=||'real GDP','GDP price defl','Comm. Price Ind.','Fed Funds Rate','Nonborr. Reserv.','Total Reserves'||
*
* n1 is the number of draws from the posterior of the VAR
* n2 is the number of draws from the unit sphere for each draw for the VAR
* nvar is the number of variables
* nstep is the number of IRF steps to compute
* KMAX is the "K" value for the number of steps constrained
*
compute n1=200
compute n2=200
compute nvar=6
compute nstep=60
compute KMAX=5
*
* This is the standard setup for MC integration of an OLS VAR
*
compute sxx =%decomp(%xx)
compute svt =%decomp(inv(%nobs*%sigma))
compute betaols=%modelgetcoeffs(varmodel)
compute ncoef =%rows(sxx)
compute wishdof=%nobs-ncoef
dec rect ranc(ncoef,nvar)
*
* Most draws are going to get rejected. We allow for up to 1000
* good ones. The variable accept will count the number of accepted
* draws. GOODRESP will be a RECT(nsteps,nvar) at each accepted
* draw.
*
declare vect[rect] goodresp(1000)
declare vector ik a(nvar)
*
compute accept=0
infobox(action=define,progress,lower=1,upper=n1) 'Monte Carlo Integration'
do draws=1,n1
*
* Make a draw from the posterior for the VAR and compute its impulse
* responses.
*
compute sigmad =%ranwisharti(svt,wishdof)
compute swish =%decomp(sigmad)
compute ranc =%ran(1.0)
compute betau =sxx*ranc*tr(swish)
compute betadraw=betaols+betau
compute %modelsetcoeffs(varmodel,betadraw)
impulse(noprint,model=varmodel,decomp=swish,results=impulses,steps=nstep)
*
* Do the subdraws over the unit sphere. These give the weights on the
* orthogonal components.
*
do subdraws=1,n2
************************************************
* First Set of Restrictions - Unique Impulse Vector
************************************************
compute v1=%ran(1.0),v1=v1/sqrt(%normsqr(v1))
compute p=inv(sigmad)
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(4)<0.or.ik(6)<0.or.ik(2)>0.or.ik(5)>0
branch 105
end do k
*
* Meets the first restriction
* Draw from the orthogonal complement of i1 (last five columns of the
* factor "f").
*
@forcedfactor(force=column) sigmad i1 f
compute v2=%ran(1.0),v2=v2/sqrt(%normsqr(v2))
compute v=i2=%xsubmat(f,1,6,2,6)*v2
*****************************************************
* Second Set of Restrictions - Demand Shock
*****************************************************
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(1)<0.or.ik(2)<0
branch 105
end do k
*
* Meets both restrictions
*
compute accept=accept+1
dim goodrespa(accept)(nstep,nvar)
dim goodresp(accept)(nstep,nvar)
ewise goodresp(accept)(i,j)=(ik=%xt(impulses,i)*i1),ik(j)
ewise goodrespa(accept)(i,j)=(ik=%xt(impulses,i)*i2),ik(j)
if accept>=1000
break
:105
end do subdraws
if accept>=1000
break
infobox(current=draws)
end do draws
infobox(action=remove)
*
* Post-processing. Graph the mean of the responses along with the 16% and 84%-iles
*
clear upper lower resp
*
spgraph(vfields=3,hfields=2,hlabel='Figure 6. Impulse Responses with Pure-Sign Approach')
do i=1,nvar
compute minlower=maxupper=0.0
smpl 1 accept
do k=1,nstep
set work = goodresp(t)(k,i)
compute frac=%fractiles(work,||.16,.84||)
compute lower(k)=frac(1)
compute upper(k)=frac(2)
compute resp(k)=%avg(work)
end do k
*
smpl 1 nstep
graph(ticks,number=0,picture='##.##',header='Impulse Responses for '+vl(i)) 3
# resp
# upper / 2
# lower / 2
end do i
*
spgraph(done)
OPEN DATA fiscal.RAT
CALENDAR(q) 1980
ALL 2005:04
compute missc=1.0e+32
DATA(FORMAT=RATS,missing=missc) / GDP GOVE DEFLA CRUDE INT M1
set gdpc1 = log(gdp)*100.0
set gdpdef = log(defla)*100.0
set cprindex = log(crude)*100.0
set bognonbr = log(m1)*100.0
set eerr = log(gove)*100.0
*
system(model=varmodel)
variables gdpc1 gdpdef cprindex int bognonbr gove
lags 1 to 4
end(system)
estimate(noprint,resid=resids)
dec vect[strings] vl(6)
compute vl=||'real GDP','GDP price defl','Comm. Price Ind.',$
'Bank Rate','Money Stock M1','Real Effective Exchange Rate'||
compute n1=200
compute n2=200
compute nvar=6
compute nstep=40
compute KMAX=1
* This is the standard setup for MC integration of an OLS VAR
*
dec symm s(6,6)
dec vect v1(6) ;* For the unit vector on the 1st draw
dec vect v2(5) ;* For the unit vector on the 2nd draw
dec vect v(6) ;* Working impulse vector
compute sxx =%decomp(%xx)
compute svt =%decomp(inv(%nobs*%sigma))
compute betaols=%modelgetcoeffs(varmodel)
compute ncoef =%rows(sxx)
compute wishdof=%nobs-ncoef
dec rect ranc(ncoef,nvar)
*
* Most draws are going to get rejected. We allow for up to 1000
* good ones. The variable accept will count the number of accepted
* draws. GOODRESP will be a RECT(nsteps,nvar) at each accepted
* draw.
*
declare vect[rect] goodresp(1000)
declare vect[rect] goodrespa(1000)
declare vector ik a(nvar)
source forcedfactor.src
*
compute accept=0
infobox(action=define,progress,lower=1,upper=n1) 'Monte Carlo Integration'
do draws=1,n1
*
* Make a draw from the posterior for the VAR and compute its impulse
* responses.
*
compute sigmad =%ranwisharti(svt,wishdof)
compute p =%decomp(sigmad)
compute ranc =%ran(1.0)
compute betau =sxx*ranc*tr(p)
compute betadraw=betaols+betau
compute %modelsetcoeffs(varmodel,betadraw)
*
* This is changed to unit shocks rather than orthogonalized shocks.
*
impulse(noprint,model=varmodel,decomp=%identity(6),results=impulses,steps=nstep)
*
* Do the subdraws over the unit sphere. These give the weights on the
* orthogonal components.
*
do subdraws=1,n2
************************************************
* First Set of Restrictions - Unique Impulse Vector
************************************************
compute v1=%ran(1.0),v1=v1/sqrt(%normsqr(v1))
compute v=i1=p*v1
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(4)<0.or.ik(6)<0.or.ik(2)>0.or.ik(5)>0
branch 105
end do k
*
* Meets the first restriction
* Draw from the orthogonal complement of i1 (last five columns of the
* factor "f").
*
@forcedfactor(force=column) sigmad i1 f
compute v2=%ran(1.0),v2=v2/sqrt(%normsqr(v2))
compute v=i2=%xsubmat(f,1,6,2,6)*v2
*****************************************************
* Second Set of Restrictions - Demand Shock
*****************************************************
do k=1,KMAX+1
compute ik=%xt(impulses,k)*v
if ik(1)<0.or.ik(2)<0
branch 105
end do k
*
* Meets both restrictions
*
compute accept=accept+1
dim goodrespa(accept)(nstep,nvar)
dim goodresp(accept)(nstep,nvar)
ewise goodresp(accept)(i,j)=(ik=%xt(impulses,i)*i1),ik(j)
ewise goodrespa(accept)(i,j)=(ik=%xt(impulses,i)*i2),ik(j)
if accept>=1000
break
:105
end do subdraws
if accept>=1000
break
infobox(current=draws)
end do draws
infobox(action=remove)
*
* Post-processing. Graph the mean of the responses along with the 16% and 84%-iles
*
clear upper lower resp
*
spgraph(vfields=3,hfields=2,hlabel='Impulse Responses with Pure-Sign Approach',subhea='Italy')
do i=1,nvar
compute minlower=maxupper=0.0
smpl 1 accept
do k=1,nstep
set work = goodresp(t)(k,i)
compute frac=%fractiles(work,||.16,.84||)
compute lower(k)=frac(1)
compute upper(k)=frac(2)
compute resp(k)=%avg(work)
end do k
*
smpl 1 nstep
graph(pattern,ticks,number=0,picture='##.##',header='Impulse Responses for '+vl(i)) 3
# resp
# upper / 2
# lower / 2
end do i
*
spgraph(done) dim goodrespa(accept)(nstep,nvar)
dim goodresp(accept)(nstep,nvar)
ewise goodresp(accept)(i,j)=(ik=%xt(impulses,i)*i1),ik(j)
ewise goodrespa(accept)(i,j)=(ik=%xt(impulses,i)*i2),ik(j)dec symm s(4,4)
dec vect v(4)
compute s=%ranwishart(4,10.0)
compute p=%decomp(s)
*
* Draw an impulse vector
*
compute v=%ransphere(4)
compute i1=p*v
*
* Do a forcedfactor
*
@forcedfactor(force=column) s i1 f
*
* Draw an impulse vector from the span of the last three columns
*
compute v=%ransphere(3)
compute i2=%xsubmat(f,1,4,2,4)*v
*
* Do a forced factor with i1/i2
*
@forcedfactor(force=column) s i1~i2 f
*
* Draw an impulse vector from the span of the last two columns
*
compute v=%ransphere(2)
compute i3=%xsubmat(f,1,4,3,4)*v
*
* This will give a complete factorization of f
*
@ForcedFactor(force=column) s i1~i2~i3 fReturn to VARs (Vector Autoregression Models)
Users browsing this forum: Bing [Bot] and 0 guests