Sign Restriction VAR

Questions and discussions on Vector Autoregressions
tophukg
Posts: 5
Joined: Fri Mar 28, 2014 5:54 am

Sign Restriction VAR

Unread post by tophukg »

Hello All,
I try to run sign restriction VAR model for my contry. In J.P. Jääskelä, D. Jennings (2011), they have "VAR sign restrictions."
Image
Folowing them, with shock to domestic demand (the 4th shock), i write

Code: Select all

 
do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v
         if ik(1)>0.or.ik(1)<0.or.ik(2)>0.or.ik(2)<0.or.ik(3)>0.or.ik(3)<0.or.ik(4)<0.or.ik(5)>0.or.ik(6)>0
           goto reject
end do k
Is that right ? I try to set no effect on foreign variables when a domestic shock happens.
Thanks for any help.
Best regard.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Sign Restriction VAR

Unread post by TomDoan »

You can't do zero restrictions by trial and error. See

http://www.estima.com/newslett/March2009RATSLetter.pdf
tophukg
Posts: 5
Joined: Fri Mar 28, 2014 5:54 am

Re: Sign Restriction VAR

Unread post by tophukg »

Thanks for your reply.
I don't understand clearly this letter.
Can I write like this for the 4th shock ?

Code: Select all

      @forcedfactor(force=column) sigmad i1~i2~i3 f
      compute v4=%ran(1.0)
      compute v4(1) = 0.0          ;*Zero the 1st effect
      compute v4(2) = 0.0          ;*Zero the 2nd effect
      compute v4(3) = 0.0          ;*Zero the 3rd effect
      compute v4=v4/sqrt(%normsqr(v4))
      compute v=i4=%xsubmat(f,1,7,4,7)*v4
      *****************************************************
      *  Fourth Set of Restrictions - Demand
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v
         if ik(4)<0.or.ik(5)<0.or.ik(5)<0
            branch 105
      end do k
Thanks.
tophukg
Posts: 5
Joined: Fri Mar 28, 2014 5:54 am

Re: Sign Restriction VAR

Unread post by tophukg »

Dear Tom,
After reading your link and as i understand, I try to rewrite my code.
But, I have a problem with 6 shocks, when i run RATs with 5 shocks, i works well. But with 6 shocks, it doesn't run and i receive a mess :
"## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points
The Error Occurred At Location 168, Line 6 of loop/block"
I tried with n2 = 100000, n1 = 100000 and it took 18 hours to run but nothing happened, and i received this mess again . I don't know how to solve.
Can you help me ?
I set domestic shocks with zero constrains at first ( if the first set is the foreign shock , the domestic shocks(6th) will don't have enough m-space (is that right ?))
Here is my code and the data is generated by a DSGE mode, so don't mind the date of data.
This is the first time i use RATS, I might make some mistake.
If I could have your instruction or checking, I will be very grateful.
Thanks a lot.

Code: Select all

OPEN DATA "Sign6.xls"
CALENDAR(D) 2000:1:1
DATA(FORMAT=XLS,ORG=COLUMNS,COMPACT=AVERAGE) 2000:01:03 2002:09:26 DYS PIS RS DY PI R DE
*
system(model=varmodel)
variables DYS PIS RS DY PI R DE
lags 1 to 4
deterministic constant
end(system)
estimate(noprint)
dec vect[strings] vl(7)
compute vl=||'Gap US','CPI US','Interest Rate us',$
     'GAP vn','cpi vn','Interest Rate vn','Real Effective Exchange Rate'||
compute n1=100000
compute n2=100000
compute nkeep=1000
compute nvar=7
compute nstep=60
compute KMAX=1
* This is the standard setup for MC integration of an OLS VAR
*
dec symm s(7,7)
dec vect v1(7)      ;* For the unit vector on the 1st draw
dec vect v2(6)      ;* For the unit vector on the 2nd draw
dec vect v3(5)       ;*For the unit vector on the 3rd draw
dec vect v4(4)      ;* For the unit vector on the 4th draw
dec vect v5(3)      ;* For the unit vector on the 5th draw
dec vect v6(2)       ;*For the unit vector on the 6th draw
dec vect v(7)     ;* 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 vect[rect] goodrespb(1000)
declare vect[rect] goodrespc(1000)
declare vect[rect] goodrespd(1000)
declare vect[rect] goodrespe(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(7),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 - Domestic Demand
   ************************************************
      compute v1=%zeros(3,1)~~%ransphere(nvar-3)
      compute i1=p*v1
      do k=1,KMAX+1
          compute ik=%xt(impulses,k)*v1
          if ik(4)<0.or.ik(5)<0.or.ik(6)<0
             branch 105
      end do k
      *
      *
      @forcedfactor(force=column) sigmad i1 f
      compute v2=%zeros(3,1)~~%ransphere(nvar-4)
      compute i2=%xsubmat(f,1,7,2,7)*v2
      compute v2=inv(p)*i2
      *****************************************************
      *  Second Set of Restrictions - Domestic productivity
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v2
         if ik(4)<0.or.ik(5)>0.or.ik(6)>0
            branch 105
      end do k
      *
      *
      @forcedfactor(force=column) sigmad i1~i2 f
      compute v3=%zeros(3,1)~~%ransphere(nvar-5)
      compute i3=%xsubmat(f,1,7,3,7)*v3
      compute v3=inv(p)*i3
      *****************************************************
      *  Third Set of Restrictions - Domestic monetary policy
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v3
         if ik(4)>0.or.ik(5)>0.or.ik(6)<0
           branch 105
      end do k
      *
      *
      @forcedfactor(force=column) sigmad i1~i2~i3 f
      compute v4=%ransphere(nvar-3)
      compute i4=%xsubmat(f,1,7,4,7)*v4
      compute v4=inv(p)*i4
      *****************************************************
      *  Fourth Set of Restrictions - Foreign Demand
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v4
         if ik(1)<0.or.ik(2)<0.or.ik(3)<0
            branch 105
      end do k
      *
      *
      @forcedfactor(force=column) sigmad i1~i2~i3~i4 f
      compute v5=%ransphere(nvar-4)
      compute i5=%xsubmat(f,1,7,5,7)*v5
      compute v5=inv(p)*i5
      *****************************************************
      *  Fifth Set of Restrictions - Foreign Productivity
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v5
         if ik(1)<0.or.ik(2)>0.or.ik(3)>0
            branch 105
      end do k
      *
      *
      @forcedfactor(force=column) sigmad i1~i2~i3~i4~i5 f
      compute v6=%ransphere(nvar-5)
      compute i6=%xsubmat(f,1,7,6,7)*v6
      compute v6=inv(p)*i6
      *****************************************************
      *  Sixth Set of Restrictions - Foreign Monetary policy
      *****************************************************
      do k=1,KMAX+1
         compute ik=%xt(impulses,k)*v
         if ik(1)>0.or.ik(2)>0.or.ik(3)<0
            branch 105
      end do k
      *
      * Meets all restrictions
      *
      compute accept=accept+1
      dim goodresp(accept)(nstep,nvar)
      dim goodrespa(accept)(nstep,nvar)
      dim goodrespb(accept)(nstep,nvar)
      dim goodrespc(accept)(nstep,nvar)
      dim goodrespd(accept)(nstep,nvar)
      dim goodrespe(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)
      ewise goodrespb(accept)(i,j)=(ik=%xt(impulses,i)*i3),ik(j)
      ewise goodrespc(accept)(i,j)=(ik=%xt(impulses,i)*i4),ik(j)
      ewise goodrespd(accept)(i,j)=(ik=%xt(impulses,i)*i5),ik(j)
      ewise goodrespe(accept)(i,j)=(ik=%xt(impulses,i)*i6),ik(j)
      if accept>=nkeep
         break
   :105
   end do subdraws
   if accept>=nkeep
      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=3,hlabel='Impulse Responses with Pure-Sign Approach',subhea='VN')
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)

Attachments
Code.RPF
(6.76 KiB) Downloaded 959 times
Sign6.xls
(182.5 KiB) Downloaded 656 times
Post Reply