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

From |
Scott Merryman <scott.merryman@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: spatial analysis - DISTANCE |

Date |
Sun, 30 Aug 2009 10:13:03 -0500 |

On Sun, Aug 30, 2009 at 9:15 AM, David Torres<torresd@umich.edu> wrote: > Austin, I've looked over the code you offered and it seems that what I'm > getting is just the xy coordinates rather than what I need. There's got to > be a way, somehow, to have stata return a list of all the unitids that are > within the specified radius. When I run the code I have, all I get is a > return of the unitid on the nearest school to my 65000 tracts. However, > within the rad10 variable, several tracts have multiple schools within my > radius of 10 miles. I need to get all of these unitids regardless of > whether I end up with wide or long data; I can always reshape later. > How about something like this: clear set obs 9 gen id =_n set seed 1234 gen latitude = uniform()/2 gen longitude = uniform()/2 mata X= st_data(.,( "latitude" , "longitude")) X =X*(pi()/180) dist = J(rows(X),rows(X), 0) for (i = 1; i <=rows(X); i++) { for (j = 1; j <=rows(X); j++) { dist[i,j] = (1/1.609)*6372.795*(2*asin(sqrt( sin((X[i,1] /// - X[j,1])/2)^2 + cos(X[i,1])*cos(X[j,1])*sin((X[i,2] /// - X[j,2])/2)^2 ))) } } N = mm_cond(dist :<= J(rows(dist), cols(dist), 10), /// J(rows(dist), cols(dist),1), J(rows(dist), cols(dist), 0)) st_matrix("N" ,N) dist end svmat N l Scott * * 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/

**Follow-Ups**:**Re: st: spatial analysis - DISTANCE***From:*David Torres <torresd@umich.edu>

**References**:**st: spatial analysis - DISTANCE***From:*David Torres <torresd@umich.edu>

**Re: st: spatial analysis - DISTANCE***From:*Austin Nichols <austinnichols@gmail.com>

**Re: st: spatial analysis - DISTANCE***From:*David Torres <torresd@umich.edu>

- Prev by Date:
**Re: st: spatial analysis - DISTANCE** - Next by Date:
**st: How to read dummy coefficients in GARCH model** - Previous by thread:
**Re: st: spatial analysis - DISTANCE** - Next by thread:
**Re: st: spatial analysis - DISTANCE** - Index(es):

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