*
* @Corrado(options)  r
* Computes the non-parametric test statistic from Corrado (1989), "A non
* Parametric Test for Abnormal Security-Price Performance in Event Studies.
* Journal of Financial Economics, vol 23, pp 385-395.
*
* Parameters:
*  r    number of periods x number of securities matrix of abnormal returns
*
* Options:
*  EVENT=row for the event time [1]
*
* Variables Defined:
*  %CDSTAT test statistic
*  %SIGNIF two-tailed Normal significance level.
*
* Revision Schedule:
*  03/2008 Written by Tom Doan, Estima.
*
proc Corrado r
type rect r
option integer event 1
*
local rect ranks
local integer i
local vector crossdiffs
local real vsq
*
* Create a matrix with the ranks (from smallest=1) of the abnormal returns for
* each security in each column.
*
dim ranks(%rows(r),%cols(r))
*
do i=1,%cols(r)
   compute %psubmat(ranks,1,i,%ranks(%xcol(r,i)))
end do i
*
* Compute the average across securities of the excess rank at each time period.
*
compute crossdiffs=ranks*%fill(%cols(r),1,1.0/%cols(r))-.5*(%rows(r)+1)
*
* Compute the estimate of the variance from that.
*
compute vsq=%dot(crossdiffs,crossdiffs)/%rows(r)
*
* Create the test statistic from the average excess rank at the event time.
*
compute %cdstat=crossdiffs(event)/sqrt(vsq)
compute %signif=%ztest(%cdstat)
end



