Bookmark and Share

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

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

st: RE: SPHDIST, creating pairs

From   "Nick Cox" <>
To   <>
Subject   st: RE: SPHDIST, creating pairs
Date   Thu, 25 Feb 2010 21:35:14 -0000

It would not be surprising that you have had problems trying to install
-vicenty- as it does not exist. -vincenty- is what you seek. I know no
reason to doubt the availability (it's there on SSC) or utility or
correctness of that program. It is hardly discreet to question any of
those in public without evident grounds. 

I have not looked at either program carefully and in any case would be
reluctant to judge on their relative merits. Asking people to make such
judgements in public may or may not elicit responses. I think most
people prefer just to comment on solutions they know to be good. 


Tomeka Davis

I am trying to calculate distance between two points using longitude and
latitude data.  I have come across 2 different Stata commands to do this
- SPHDIST and VICENTY.  I have not been able to install the VICENTY
command.  It appears from previous StataList posts that there might be
problems associated with it and therefore it is temporarily unavailable

Although I have longitude and latitude data, I am not sure how to create
the pairs necessary to calculate distance with SPHDIST.   I would like
to calculate distance from a each public school in a district to all the
other private schools in the same district.  My data SHOULD look like

District ID     Public School ID       Private School ID        Public
Longitude         Public Latitude       Private Latitude        Private
1                          A                             1  
1                          A                             2 
1                          B                             1
1                          B                             2
1                          B                             3
1                          B                             4
2                          C                             1    
2                          C                             2
2                          C                             3
2                          D                             1
2                          D                             2  

I initially had two separate files; one with public school data and one
with private school data.  I appended the public school file and tacked
on the private school data.  

NOW the data looks something like this 

Distric ID     School ID       Public School     Private School
Latitude       Longitude
1                          A                       Y
1                          A                       Y
1                          B                       Y
1                          B                       Y
1                          B                       Y
1                          B                       Y
2                          C                      N
2                          C                      N
2                          C                      N
2                          D                      N
2                          D                      N

But I want to pair each public school with each private school.

So far, I have figured out how to produce a data set pairing ALL schools
within each district; this would pair public schools within a district
with other public schools in the same district (using a an FAQ page from
2005 written by Nick Cox titled "Expanding datasets to all possible
pairs").  However, I don't want this.  I only want to pair each public
school with each private school in the same district.

How do I accomplish this?

I would appreciate any help anyone could offer. Also, any suggestions
about the best distance command would be appreciated.

*   For searches and help try:

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