Kelly--
This comes up just often enough to warrant an FAQ, but I don't know if
there is one. There is a program that _almost_ does what you want
called -nearest- written by Nick Cox on 10 January 2003 and available
by typing -ssc install nearest- but it does not calculate distance on
a spherical or ellipsoidal model of the Earth. I assume when you say
x,y you mean you have signed decimal degrees lat and lon. In that
case, you can calculate distance using the -vincenty- program
vincenty lat1 lon1 lat2 lon2, g(d1) h(d2)
to generate distance variables.
Don't have the -vincenty- program? Here it is:
net from http://www-personal.umich.edu/~nicholsa/stata
net install vincenty
If you want to calculate distance to each hospital (or each VA and
non-VA hosp), you can merge the hospital data onto the patient data,
and do the calculations inside a loop that executes once for each
patient. If you're more specific about the structure of your data,
you will likely get more specific advice...
On 1/3/07, Richardson, Kelly K. <[email protected]> wrote:
Dear Statalisters,
I would like to calculate the distance between a patient's home and the
nearest hospital to their home. I have the x,y coordinates for the
patient's home and the x,y coordinates for every hospital in the
country. How do I get the distance to the nearest hospital? I looked at
the globdist command but I can't see how to enter coordinate variables
for both locations. For example, say I have 1000 patients across the
country and 5000 hospitals. How do I get one distance for each patient
that represents the distance to the nearest hospital? I'm not clear on
how my data should be constructed or which command to use. Right now the
data are in separate files, one for patients (n=1000) and one for
hospitals (n=5000). [...]