Diego,
Do you mean something like this:
clear
input str14 gisjoin longitude latitude sch_lon sch_lat unitid
"G060000400100" -124.5746 39.97379 -85.95683 31.80067 102368
"G0600010400200" -124.5933 39.95392 -86.25552 31.30878 101107
"G0600010400300" -124.5983 39.94619 -86.86419 33.10434 101709
"G0600010400400" -124.6022 39.95378 -87.67984 34.73044 101736
"G0600010400500" -124.6101 39.95397 -85.94818 32.92472 100760
"G0600010400600" -124.6098 39.9473 -86.16864 32.38251 101958
"G0600010400700" -124.6177 39.94698 -86.99479 33.36999 100919
"G0600010400800" -124.6299 39.95023 -87.55314 33.09406 102067
"G0600010400900" -124.6261 39.94432 -85.83498 31.29919 101143
"G0600010401000" -124.617 39.93631 -85.68978 32.42277 102216
"G0600010401100" -124.6081 39.9358 -87.01451 32.44433 101301
"G0600010401200" -124.6017 39.93617 -86.34469 32.34993 102313
"G0600010401300" -124.6105 39.9232 -86.31091 32.37661 102359
"G0600010401400" -124.6178 39.9257 -86.79467 33.46106 102049
"G0600010401500" -124.6257 39.9277 -87.0184 32.42337 101073
end
matrix dist = J(15,15,0)
matrix id_2100_ = J(15,15,0)
forv j = 1/15 {
forv i = 1/15 {
matrix dist[`j',`i'] = sqrt( (69.1*(sch_lat[`i'] - latitude[`j']))^2 ///
+ (69.1*(sch_lon[`i'] - longitude[`j']) * cos(latitude[`j']/57.3))^2)
matrix id_2100_[`j',`i'] = unitid[`i']*(dist[`j',`i'] < 2100)
}
}
mat list dist
mat list id_2100_
svmat id_2100_
Given that all you gisjoin coordinates are in the Pacific Ocean off of
California and the unitids are in Alabama, you are going to need a
radius larger than 50 miles to find any matches. In the example above
I changed the cutoff to 2100 miles.
Scott
On Tue, Jul 7, 2009 at 8:58 AM, David Torres<[email protected]> wrote:
> Austin,
>
> Thanks for the tip. I figured there was a way to complete this
> process in a loop, but as I'm not too familiar with the intricacies of
> stata code (and don't possess a good text on it) I just waste a lot of
> time trying different things based on other code I've seen. At any
> rate, allow me to give an example of the data I'm working with
> (already nonmatch merged and abbreviated for simplicity).
>
> input gisjoin longitude latitude sch_lon sch_lat unitid
> G0600010400100 -124.5746 39.97379 -85.95683 31.80067 102368
> G0600010400200 -124.5933 39.95392 -86.25552 31.30878 101107
> G0600010400300 -124.5983 39.94619 -86.86419 33.10434 101709
> G0600010400400 -124.6022 39.95378 -87.67984 34.73044 101736
> G0600010400500 -124.6101 39.95397 -85.94818 32.92472 100760
> G0600010400600 -124.6098 39.9473 -86.16864 32.38251 101958
> G0600010400700 -124.6177 39.94698 -86.99479 33.36999 100919
> G0600010400800 -124.6299 39.95023 -87.55314 33.09406 102067
> G0600010400900 -124.6261 39.94432 -85.83498 31.29919 101143
> G0600010401000 -124.617 39.93631 -85.68978 32.42277 102216
> G0600010401100 -124.6081 39.9358 -87.01451 32.44433 101301
> G0600010401200 -124.6017 39.93617 -86.34469 32.34993 102313
> G0600010401300 -124.6105 39.9232 -86.31091 32.37661 102359
> G0600010401400 -124.6178 39.9257 -86.79467 33.46106 102049
> G0600010401500 -124.6257 39.9277 -87.0184 32.42337 101073
> end
>
> The first three columns represent information from the master data, while
> the remaining three columns represent information from the using data set.
> I'm supposing that additional variables can be excluded in this example
> since what I need is the total number of unitids--of the using data set--in
> a radius of, say, 50 miles of gisjoin--of the master data set.
>
> Thanks,
> Diego
>
> --------------------------------------------
>
> 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 at umich dot edu
>
> *
> * 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/