*
* This implements the calculation of a ergodic variance of a
* state space model using the diagonalization methods described
* in
*
* Soren Johansen, "A Small Sample Correction for the Test of
* Cointegrating Rank in the Vector Autoregressive Model",
* Econometrica, September 2002.
*
* This is more efficient than the direct solution of the linear
* system used in the RATS function %PSDINIT when there are 6 or more
* states, with the advantage becoming quite noticeable when there are
* 15 or more. (%PSDINIT needs to solve an n(n+1)/2 x n(n+1)/2 system
* of linear equations which gives an operation count on the order of n**6,
* while the eigenvalue method is order n**3).
*
* Syntax
*
* %PSDINITCX(A,SW) returning a symmetric
*
* Revision Schedule:
*   07/2004 Written by Tom Doan, Estima.
*
function %psdinitcx a sw
type symmetric %psdinitcx
type rect a
type symm sw
*
local integer i j n
local rect[complex] ceigvect swc sxc cxpsd
local vect[complex] ceigval
*
compute n=%rows(a)
if %cols(a)<>%rows(a).or.%cols(a)<>%rows(sw) {
   disp '%PSDINITCX(A,SW) needs A and SW to be NxN'
   return
}
eigen(cvectors=ceigvect,cvalues=ceigval) a
compute swc=%cxinv(ceigvect)*sw*%cxadj(%cxinv(ceigvect))
dim sxc(n,n) %psdinitcx(n,n)
ewise sxc(i,j)=swc(i,j)/(1-ceigval(i)*ceigval(j))
compute cxpsd=ceigvect*sxc*%cxadj(ceigvect)
ewise %psdinitcx(i,j)=%real(cxpsd(i,j))
end

