Statalist


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

st: Vincenty question


From   David Torres <torresd@umich.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Vincenty question
Date   Thu, 27 Aug 2009 18:34:06 -0400

I'm was originally calculating distances from census tract centroids to nearest postsecondary institution. Secondary to this, I also created a variable to just list the number of schools within a certain radius of the tract centroids. Everything works superbly and I thank Austin and Nick for their help.

Now I need to be able to list all distances from tracts to schools as well as the IDs for the schools that are within the distance I've given for my radius. That is, I'd like to have the school that is nearest to a tract listed first, followed successively by the next closest school, and so on, within the the radius in my command. I've included a piece of the code that I have for doing this for ONLY the minimum distance. I appreciate any help y'all can give.

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


David Torres

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