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

From |
"David Torres" <writeon4truth2@msn.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Re: Nearest distance (spatial) and shp2dta question |

Date |
Fri, 3 Jul 2009 16:27:17 -0400 |

I think I got what I wanted, Austin. Thanks. I was able to calculate my tract and county centroids in decimal degrees based on my map's projection using arcmap and the Mean Center tool. So that solved that problem. Now that all of my data are in decimal degrees, I can work from there using your and Sergio's examples to help me get where I ultimately want to be. Thanks for the reference; I'll peruse it when I can. Cheers, ********************************** David Diego Torres, MA(Sociology) PhD Candidate in Sociology 2030D Population Studies Center University of Michigan Institute for Social Research Ann Arbor MI 48106-1248 Tel 734.763.4098 Fax 734.763.1428 torresd@umich.edu ----- Original Message ----- From: "Austin Nichols" <austinnichols@gmail.com> To: <statalist@hsphsun2.harvard.edu> Sent: Friday, July 03, 2009 3:54 PM Subject: Re: st: Re: Nearest distance (spatial) and shp2dta question > David Torres<writeon4truth2@msn.com> : > > It's still not clear to me what you hope to achieve. I also don't see > any added value in Sergio's pointing you to the SSC program -vincenty- > (though that program may help you later if you calculate a weighted > average over all schools in the country, where distances involved may > be both great and small). The example code you quoted at the outset > gives the general method you need to adapt to your data, except that > you need to calculate centroids of some existing polygons first, for > which code follows. I am assuming that you are working with polygons > small enough that you can assume that distances can be measured as if > they lay in a plane; otherwise centroids will be difficult to > calculate. Also note centroids need not lie inside a polygon, if > polygons may be nonconvex, which may undercut your intuition about > using centroids to measure distances between points and sets. See > also appendices A and B in http://www.nber.org/papers/w13246 for > discussion of distance-weighted measures. Here is a program for > calculating centroids, and a couple of examples: > > clear all > prog calcentr, sortpreserve > version 8.2 > syntax varlist [,by(varlist) Stub(string) Force] > gettoken X Y: varlist > if "`stub'"=="" loc stub "c" > if "`by'"=="" { > tempvar by > g byte `by'=1 > } > tempvar t x y xm ym sx sy sa a b > qui { > g long `t'=_n > su `X', meanonly > loc xo=r(min) > g double `x'=`X'-`xo' > su `Y', meanonly > loc yo=r(min) > g double `y'=`Y'-`yo' > egen long `b'=group(`by') > sort `by' `t' > if "`force'"=="" by `by': assert `x'[1]==`x'[_N] > if "`force'"=="" by `by': assert `y'[1]==`y'[_N] > by `by' : g double `ym'=(`y'+`y'[_n+1])*(`x'*`y'[_n+1]-`x'[_n+1]*`y') > by `by' : g double `xm'=(`x'+`x'[_n+1])*(`x'*`y'[_n+1]-`x'[_n+1]*`y') > by `by' : g double `a'=(`x'*`y'[_n+1]-`x'[_n+1]*`y')/2 > egen `sa'=sum(`a'), by(`b') > egen `sy'=sum(`ym'), by(`b') > replace `sy'=`sy'/6/`sa'+(`yo') > egen `sx'=sum(`xm'), by(`b') > replace `sx'=`sx'/6/`sa'+(`xo') > } > if "`stub'"!="" { > ren `sx' `stub'x > ren `sy' `stub'y > } > end > > input x y > .9 0 > 0 1 > .9 2 > 1 2 > .1 1 > 1 0 > .9 0 > end > calcentr x y, f > line y x || sc cy cx, aspect(2) name(outside) > > use http://pped.org/stata/usa.dta, clear > calcentr _X _Y, by(_ID) stub(b) f > line _Y _X if _ID==10, aspect(1) || scatter by bx if _ID==10 > * > * 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/ > * * 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/

**References**:**st: Nearest distance (spatial) and shp2dta question***From:*"Sergio I Prada" <sprada1@umbc.edu>

**st: Re: Nearest distance (spatial) and shp2dta question***From:*"David Torres" <writeon4truth2@msn.com>

**Re: st: Re: Nearest distance (spatial) and shp2dta question***From:*Austin Nichols <austinnichols@gmail.com>

- Prev by Date:
**Re: st: Re: Nearest distance (spatial) and shp2dta question** - Next by Date:
**st: Re: Random Effects and RE Tobit** - Previous by thread:
**Re: st: Re: Nearest distance (spatial) and shp2dta question** - Next by thread:
**st: xtreg, xtdata with fixed effects in unbalanced panels** - Index(es):

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