*
*   COINTPO.SRC
*   Multivariate Trace Statistic for Cointegration
*   Phillips and Ouliaris (1990)
*
*   Revision Schedule:
*     06/91 Written by Paco Goerlich
*     07/93 Revised by Paco Goerlich for RATS v 4
*     01/94 Documentation added and some code changed by Tom Doan
*
*   @COINTPO  start  end
*   # list of variables in VAR
*
*   Options:
*     REGRESS=TREND/CONSTANT/[NONE] Include constant+trend,constant or none
*     N1WINDOW=Minimum window width considered[0]
*     N2WINDOW=Maximum window width considered[4]
*     PRINT/[NOPRINT]
*
PROC COINTPO TBEGP TENDP
*
LOCAL INTEGER       NVAR    RES   I TBEG TEND
LOCAL REAL          PZ
LOCAL SERIES        TIME
LOCAL VECT[INTEGER] VARLIST DETLIST
LOCAL SYMM          ZZ
LOCAL RECT          Y1 X1   EIGENZZ
LOCAL VECTOR        LAMBDA
LOCAL VECT[SERIES]  RESLIST
*
OPTION CHOICE  REGRESS  3 TREND CONSTANT NONE
OPTION INTEGER N1WINDOW 0
OPTION INTEGER N2WINDOW 4
OPTION SWITCH  PRINT    0
*
ENTER(VARYING,ENTRIES=NVAR) VARLIST
INQUIRE(REGRESSORLIST) TBEG>>TBEGP  TEND>>TENDP
# VARLIST

MAKE Y1 TBEG TEND
# VARLIST
DIM ZZ(NVAR,NVAR) RESLIST(NVAR)

DIS 'COINTPO procedure. Written by Paco Goerlich'
DIS 'MULTIVARIATE TRACE STATISTIC - PHILLIPS & OUILARIS (1990)'
DIS 'SERIES: ' %LABEL([SERIES]VARLIST(1)) @19 'FROM' %DATELABEL(TBEG) 'TO'  $
                                                     %DATELABEL(TEND)
DO I = 2,NVAR
   DIS @9 %LABEL([SERIES]VARLIST(I))
END DO I
*
IF REGRESS==1
   {
   DIS 'Includes Constant and a Linear Trend'
   SET TIME TBEG TEND = T-TBEG
   COMPUTE DETLIST=||CONSTANT,TIME||
   }
ELSE IF REGRESS==2
   {
   DIS 'Includes a Constant'
   COMPUTE DETLIST=||CONSTANT||
   }

IF REGRESS==3
   {
   DIS 'Includes No Deterministic Components'
   COMPUTE ZZ = TR(Y1)*Y1
   DIM DETLIST(0)
   }
ELSE
   {
   MAKE X1 TBEG TEND
   # DETLIST
   MAT ZZ = TR(Y1)*Y1 - (TR(Y1)*X1)*(INV(TR(X1)*X1)*(TR(X1)*Y1))
   }

SYSTEM    1 TO NVAR
VARIABLES VARLIST
DETERMINI DETLIST
LAGS      1
END(SYSTEM)

ESTIMATE(PRINT=PRINT,NOFTEST) TBEG+1 TEND RESLIST(1)

DIS
DO I = N1WINDOW,N2WINDOW
   MCOV(LAGS=I,DAMP=1) TBEG+1 TEND *
   # RESLIST
   COM PZ = %NOBS*%TRACE(%CMOM*INV(ZZ))
   DIS @5 'WINDOW SIZE =' ## I @+3 'PZ =' ###.#### PZ
END DO I
DIS
DIS 'ORTHOGONAL LEAST SQUARES ESTIMATION'
DIS
EIGEN ZZ LAMBDA EIGENZZ
DIS 'SMALLEST EIGENVALUE:' LAMBDA(NVAR)
DIS
DIS ' LABEL    VAR   COEFFICIENT    NORMALIZING TO' %LABEL([SERIES]VARLIST(1))
DIS '********  ***  *************  ***************************'
DO I = 1,NVAR
   DIS %LABEL([SERIES]VARLIST(I)) @11 VARLIST(I)   $
                      EIGENZZ(I,NVAR)  @30 EIGENZZ(I,NVAR)/EIGENZZ(1,NVAR)
END DO I
DIS
END PROC COINTPO

