st: Calculating distance

 From Graeme Inglis <[email protected]> To "Stata List (E-mail)" <[email protected]> Subject st: Calculating distance Date Wed, 16 Apr 2003 09:04:38 +1000

```Hi
I would like some help from the StataList with a problem calculating the
distance between a patients residential post code and the postcode of the
nearest treatment centre.

I have assembled a two data files. The first file contains the patients
postcodes and the X & Y (px, py) coordinates of these  post codes. The
second  file has the radiotherapy centres with their post codes and the X &
Y (rdx, rdy) coordinates of their post codes.
By subtracting the X's and the Y's and applying pythagoras's theorem the
distance in km can be calculated, but the difficulty is to select the
shortest distance and write the location and shortest distance into a new
variable for each patient.

Now I envisage the shortest distance would be determined by taking the first
patient and calculating the distance to each treatment  centre (13 centres
in this case), then selecting the shortest distance among the centres then
writing this distance and the centres post code into two new variables
'pradpc' and 'praddist' for that patient in the patient dataset. So that the
patient data set would progressively have values written into the post code
'pradpc' of the nearest centre and the distance 'praddist' to this centre.

I can calculate the distance OK but I can't get an iterative process working

I have attached two sample files for the patient data and the treatment
centre data to assist.

Now the process may be simplified by considering those patients who live in
the same post code as a treatment  centre in which case  pradpc=patpc and
the distance would be zero.

In addition if the patient file is sorted by post code duplicate values of
the same post code would have the same pradpc and distance.

I will be very grateful for help in this problem.
I'm still using Stata 7.
Thankyou in anticipation
Cheers

Graeme Inglis.
Research Officer.
Cancer Control Research Institute.
Centre for Behavioural Research in Cancer.
The Cancer Council of Victoria.
Telephone: 61(0)3 9635 5203.

Graeme Inglis.
Research Officer.
Cancer Control Research Institute.
Centre for Behavioural Research in Cancer.
The Cancer Council of Victoria.
Telephone: 61(0)3 9635 5203.

```

Attachment: stata_qp_140403.dta
Description: Binary data