Announcement

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

  • Calculate distance between 2 geographical locations

    Hi

    I am working with 2 files with data sets which have longitude and latitudes for different districts. I am trying to figure out how to calculate the distance between the longitude and latitude in these two files. Does anyone have any idea?

    For instance,
    File 1:
    Longitude Latitude District
    1) -70 -35 example
    2) -40 -25 example 2
    3) -50 -27 example 3
    4) -66 -44 example 4
    5) -79 -28 example 5

    File 2:
    Longitude Latitude District
    1) -25 -38 example 3
    2) -38 -79 example 5


    Thank you!
    Last edited by Guo Pei; 01 Jan 2017, 21:22.

  • #2
    I've never used it but the package georoute might help.

    Code:
    ssc install georoute
    help georoute

    Comment


    • #3
      If you are trying to calculate the distance between all pairwise combinations, use cross to create a dataset with all possible combinations and geodist (from SSC) to calculate the distances. If you are trying to find the closest location or subsets within a set distance, use geonear (also from SSC).

      Comment


      • #4
        Thanks so much Chris and Robert! These are really helpful! Will you happen to know whether there is any code to sort the data if there is no common identifier in the 2 dta files? For instance, in the 2 files, 'district' is different from 'area'.
        File 1:
        Longitude Latitude District


        File 2:
        Longitude Latitude Area

        I did it manually (using excel) by changing the name 'area' to 'district' and eliminating the outliers such as 'example 2' and 'example 4' before importing the combined version onto Stata but was wondering whether there is a neater way of doing it.

        Thank you!

        Comment


        • #5
          Hi Guo,

          I don't know what example 2 and example 4 are, not being familiar with your dataset.

          It seems like what you want though is a lookup of different statistical geographies. Try a thorough google search (or your search engine of choice), and you may well be able to find something that links up Districts to Areas, for example

          Good luck

          Comment

          Working...
          X