hi,
in relation to the feature request about cross-section dependence
testing in panels I've encountered some performance bottleneck.
Here's working code given some panel variable 'u':
<hansl>
series unit = $obsmajor
N = max(unit)
#### more elegant attempt (but slow for some reason...)
rhos = zeros(N,N)
Tcomms = zeros(N,N)
loop i=1..N -q
loop j=(i+1)..N -q
smpl (unit == i || unit == j) --restrict --replace
smpl pxnobs(u) == 2 --restrict # both units have values there
matrix uij = { u } # hope it's stacked, so that upper half is unit i
Tcomms[i,j] = rows(uij) / 2
rhos[i,j] = corr( uij[1: Tcomms[i,j]], uij[Tcomms[i,j] + 1 : ] )
endloop
endloop
# Pesaran's CD (unbalanced)
scalar CD = sqrt( 2 / (N*(N-1)) ) * sum( sqrt(Tcomms) .* rhos )
</hansl>
This takes quite long to run (several seconds for datasets like
abdata.gdt). I've had a less elegant implementation before with more
code and more copying to temporary matrices and so on (including the
nested loop) which was much faster.
I'm wondering whether perhaps the sample restriction with the pxnobs()
function is slow.
thanks,
sven