Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: calculating longitudinal-latitudinal distances


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: calculating longitudinal-latitudinal distances
Date   Thu, 20 Apr 2006 14:14:12 -0400

Assuming you have a dataset of legal providers, you don't need to
treat people differently depending on what type of state they live in,
since the nearest provider for some people cannot lie inside their
state, while it may for others, but the nearest provider *can* lie
outside the state for either type of person.  Assume you've got N obs,
one per person, with lat/lon in your primary dataset people.dta, and M
providers with lat/lon in your provider data prov.dta. Then try this
approach on for size (assumes you may want to know something about the
nearest provider other than distance to it, e.g. what state it's in,
or costs of services):

use people
gen provid=.
gen mindist=.
sort id
forv i=1/`=_N' {
 su lat in `i', meanonly
 scalar plat=r(mean)
 su lon in `i', meanonly
 scalar plon=r(mean)
 preserve
 use prov, clear
 vincenty lat lon plat plon, gen(dist)
 su dist, meanonly
 keep if dist==r(min)
 * What do you do if multiple providers are all closest?
 * I pick one at random.
 * You could instead: scalar n=_N and save IDs
 *  in a loop, then expand n after the restore
 scalar cprovid=provid
 scalar mdist=dist
 restore
 replace provid=cprovid in `i'
 replace mindist=mdist in `i'
}
sort provid
merge provid using prov, uniqusing

You can get vincenty.ado via the command
net from http://www-personal.umich.edu/~nicholsa/stata
or use your own method.

All of the above is untested code--use at own risk...

On 4/20/06, Scott Cunningham <scunning@gmail.com> wrote:
> I am currently working on a project wherein I attempt to determine
> whether abortion restrictions (specifically, state-level laws
> requiring parental involvement for minors seeking an abortion and
> mandatory delays for all women seeking abortions) affects sexual
> debut and contemporaneous sexual frequency (as well as contraception
> decisions).  To do this project correctly, I have to control for the
> distance between a woman in my sample affected by the law (ie, a
> minor in a state with an parental involvement law, and all women for
> the mandatory delay law) woman's proximity to an out-of-state
> abortion provider (ie, in a state without the law).  The idea is that
> the law is not binding if a woman can travel out-of-state to elect an
> abortion.
>
> I know the formula for calculating distances using latitude/
> longitude, but am having trouble thinking of the most efficient way
> to do this in Stata.  My problem requires that I find not the
> distance between every county and every abortion provider, but
> rather, every county where I have a respondent living and assuming
> they live in a state with a binding abortion restriction law, the
> distance from their county and the nearest abortion provider without
> the law.  If they don't live in such a state, then I need only to
> indicate the distance from their county of residence and the nearest
> abortion provider at all.
>
> So, my question is not about the mathematical formula for calculating
> geographic distance, but the most efficient way to do this in Stata.
> Does anyone have any insights to help me think through this?
>
>
> scott
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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