*
* @BVarBuildPrior(options)  hbprior hprior
* builds a prior for an equation in a BVAR one element at a time. Each
* element is independent of the others and Normally distributed.
*
* Parameters (required)
*   HBPRIOR    accumulation of precision matrix x prior mean vectors for
*              the elements of the prior
*   HPRIOR     accumulation of the precision matrices for the element of
*              the prior
*
* Options:
*   EQUATION=equation defining the form of the estimated equation
*   INIT/[NOINIT] initialize (dimension and zero) the hbprior and hprior
*
*   STDDEV=prior standard deviation for coefficient [1 if V isn't used]
*   V=prior variance
*     One of these two is used to set the variance of the prior
*
*   POSITION=coefficient position
*   MEAN=prior mean for coefficient [0]
*     These two (plus one of the above) handle the standard priors on
*     individual coefficients.
*
*   X=x vector for dummy observation
*   Y=y value for dummy observation
*     These handle "dummy observation" priors - ones of the form y=Xb+e
*
*  Revision Schedule:
*   05/2009 Written by Tom Doan, Estima
*
procedure BVarBuildPrior hbprior hprior
type vector *hbprior
type symm   *hprior
*
option equation equation
option switch   init
*
option real     y
option vector   x
option real     v
*
option integer  position
option real     mean       0.0
option real     stddev     1.0
*
local  real     vscale
local  integer  ncoef
*
if init {
   compute ncoef=%eqnsize(equation)
   compute hbprior=%zeros(ncoef,1)
   compute hprior =%zeros(ncoef,ncoef)
   return
}
if %defined(v)
   compute vscale=1.0/v
else
   compute vscale=1.0/stddev^2

if %defined(position) {
   compute hprior(position,position)+=vscale
   compute hbprior(position)+=mean*vscale
}
else {
   if %defined(y)
      compute hbprior=hbprior+vscale*x*y
   else
      compute hbprior=hbprior+vscale*x*tr(x)*%ginv(hprior)*hbprior
   compute hprior=hprior+vscale*x*tr(x)
   }
end

