Announcement

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

  • distance between two addresses (with latitude and longitude)

    Dear all, I ask this question for someone else (here in Chinese), The data is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long stkcd int year str21(Jingwei1 Jingwei2)
    2 2007 "114.068746,22.573589" "113.979272,22.562049"
    2 2008 "114.068746,22.573589" "113.979272,22.562049"
    2 2009 "114.068746,22.573589" "113.979272,22.562049"
    2 2010 "114.068746,22.573589" "113.979272,22.562049"
    2 2011 "114.068746,22.573589" "113.979272,22.562049"
    2 2012 "114.068746,22.573589" "113.979272,22.562049"
    2 2013 "114.068746,22.573589" "113.979272,22.562049"
    2 2014 "114.068746,22.573589" "113.979272,22.562049"
    2 2015 "114.068746,22.573589" "113.979272,22.562049"
    2 2016 "114.068746,22.573589" "113.979272,22.562049"
    2 2017 "114.068746,22.573589" "114.070184,22.552655"
    2 2018 "114.068746,22.573589" "114.070184,22.552655"
    2 2019 "114.068746,22.573589" "114.070184,22.552655"
    2 2020 "114.068746,22.573589" "114.070184,22.552655"
    4 2007 "114.054117,22.556835" "114.057334,22.54277"
    4 2008 "114.054117,22.556835" "114.057334,22.54277"
    4 2009 "114.054117,22.556835" "114.057334,22.54277"
    4 2010 "114.054117,22.556835" "114.057334,22.54277"
    4 2011 "114.054117,22.556835" "114.057334,22.54277"
    4 2012 "114.054117,22.556835" "114.057334,22.54277"
    end
    The question is how to calculate the distance between `Jingwei1' (one address) and `Jingwei2' (the other address)? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    For geodetic distances, use geodist from SSC by Robert Picard. If you want distance by road, ask Google Maps. Distances are in kilometers. If you want miles, specify the -miles- option.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long stkcd int year str21(Jingwei1 Jingwei2)
    2 2007 "114.068746,22.573589" "113.979272,22.562049"
    2 2008 "114.068746,22.573589" "113.979272,22.562049"
    2 2009 "114.068746,22.573589" "113.979272,22.562049"
    2 2010 "114.068746,22.573589" "113.979272,22.562049"
    2 2011 "114.068746,22.573589" "113.979272,22.562049"
    2 2012 "114.068746,22.573589" "113.979272,22.562049"
    2 2013 "114.068746,22.573589" "113.979272,22.562049"
    2 2014 "114.068746,22.573589" "113.979272,22.562049"
    2 2015 "114.068746,22.573589" "113.979272,22.562049"
    2 2016 "114.068746,22.573589" "113.979272,22.562049"
    2 2017 "114.068746,22.573589" "114.070184,22.552655"
    2 2018 "114.068746,22.573589" "114.070184,22.552655"
    2 2019 "114.068746,22.573589" "114.070184,22.552655"
    2 2020 "114.068746,22.573589" "114.070184,22.552655"
    4 2007 "114.054117,22.556835" "114.057334,22.54277"
    4 2008 "114.054117,22.556835" "114.057334,22.54277"
    4 2009 "114.054117,22.556835" "114.057334,22.54277"
    4 2010 "114.054117,22.556835" "114.057334,22.54277"
    4 2011 "114.054117,22.556835" "114.057334,22.54277"
    4 2012 "114.054117,22.556835" "114.057334,22.54277"
    end
    
    split Jingwei1, p(,) g(coord1) destring
    split Jingwei2, p(,) g(coord2) destring
    rename (coord11-coord22) (lon1 lat1 lon2 lat2)
    geodist lat1 lon1 lat2 lon2, g(wanted)
    Res.:

    Code:
    . l stkcd year lon1-wanted, sepby(stkcd)
    
         +--------------------------------------------------------------------------+
         | stkcd   year        lon1        lat1        lon2        lat2      wanted |
         |--------------------------------------------------------------------------|
      1. |     2   2007   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      2. |     2   2008   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      3. |     2   2009   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      4. |     2   2010   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      5. |     2   2011   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      6. |     2   2012   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      7. |     2   2013   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      8. |     2   2014   114.06875   22.573589   113.97927   22.562049   9.2903548 |
      9. |     2   2015   114.06875   22.573589   113.97927   22.562049   9.2903548 |
     10. |     2   2016   114.06875   22.573589   113.97927   22.562049   9.2903548 |
     11. |     2   2017   114.06875   22.573589   114.07018   22.552655   2.3229013 |
     12. |     2   2018   114.06875   22.573589   114.07018   22.552655   2.3229013 |
     13. |     2   2019   114.06875   22.573589   114.07018   22.552655   2.3229013 |
     14. |     2   2020   114.06875   22.573589   114.07018   22.552655   2.3229013 |
         |--------------------------------------------------------------------------|
     15. |     4   2007   114.05412   22.556835   114.05733    22.54277   1.5922887 |
     16. |     4   2008   114.05412   22.556835   114.05733    22.54277   1.5922887 |
     17. |     4   2009   114.05412   22.556835   114.05733    22.54277   1.5922887 |
     18. |     4   2010   114.05412   22.556835   114.05733    22.54277   1.5922887 |
     19. |     4   2011   114.05412   22.556835   114.05733    22.54277   1.5922887 |
     20. |     4   2012   114.05412   22.556835   114.05733    22.54277   1.5922887 |
         +--------------------------------------------------------------------------+
    Last edited by Andrew Musau; 14 Nov 2021, 04:14.

    Comment


    • #3
      Dear Andrew, Thanks for this helpful suggestion.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X