Statalist


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

Re: st: spatial analysis - DISTANCE


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: spatial analysis - DISTANCE
Date   Sun, 30 Aug 2009 05:30:13 -0400

David Torres<[email protected]> :
This is in reference to e.g.
http://stata.com/statalist/archive/2009-07/msg00083.html
http://stata.com/statalist/archive/2007-01/msg00098.html
I believe.

Note that standard Stata commands like -summarize- and -replace-
inside the loop do all the work of saving characteristics of the
nearest, or k nearest, observations (and whatever else, such as mean
of Z over those with distance less than 10 units).  No program like
-vincenty- (on SSC) does that; a -replace- command does it.
-vincenty- does not return "the min, max, mean, or whatever" and it
appears that -globdist- (which I found with -findit-) does only part
of what -vincenty- does (and the -globdist- help file contains the
caveat that "Testing of this program has been limited").  In other
words, add a -replace- to put the result you want in a variable.

Maybe you want something like:

g long rad10=.
g double dist1=.
g id1=""
g xy1=""
merge using univpoints00_0
forv i=1/`np' {
qui vincenty `=latitude[`i']' `=longitude[`i']' sch_lat sch_lon, hav(dis)
g within10=dis<10
su within10, meanonly
qui replace rad10=r(sum) in `i'
su dis, meanonly
qui replace dist1=r(min) in `i'
qui levelsof unitid if dis==dist1[`i'], loc(vs)
foreach v of loc vs {
 qui replace id1="`v' "+id1 in `i'
 su sch_lat if unitid==`v', meanonly
 loc y1=r(mean)
 su sch_lon if unitid==`v', meanonly
 loc x1=r(mean)
 qui replace xy1="(`x1',`y1') "+id1 in `i'
 }
drop dis within10
}

On Sat, Aug 29, 2009 at 4:26 PM, David Torres<[email protected]> wrote:
> I am trying to calculate multiple distances from one set of xy coordinates
> to another
> using vincenty.  In addition to getting those distances, however, I need to
> somehow list
> the ids for the xy coordinates used to calculate the distance.
>
> Here is the piece of code I'm working with:
>
> code excerpt:
>
> g long rad10=.
> g double dist1=.
> g id1=""
> merge using univpoints00_0
>
> forv i=1/`np' {
> qui vincenty `=latitude[`i']' `=longitude[`i']' sch_lat sch_lon, hav(dis)
> g within10=dis<10
> su within10, meanonly
> qui replace rad10=r(sum) in `i'
> su dis, meanonly
> qui replace dist1=r(min) in `i'
> qui levelsof unitid if dis==dist1[`i'], loc(vs)
> foreach v of loc vs {
>  qui replace id1="`v' "+id1 in `i'
>  }
> drop dis within10
> }
>
> end excerpt
>
> As you can see, I'm getting a count of all sch_lat and sch_lon coordinates
> within a 10
> mile radius of the other set of latitude and longitude points.  Then I
> return only the
> minimum distance.  Will vincenty allow for returning more than just the min,
> max, mean,
> or whatever?  Or is globdist a better choice for returning multiple
> distances and the ids
> attached to the point the distance to which is being calculated?
>
> Thanks
>
> David Torres
> UMich

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index