Announcement

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

  • What code will match longitude and latitudes

    I hope there is someone that will be able to help me. I have been looking at previous FAQ on Statalist but could not find the one that will give me the code I need.

    I have two datasets. In the first dataset I have 60 obs of small gold mines in Burkina Faso. I have the longitude and latitude of each mine. It is just a point, not a polygon. So the database looks something like this: (The "objectid" is just each mine numbered and the longitude and latitude is the specific mine's coordinates.)

    | objectid longitude latitude |
    |--------------------------------------------|
    | 1 12.019287 1.3967028 |
    | 2 12.471074 .76883174 |
    | 3 13.353399 -.29639484 |
    | 4 12.411368 -.72431002 |
    | 5 12.246743 -.87246019 |

    In the second database I use data from the DHS survey from USAID - I have more than 25000 observations of households in Burkina Faso. With variables that describe the household (wealth, if they have electricity, literacy, etc) as well as the longitude and latitude of the village the household is in. It looks something like this:

    id longit~e latitude wealth~x litera~y |
    |-------------------------------------------------------------------|
    | 517 -4.307324 11.18618 richest able to |
    | 164 -2.36086 13.205 richer cannot r |
    | 200 -5.289879 10.70456 poorest cannot r |
    | 349 0.304598 13.81315 poorest cannot r |
    | 173 -4.324343 9.669069 richest cannot r |


    My question:
    I want to create a dummy variable in my second database called vicinity_mine that is 1 if the household's village (longitude and latitude attached to the household) is in the vicinity of a mine and 0 if not. Let's say "vicinity" is defined as within a 5km radius of the mine. I want to use the coordinates of the mines in the first database to create such a database but I am not sure where to start.


    I have very little experience with distances and using coordinates on Stata so any help on what code I should use will be very helpful.

    Thank you very much.
    All the bet,
    Nettie
    Last edited by Nettie vd Merwe; 18 Mar 2020, 05:55.

  • #2
    Please see -ssc describe geonear-. This user-written command has various options for detecting "neighbors" (mines in your case) that are near to observations. (Also, for the future, please re-read the StataList FAQ, which prescribes using the -dataex- command to show example data.) Note that in the example data you supplied, it appears that none of the mines are within 5 km of any household.

    Code:
    clear
    // Create example files
    // mines
    input int objectid longitude latitude
    1 12.019287 1.3967028
    2 12.471074 .76883174
    3 13.353399 -.29639484
    4 12.411368 -.72431002
    5 12.246743 -.87246019
    end
    tempfile mines
    save `mines'
    clear
    // households
    input int id longitude latitude
    517 -4.307324 11.18618
    164 -2.36086 13.205
    200 -5.289879 10.70456
    349 0.304598 13.81315  
    173 -4.324343 9.669069
    end
    // With your household file resident in Stata, and your mines in an external file,
    // you can find the nearest mine for each household and note if within 5 km.
    geonear id latitude longitude using `mines', ///
       wide neighbors(objectid latitude longitude)
    gen byte vicinity = (km_to_nid) <= 5.0
    list

    Comment


    • #3
      Thank you Mike!

      This is super helpful.

      And thank you for the advice on how to display example data - that will help with questions in the future.

      Comment

      Working...
      X