PROCEDURE SPATWEIGHT2 Z WZ NB NE NNVEC NN

* Z = THE SERIES TO BE SPATIALLY WEIGHTED
* WZ = THE RESULTING SPATIALLY-WEIGHTED SERIES
* NB, NE = THE RANGE OF OBSERVATIONS
* NN = THE NUMBER OF NEAREST NEIGHBORS
* NNVEC = THE VECTOR IDENTIFYING THE NEAREST NEIGHBORS

TYPE SERIES Z *WZ
TYPE INTEGER NB NE NN
TYPE VECTOR[INTEGER] NNVEC
LOCAL INTEGER I J K KK

SET WZ NB NE = 0.0
COMPUTE K = 0
DO I = NB,NE
DO J = 1,NN
COMPUTE K = K+1
COMPUTE KK = NNVEC(K)
COMPUTE WZ(I) = WZ(I) + Z(KK)
END DO J
COMPUTE WZ(I) = WZ(I)/NN
END DO I
END SPATWEIGHT2
