[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: Matrix manipulation help

From   "Nick Cox" <>
To   <>
Subject   st: RE: RE: Matrix manipulation help
Date   Wed, 13 May 2009 19:27:48 +0100

-nearest- on SSC has relevant (pre-Mata) code. 

I thought Michael Blasnik had written something more efficient but I
can't find it or -findit- quickly. 


Nick Cox

By the way, hasn't this been done before? 


Susan Olivia

Can I get programming advice how to create a NxN distance
matrix using the information on latitude and longitude. 

Below is what I attempted to do in STATA, but it didn't
work. Would be great if I can get any advice on how to
improve this code. 

qui set obs 1000

gen xcoord = uniform()*100
gen ycoord = uniform()*100

mkmat xcoord ycoord 

local N=_N
scalar N = _N

matrix latlong= xcoord,ycoord

matrix D = J(`N',`N', 0)

* looping through the rows and columns of the matrix D, to
get distance pair for each observations 

  for(i = 1; i <=N; i++) {
       for(j = 1; j<=N; j++) {
            if (i!=j){

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index