Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using GEONEAR with a LOOP


    Hello everyone!

    I have a 55k observations data set (USA census tracts) with latitude and longitude in every case. Also, the information of employment (number of jobs) in every tract.
    I need to use the GEONEAR function to identify all the tracts (around each tract) within a 1km diameter AND to sum the number of jobs of those tracts in that first 1k window. (And ultimately get employment density)

    This is the expression I`m using, but the result is just THE NEAREST no all tracts around each tract.

    geonear ctid0 ycoord xcoord using "'file_1'", n(fid ycoord xcoord) ign long within(1) near(0)

    The use of GEONEAR is not the problem. The loop to sum employment it’s the complicated part, where I would appreciate some guidance. I really appreciate any help you can provide.


  • #2
    I do not understand why you use the near(0) option. It limits the number of neighbors returned, in your case apparently to 1 (since limiting the results to 0 makes no sense). I think if you removed that option you would get every tract within 1km.

    With the resulting long form dataset, you can do something like
    Code:
    geonear ctid0 ycoord xcoord using "`file_1'", n(fid ycoord xcoord) ign long within(1)
    merge m:1 fid using "`file_1'", keep(master match) keepusing(employment)
    collapse (sum) near_empl=employment (count) near_tracts=employment, by(ctid0)
    and you will now have a dataset with observations identified by ctid0 including the total employment in all tracts within 1km, as well as a count of the number of tracts.

    This is completely untested code meant to outline the direction you can take. The key feature is there is no reason at all for you to code a loop to accomplish what you seek.

    Comment

    Working...
    X