@ Written by Stephen G. Donald, Department of Economics, University of Texas at Austin.
If you use this procedure please cite Cragg and Donald (1997) Journal of Econometrics
and Cragg and Donald (1993) Econometric Theory. Both papers provide more details on
the rank tests computed in this proc. Note that if it fails to converge in 50 iterations
try and rearrange the columns of the matrix (and its variance matrix) and try again. The test
is invariant to this but the algorithm may work better. If you have any questions pleas contact
Stephen Donald
@
@ This procedure takes an estimated matrix, PIHAT and the variance covariance matrix
of vec(PIHAT), say OMEGA and computes the Cragg Donald test statistic for a given null
rank of L
Note that PIHAT must have dimension K by G with K>=G.
Therefore OMEGA is of dimension KG by KG.
It must be the case that L=G; PRINT "This will crash because you cannot test that the
rank is larger or equal to the number of columns";ENDIF;
@ This program iterates by letting the last G-L columns of PI be
linearly dependent on the first L columns. Using this parameterization
the program then uses Newton Raphson iterations to obtain the solution @
@ There are two possible ways to initialize V, which is the matrix
that imposes the constraint that PI2 = PI1* V, where PI2 are the
last G-L columns and PI1 are the first L columns. The first is based
on using the sample values based on the first L rows. The second
which is the current one, sets V equal to zero. If one does not result in
convergence then the other should be tried. @
L~G;
V=INV(PIHAT[1:L,1:L])*PIHAT[1:L,L+1:G];
V=ZEROS(L,G-L);
FREE=K*L+L*(G-L); @number of free parameters @
THETA0=ZEROS(FREE,1);THETA1=ZEROS(FREE,1); @ free parameters @
P1=PIHAT[.,1:L];
OMINV=PINV(OMEGA);
D=ZEROS(G*K,FREE); @ will contain the first derivative matrix @
COUNT=0;
FL=1;
DO UNTIL FL==0;
THETA0[1:K*L,1]=VEC(P1); @ initialize theta0 @
THETA0[K*L+1:FREE,1]=VEC(V);
D[K*L+1:K*G,K*L+1:FREE]=EYE(G-L).*.P1;
D[1:K*L,1:K*L]=EYE(K*L);
D[K*L+1:K*G,1:K*L]=V'.*.EYE(K);
PITIL[.,1:L]=P1;
PITIL[.,L+1:G]=P1*V;
THETA1=THETA0+INV(D'OMINV*D)*D'OMINV*(VEC(PIHAT)-VEC(PITIL));
I=0;
DO UNTIL I==L;
I=I+1;
P1[.,I]=THETA1[(I-1)*K+1:I*K,1];
ENDO;
I=0;
DO UNTIL I==G-L;
I=I+1;
V[.,I]=THETA1[K*L+(I-1)*L+1:K*L+I*L,1];
ENDO;
C1=(THETA1-THETA0)'(THETA1-THETA0);
C2=(VEC(PIHAT)-VEC(PITIL))'OMINV*D*D'*OMINV*(VEC(PIHAT)-VEC(PITIL));
C3=VEC(PIHAT-PITIL)'OMINV*VEC(PIHAT-PITIL);
IF abs(C1)NIT;FL=0;
PRINT "MAXIMAL ITERATIONS REACHED WITHOUT CONVERGENCE. YOU SHOULD
EITHER INCREASE THE MAXIMAL NO. OF ITERATIONS OR TRY PERMUTING THE
COLUMNS OF THE MATRIX (AND ITS COVARIANCE MATRIX) OR TRY A DIFFERENT
STANDARDIZATION FOR THE MATRIX TO IMPROVE NUMERIC STABILITY";
ENDIF;
THETA0=THETA1;
ENDO;
@
PRINT "No of iterations:" COUNT;
PRINT C1 C3;
@
if count==51;c3=0;endif;
retp(C3);
ENDP;
@ You should insert code here that will compute the matrices -- using
n observations (referred to as T in the proc)
pim -- K by G
varp=variance(vec(pim)) -- KG by KG
-- note that if varp is of the form a .*. b then the calculations are much
simpler -- see Cragg and Donald (1993, Econometric Theory)
The procedure will return a test statistic for testing the null
that rank(pim)<=r