*
*  @MIXVAR( options )  depvar  start  end  resids
*  #  list of other endogenous variables
*  #  list of deterministic variables (if MORE option)
*
*  MIXVAR computes estimates for a single equation using the mixed estimation
*  procedure used by the RATS command ESTIMATE.  It can be helpful in dealing
*  with the following situations:
*
*     1. You have a variable you wish to forecast which does not fit into
*        a full-blown VAR, since it has no predictive content for the
*        other variables.
*     2. You have a limited amount of data for one variable, so you need to
*        use fewer coefficients in that equation than in others.
*
*  Parameters:
*     depvar         Dependent variable
*     start end      Estimation range [maximum possible]
*     resids         (optional) Series for residuals
*
*  Options:
*     NUMLAGS=number of lags (for all variables) [1]
*     TIGHT=tightness [.2]
*
*     LAGTYPE=[HARMONIC]/GEOMETRIC
*     DECAY=parameter of lag decay
*         These are identical to the options on SPECIFY
*     OTHER="weight" on other variables [1.0]
*         This is the symmetric prior weight
*     ZEROLAG/[NOZEROLAG]
*         If ZEROLAG, the other variables are put in with lags 0 to
*         NUMLAGS-1
*     DEFINE=equation to define
*     MORE/[NOMORE]
*        Use MORE and an extra supplementary card if you want
*        deterministic variables other than CONSTANT.
*
*   MIXVAR was written by Tom Doan and Craig Burnside
*   Revision Schedule:
*      February, 1992 - Updated to Version 4.0
*
*
procedure mixvar series start end resids
type series  series *resids
type integer start   end
*
option integer  numlags  1
option real     tight    .20
option switch   zerolag  0
option choice   lagtype  1 harmonic geometric
option choice   type     1 symmetric general
option real     decay    0.0
option real     other    1.0
option equation *define
option switch   more    0
*
*   VARS     = List of Other Endogenous Variables
*              Entered from Supplementary Card
*   DETRMVAR = List of "deterministic" variables
*   BUILDSUP = Built-up supplementary card
*
local index vars buildsup detrmvar
local integer sl el bl i j depvar indepvar numvar diagel
local vector ster lagdecay reltight
local real stdep decayval ownadd
*
*  Enter first supplementary card
*
enter(varying,entries=numvar) vars
dim reltight(numvar)
if type==2
  enter reltight
else
  ewise reltight(i)=other
*
dim ster(numvar) lagdecay(numlags)
*
*  Enter second supplementary card, if necessary
*
if more
  enter(varying) detrmvar
else
  compute detrmvar=||constant||
*
*  Set up lag decay vector
*
if lagtype==1
   ewise lagdecay(i)=i**(-decay)
else {
   compute decayval=%if(decay<=0,1.0,decay)
   ewise lagdecay(i)=decayval**i
   }

if zerolag
   compute sl=0 , el = numlags-1 , bl = numlags
else
   compute sl=1 , el = numlags   , bl = numlags+1

enter(varying) buildsup
# series{0 to numlags}
do i=1,numvar
   enter(varying) buildsup
   # buildsup vars(i){0 to el}
end do i
cmom(noprint) start end
#  buildsup  detrmvar
*
linreg(cmom,noprint) series
# detrmvar series{1 to numlags}
compute stdep=sqrt(%seesq*%ndf/%nobs)
do indepvar=1,numvar
   compute depvar=vars(indepvar)
   linreg(cmom,noprint) depvar
   # detrmvar depvar{1 to el}
   compute ster(indepvar)=sqrt(%seesq*%ndf/%nobs)
end do indepvar
*
compute ownadd=stdep/tight
*
do i=1,numvar
  compute diagel=(i-1)*bl+numlags+2-zerolag
  do j=1,numlags
     compute %cmom(diagel+j,diagel+j)=%cmom(diagel+j,diagel+j)+$
       (ster(i)/(tight*reltight(i)*lagdecay(j)))**2
  end do j
end do i
*
do j=1,numlags
   compute %cmom(1+j,1+j)=%cmom(1+j,1+j)+(ownadd/lagdecay(j))**2
end do j
compute %cmom(2,1)=%cmom(2,1)+ownadd**2
*
enter(varying) buildsup
# series{1 to numlags}
do i=1,numvar
   enter(varying) buildsup
   # buildsup vars(i){sl to el}
end do i
*
linreg(cmom,define=define) series / resids
# buildsup  detrmvar
end


