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

st: Nearest distance (spatial) and shp2dta question

From   "Sergio I Prada" <>
Subject   st: Nearest distance (spatial) and shp2dta question
Date   Fri, 3 Jul 2009 09:40:06 -0400 (EDT)

Here another resource (which I got before from the kind people at Stata):

Havershine is a user written command that calculates the distance using
the Haversine formula, Vincenty formula, and/or the Law-of-Cosines-based
formula. Type the following to install this command:

net describe vincenty, from(
net install vincenty

Then, type -help vincenty- to view the help file. By using the hav()
option you
can calculate the distance using the Haversine formula instead of manually
entering the equation. Also, the default is to express the distances in miles
but you can change this to kilometers with the in km option.

See one example here

use testdistance, clear
set more off
sort patient
gen id = _n
qui levelsof patient, local(patients)
qui gen shortest_dist = .
qui gen matched_hos = .
foreach p of local patients {
        qui keep if patient==`p'
        local pat_long = pat_long[1]
        local pat_lat = pat_lat[1]
        local obs = id[1]
        vincenty `pat_lat' `pat_long' hos_lat hos_long, hav(h) replace
        summarize h
        qui replace shortest_dist = `r(min)' in `obs'
        keep if round(h,.00001) == round(`r(min)', .00001)
        local id = hospital[1]
        qui replace matched_hos = `id' in `obs'

drop id

This is calculating the straight distance from the patient to the
hospital. This is not taking into consideratin any physical land barriers,
such as mountains and rivers.

Sergio I. Prada, PhD (Candidate)
Department of Public Policy
University of Maryland, Baltimore County
1000 Hilltop Circle, Baltimore, MD 21250
Phone: 410-455-6527

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index