Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Compute distance to all observations in a group


From   Fernando Luco <[email protected]>
To   [email protected]
Subject   st: Compute distance to all observations in a group
Date   Sat, 25 Feb 2012 09:26:02 -0600

Dear all,

I have a data set with the coordinates of all stores in a country,
grouped at the county level. I need to compute the distance from one
store to all other stores in the same county. In particular, I'm
interested in computing, for each store, the distance to the nearest
store, the second one, the third and so on. So far, I haven't been
able to do so.
The number of stores varies by county. The data looks like this

County Store  latitude         longitude
1            1	  -18.47785	-70.31808
1	      2  -18.47846	-70.31757
1	      3  -18.48126	-70.31446
2            1  -20.24057        -70.14498
2            2  -20.23462        -70.14281
2            3  -20.21667        -70.14654
2            4  -20.25699        -70.1329
3            1  -23.67862        -70.40953
3            2  -23.5791          -70.39053

Because of what I need to do after getting the distances, I would like
the data to look as follows

County Store latitude longitude distance_to_nearest_store
distance_to_second_nearest store ...distance_to_nth_nearest_store.

Any ideas on how to do this?

Thanks,

Fernando
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index