Page 1 of 1

Orthogonal Shocks Sign Restrictions

Posted: Wed Aug 09, 2017 5:54 am
by Jules89
Dear Tom,

I am working on the Mountfort Uhlig (2009) code which is doing the sign restrictions on multiple shocks where the first two are constructed to be orthogonal:

Code: Select all

*
* Replication file for Mountford and Uhlig (2009), "What are the Effects
* of Fiscal Policy Shocks?", Journal of Applied Econometrics.
*
* Experiment with sign restrictions rather than penalty functions
*
* nkeep is the desired number of accepted draws
*
compute nkeep=250
compute n1   =500
compute n2   =1000
*
* Pull in common setup
*
source mujaesetup.src
********************************************************************************
*
* Range of steps to constrain. Note - these are based at 1, not 0.
*
compute KMIN  =1
compute KMAX  =4
*
* Parameter vectors for the nested optimization problems. They should
* have a size equal to nvar less 1 + the number of constraints imposed
* prior to their estimation. Those prior constraints can be
* orthogonality to previous shocks, or can be zero restrictions.
*
compute nshocks=4
dec vect[strings] sl(nshocks)
compute sl=||"Business Cycle","Monetary Policy","Revenue","Spending"||
*
*******************************************************************************
declare vector ik a(nvar) ones(nvar)
compute ones=%const(1.0)
source forcedfactor.src
*
infobox(action=define,progress,lower=1,upper=n1) "Monte Carlo Integration"
compute accept=0
do draw=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 betadraw=betaols+%ranmvkron(p,sxx)
   compute %modelsetcoeffs(varmodel,betadraw)
   *
   impulse(noprint,model=varmodel,factor=p,results=impulses,steps=nstep)
   gset irfsquared 1 1     = %xt(impulses,t).^2
   gset irfsquared 2 nstep = irfsquared{1}+%xt(impulses,t).^2
   do subdraw=1,n2
      ************************************************
      * First in Order - Business Cycle Vector
      ************************************************
      compute [vector] v1=%ransphere(nvar)
      if UhligAccept(v1,KMIN,KMAX,||+1,+3,+8,+9||)==0
         goto reject
      compute i1=p*v1
      *
      * Compute a factor with i1 forced as the first column.
      * Transform the orthogonal complement (remaining columns) back into weights on
      * the Choleski factor.
      *
      @forcedfactor(force=column) sigmad i1 f
      compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)
      *****************************************************
      *  Second in Order - Monetary Shock
      *****************************************************
      compute [vector] v2=r2*%ransphere(nvar-1)
      if UhligAccept(v2,KMIN,KMAX,||+4,-5,-6,-7||)==0
         goto reject
      compute i2=p*v2
      *
      * Compute a factor with i1~i2 forced as the first two columns.
      * Transform the orthogonal complement (remaining columns) back into weights on
      * the Choleski factor.
      *
      @forcedfactor(force=column) sigmad i1~i2 f
      compute r3=inv(p)*%xsubmat(f,1,nvar,3,nvar)
      *****************************************************
      *  Third in Order - Govt Revenue Shock (no delay)
      *****************************************************
      *
      * Draw from the orthogonal complement of i1 and i2 (final nvar-2 columns
      * in the factor).
      *
      compute [vector] v3c=r3*%ransphere(nvar-2)
      if UhligAccept(v3c,KMIN,KMAX,||+3||)==0
         goto reject
      compute i3c=p*v3c
      *****************************************************
      *  Third in Order - Govt Spending Shock (no delay)
      *****************************************************

      compute [vector] v3e=r3*%ransphere(nvar-2)
      if UhligAccept(v3e,KMIN,KMAX,||+2||)==0
         goto reject
      compute i3e=p*v3e
      *
      * Meets all restrictions
      *
      compute accept=accept+1
      dim %%responses(accept)(nshocks*nvar,nstep)
      *
      * Save the desired sets of linear combinations of the Choleski
      * responses
      *
      compute vweights=v1~v2~v3c~v3e
      ewise %%responses(accept)(i,j)=(ik=%vec(%xt(impulses,j)*vweights)),ik(i)
      if accept>=nkeep
         break
   :reject
   end do subdraw
   if accept>=nkeep
      break
   infobox(current=draw)
   :newdraw
end do draw
infobox(action=remove)
disp "Acceptances" accept "on" draw "main draws"
*
@MCGraphIRF(model=varmodel,varlabels=vl,shocklabels=sl,$
  page=byshock,center=median,columns=2,include=||1,2,10,4,6,8,3,9,5,7||)
******************************************************************************
*
* Combination shocks
*
* Spending = variable 2, revenue = variable 3
* Revenue = shock 3, Spending = shock 4
*
compute [vect[integer]] xvars=||2,3||
compute [vect[integer]] xshocks=||3,4||
dec rect xsolve(2,2)
dec rect xrespy(nvar,2)
dec vect yresp(nvar)
*
* Target values for spending,revenue for the combination shocks
*
dec vect[vect] experiments(3)
compute experiments(1)=||1.0,0.0||
compute experiments(2)=||0.0,-1.0||
compute experiments(3)=||1.0,1.0||
compute [vect[strings]] cl=||"Deficit Spending","Deficit Tax Cut","Balanced Budget"||
*
dec vect[vect] target(KMAX)
dec vect[rect] %%combos
dim %%combos(nkeep)
*
do draw=1,nkeep
   compute %%combos(draw)=%zeros(%rows(experiments)*nvar,nstep)
   do k=1,%rows(experiments)
      *
      * Copy the target values for each step being constrained.
      *
      do s=1,KMAX
         compute target(s)=experiments(k)
      end do s
      *
      do s=1,KMAX
      	*
         * Compute the shock needed at step <<s>> to hit the remainder.
         * This is always computed using the impact multipliers.
         *
         compute xresp=%reshape(%xcol(%%responses(draw),1),nvar,nshocks)
         ewise xsolve(i,j)=xresp(xvars(i),xshocks(j))
         compute needed=%solve(xsolve,target(s))
         *
         * Propagate that shock through to the responses being
         * constructed. Since this is a shock at step <<s>>, the
         * response to it at step <<u>> is computed using the IRF at
         * u-s+1.
         *
         do u=s,nstep
            compute xresp=%reshape(%xcol(%%responses(draw),u-s+1),nvar,nshocks)
            *
            * Pull out the responses of all variables to the two shocks
            * being combined. Take the linear combination of these that
            * we just computed. Add it to the running sums.
            *
            ewise xrespy(i,j)=xresp(i,xshocks(j))
            compute yresp=xrespy*needed
            do i=1,nvar
               compute %%combos(draw)(i+(k-1)*nvar,u)+=yresp(i)
            end do i
            *
            * If u is inside of the number of steps being constrained,
            * update the target by subtracting off the response to the
            * shock we just computed.
            *
            if u<=KMAX {
            	ewise xsolve(i,j)=xresp(xvars(i),xshocks(j))
               compute target(u)=target(u)-xsolve*needed
 				}
         end do u
      end do s
   end do k
end do draw
*
* Copy the information generated into %%responses so we can use MCGraphIRF
*
compute %%responses=%%combos
@MCGraphIRF(model=varmodel,varlabels=vl,shocklabels=cl,$
  page=byshock,center=median,columns=2,include=||1,2,10,4,6,8,3,9,5,7||)


The question is reagrding the use of the @forcedfactor procedure.

Code: Select all

"@forcedfactor(force=column) sigmad i1 f"
It takes the Cholesky decomposition of the covariance matrix, sigmad, and factorizes it such that "i1" is the first column and the resulting matrix "f" fulfills ff'=sigmad.
What I dont get is what
"

Code: Select all

compute r2=inv(p)*%xsubmat(f,1,nvar,2,nvar)
"
does.
In the VAR workbook something like "we
need to back transform draws, thus the complete process.." is written, but I dont understand what that means.

Best Jules

Re: Orthogonal Shocks Sign Restrictions

Posted: Wed Aug 09, 2017 7:46 am
by TomDoan
Read the whole sentence: "In order to use UhligAccept or UhligPenalty, we need to back-transform draws (since the inputs to those are weights on the Cholesky factor P)". It's specifically in order to use those two functions to test the sign-restrictions on the draw.