Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: spatwmat: a further thought on XY coordinates


From   Nomorenook@netscape.net
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: RE: spatwmat: a further thought on XY coordinates
Date   Fri, 04 Feb 2005 13:36:19 -0500

Let's get the discussion less philosophical but rather the mechanism behind "spatwmat". It occurs to me that Dr. Pisati did use the global XY coordinate, because the way his code calculates the distance follows the formula that calculates the distance between two points in a two-dimension space, i.e., suppose we have point A(x1, y1) and point B(x2, y2), then the Distance = [(x1-x2)^2 + (y1-y2)^2]^(.5)

Please see his code below:

   /* Create intermediate matrix */
    matrix _W=J(`N',`N',0)
    matrix _D=J(`N',`N',0)
    preserve
    local MAXOBS=(`N'/2)*(`N'-1)
    qui set obs `MAXOBS'
    tempvar DISTAN
    qui generate `DISTAN'=.
    local d=1
    local i=1
    while `i'<=`N' {
        local j=`i'+1
        while `j'<=`N' {
            local A=(`xcoord'[`i']-`xcoord'[`j'])^2
            local B=(`ycoord'[`i']-`ycoord'[`j'])^2
            local DIST=sqrt(`A'+`B')
            qui replace `DISTAN'=`DIST' in `d'
            matrix _D[`i',`j']=`DIST'
            matrix _D[`j',`i']=`DIST'
            if `DIST'>`LOWER' & `DIST'<=`UPPER' {
                if "`binary'"!="" {
                    matrix _W[`i',`j']=1
                    matrix _W[`j',`i']=1
                }
                else {
                    matrix _W[`i',`j']=1/(`DIST'^`friction')
                    matrix _W[`j',`i']=1/(`DIST'^`friction')
                }
            }
           local d=`d'+1
           local j=`j'+1
        }
       local i=`i'+1
    }
    
    /* Generate distance statistics */
    qui summarize `DISTAN', detail
    local DMIN=r(min)
    local DP25=r(p25)
    local DP50=r(p50)
    local DP75=r(p75)
    local DMAX=r(max)
   qui svmat _D
   qui for varlist _D* : replace X=. if X==0
   qui egen ROWMIN=rmin(_D*)
   qui summ ROWMIN, mean
   local MAXMIN=r(max)
   qui egen ROWMAX=rmax(_D*)
   qui summ ROWMAX, mean
   local MINMAX=r(min)
   matrix drop _D
    restore



"Nick Cox" <n.j.cox@durham.ac.uk> wrote:

>This is not a problem. Most geographers 
>do not worry about coordinates of any 
>kind, being somewhat averse to numbers 
>in any shape or form. Those that do are 
>aware that the Earth is a oblate spheroid, 
>and better treated in a non-Cartesian way. 
>
>Nick 
>n.j.cox@durham.ac.uk 
>
>Julia Gamas
>
>> XY coordinates may just be referring to the zone pair:  So in 
>> my case if zones 1
>> and 2 are neighbors then the XY="12" and "21" entries in the 
>> table are 1.  If
>> so it seems a bit "dangerous" to name it this because a 
>> geographer will
>> interpret them as literally the XY coordinates on the globe, 
>> making the whole
>> thing confusing.  
>
>*
>*   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/
>

__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp
*
*   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