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: calculating many distances and storing them in many new variables


From   Maria Ana Vitorino <[email protected]>
To   <[email protected]>
Subject   st: calculating many distances and storing them in many new variables
Date   Thu, 20 Oct 2011 23:13:40 -0400

Dear StataList users,

Suppose we have the following toy data which has a list with patients, the hospital to which they went (hosp_ch) and the coordinates for both.

patient_id hosp_ch	lat_pat	lng_pat	lat_hosp	lng_hosp
1		a		2		4		5		6
2		a		1		3		5		6
8		c		3		5		10		12
9		a		5		2		5		6
12		b		8		6		8		9


What I would like to do is:
**To create new variables with the distances from every patient to every possible hospital in the data. So, I would like 3 new columns which will contain the distance from each patient to each hospital in the data. **Also, I would like to have those new columns labeled dist_a, dist_b and dist_c.

Is there an efficient way to achieve this?
In the real data, I have many more patients and hospitals (hundreds in fact) so I would like to generate these variables in an as automated way as possible.

Any help is appreciated.
Thanks!
Ana





































*
*   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