*
* @IRFRestrict( options ) r
*
* Builds up (one constraint at a time) a restriction matrix for a "B"
* form structural VAR. When done, this will have constructed matrix R so that
* the restrictions on the SVAR will take the form
*
*  (1) R vec(B) = 0
*
* Then vec(B) = R-perp x theta
*
* will represent all possible solutions to (1), where theta is a VECTOR of free
* parameters. The resulting model can be estimated using CVMODEL.
*
* Parameters:
*   R     (input and output) the matrix being constructed. If you do more than one
*         analysis of this type, either use a different matrix, or dimension to 0,0
*         before starting the second.
*
* Options: (all are required)
*   IRF=response matrix to unit impact shocks for the horizon being constrained
*   VARIABLE=variable whose response is being constrained
*   SHOCK=shock whose response is being constrained
*
* Revision Schedule
*  06/2014 Written by Tom Doan, Estima
*
procedure IRFRestrict r
type rect *r
*
option rect    irf
option integer variable
option integer shock
*
local  rect    b
*
if .not.%defined(r).or..not.%defined(variable).or..not.%defined(shock).or..not.%defined(irf) {
   disp "###@IRFRestrict(irf=response matrix,variable=constrained variable,shock=constrained shock) r"
   return
}
*
* Figure out this constraint. This is the outer product of the
* variable's row from IRF with a unit vector for the shock.
*
compute b=tr(%xrow(irf,variable))*tr(%unitv(%nvar,shock))
*
* If the matrix is currently empty, just make it the vec of the B.
* Otherwise add a row.
*
if %rows(r)==0
   compute r=%vec(b)
else
   compute r=r~%vec(b)
end
