On Thu, 24 Apr 2008, Allin Cottrell wrote:
On Thu, 24 Apr 2008, Franck Nadaud wrote:
See if this does what you're looking for:
<script>
matrix xc = X_COORD
matrix yc = Y_COORD
scalar n = rows(xc)
scalar m = 4
matrix nnlist = zeros(n,m)
matrix idx = transp(seq(1,n))
scalar xi, yi
loop i = 1..n --quiet
xi = xc[$i,1]
yi = yc[$i,1]
dist = sqrt((xc-xi).^2 + (yc - yi).^2) ~ idx
xind = msortby(dist,1)
nnlist[i,] = transp(xind[2:m+1,2])
end loop
print nnlist
</script>
Doh! I'd forgotten about msortby! Either gretl it's getting too big or I'm
getting too old! Or perhaps both :-)
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti