Announcement

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

  • calculating distance in Stata

    Dear All,
    I would like to know how I can calculate distance in stata between two cities in a country say for the UK Manchester and Nottingham. I have never done this before. Please advise on how I can go about it. I have information on postcodes and names of local municipalities for the uk in my dataset. I would like to generate a matrix that gives distances between one city and each of the individual cities within the dataset.

    Grateful for your help.


    Best,

    Bridget






  • #2
    You can look at the help file for the user-written command geodist(type ssc install geodist, replace in Stata)
    So if you want the distance between cities two you'll need latitude and longitude coordinates for each. Hope this helps.

    Comment


    • #3
      Many thanks Justin it does. Do these have to be imported into stata or i can generate them. Sorry for the very basic questions am doing this for the first time.

      Comment


      • #4
        Bridget, if you go to this site, you can download latitide and longitude information corresponding to UK postcodes. You need to import this into Stata and then merge with your postcodes. Note that geodist will give you distances by air - if you need road distances, you need to search elsewhere.

        Comment


        • #5
          A simple option if you have a limited set of cities, for example only cities in the UK:
          - google for a list of cities with latitudes and longitudes, and merge these with the cities in your stata dataset
          - make sure you have lat & lon of both start and end point
          - use geodist to calculate distance between start lat & lon and end lat & lon

          Alternatively, use a program that can help you collect latitude and longitude of cities or specific street addresses, e.g.:
          http://fmwww.bc.edu/repec/bocode/o/opencagegeo.pdf
          https://www.econstor.eu/bitstream/10.../1/WP16-10.pdf
          With the latter also capable of calculating travel distance
          I should not I've never used these programs myself so cant vouch for their ease of use or even if they work currently (these sorts of tools depend on api with some online resource).

          The approach to choose depends a bit on how complex you want to make this. The latter approach will take more time to learn how to use the tools but will be useful for similar tasks as well, the first approach is less complex but needs more manual work.

          Comment


          • #6
            Many thanks Jorrit . This has been very helpful. Thanks once again

            Comment

            Working...
            X