Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"Vitorino, Maria Ana" <vitorino@wharton.upenn.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: calculating many distances and storing them in many new variables |

Date |
Fri, 21 Oct 2011 10:16:17 +0000 |

Dear Yuval, Thanks. But the goal is different. I know to which hospital each patient went. What I'm trying to do is to calculate the distance between each patient and each hospital alternative (ie all the hospitals that the patient could have decided to go to). I'm guessing this can be done with some sort of loop... Ana On Oct 21, 2011, at 4:42 AM, "Yuval Arbel" <yuval.arbel@gmail.com> wrote: > Anna, > > I'm not sure what your precise goal is. But if your target is only to > map what hospital each patient went, may I suggest the following: > > Suppose you have a column of coordinates under "patient" and another > column under "hospitals" > If you are working with STATA11 you can try running: > > reg patient i.hospitals > > Let me show you what is the output you get by using one of the > examples I ran: I collected a small dataset, which measures land > values (rent) and distance from Tel Aviv center (distance): > > . reg rent i.distance > > Source | SS df MS Number of obs = 55 > -------------+------------------------------ F( 9, 45) = 12.43 > Model | 294279904 9 32697767.1 Prob > F = 0.0000 > Residual | 118368183 45 2630404.07 R-squared = 0.7131 > -------------+------------------------------ Adj R-squared = 0.6558 > Total | 412648087 54 7641631.24 Root MSE = 1621.9 > > ------------------------------------------------------------------------------ > rent | Coef. Std. Err. t P>|t| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > distance | > 1000 | -8245.833 1238.71 -6.66 0.000 -10740.72 -5750.943 > 1500 | -8087.026 1038.817 -7.78 0.000 -10179.31 -5994.741 > 2000 | -6353.833 1067.634 -5.95 0.000 -8504.158 -4203.509 > 2500 | -7560.333 1480.542 -5.11 0.000 -10542.3 -4578.37 > 3000 | -6545.958 1097.999 -5.96 0.000 -8757.442 -4334.475 > 3500 | -9500 1324.237 -7.17 0.000 -12167.15 -6832.85 > 4000 | -9891.905 1119.184 -8.84 0.000 -12146.06 -7637.752 > 4500 | -10258.33 1238.71 -8.28 0.000 -12753.22 -7763.443 > 5000 | -11600.33 1872.753 -6.19 0.000 -15372.25 -7828.414 > | > _cons | 13433.33 936.3767 14.35 0.000 11547.37 15319.29 > ------------------------------------------------------------------------------ > > Note that the distance variable includes values from 500 to 5000 > meters. The command made the 500 meter distance the base category. > > On Fri, Oct 21, 2011 at 5:13 AM, Maria Ana Vitorino > <vitorino@wharton.upenn.edu> wrote: >> 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/ >> > > > > -- > Dr. Yuval Arbel > School of Business > Carmel Academic Center > 4 Shaar Palmer Street, Haifa, Israel > e-mail: yuval.arbel@gmail.com > > * > * 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/ * * 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/

**Follow-Ups**:**RE: st: calculating many distances and storing them in many new variables***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: calculating many distances and storing them in many new variables***From:*"Michael Ralph M. Abrigo" <mmabrigo@gmail.com>

**References**:**st: calculating many distances and storing them in many new variables***From:*Maria Ana Vitorino <vitorino@wharton.upenn.edu>

**Re: st: calculating many distances and storing them in many new variables***From:*Yuval Arbel <yuval.arbel@gmail.com>

- Prev by Date:
**st: A Question Regarding the Cox Regression and Projected Survival Rates** - Next by Date:
**Re: st: calculating many distances and storing them in many new variables** - Previous by thread:
**Re: st: calculating many distances and storing them in many new variables** - Next by thread:
**Re: st: calculating many distances and storing them in many new variables** - Index(es):