Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: looping with geodist
From
Austin Nichols <[email protected]>
To
[email protected]
Subject
Re: st: looping with geodist
Date
Fri, 7 May 2010 11:25:32 -0400
Frederick Guy <[email protected]> :
Except that r(min) should be r(sum), of course.
On Fri, May 7, 2010 at 11:23 AM, Austin Nichols <[email protected]> wrote:
> conserve memory. Suppose you want the weighted sum of inverse
> distances (assuming none are zero); then you could just:
>
> use type_i, clear
> local Ni=_N
> merge using type_j
> g w=.
> qui forv i=1/`Ni' {
> g double L=(yj-yi[`i'])*_pi/180
> replace L=(yj-yi[`i']-360)*_pi/180 if L<. & L>_pi
> replace L=(yj-yi[`i']+360)*_pi/180 if L<-_pi
> local t1 acos(sin(xj*_pi/180)*sin(xi[`i']*_pi/180)
> g i=1/(`t1'+cos(xj*_pi/180)*cos(xi[`i']*_pi/180)*cos(L))*6367.44)
> su i, meanonly
> replace w=r(min) in `i'
> drop L i
> }
> la var w "Sum of Inverse (Approx) Distances"
*
* 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/