Announcement

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

  • Identifying country from latitude and longitude

    Hi,

    I am trying to identify the country from a latitude and longitude in Stata.
    I tried to install the package geocode3, which apparently did the job.
    Unfortunately it seems to be unavailable.
    Does anyone know any alternatives?

    Thanks in advance,
    Thiago

  • #2
    You can use geoinpoly (from SSC) to identify in which country each point (lat,lon) is located. You will need a suitable shapefile of the world. You can get such a shapefile by downloading the ancillary datasets of the geo2xy (from SSC) package to Stata's current directory using:

    Code:
    net get geo2xy, from("http://fmwww.bc.edu/repec/bocode/g")
    Here's a quick example that locates the country for the following universities:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 university double(lat lon)
    "U of M"     42.276933 -83.738204
    "MIT"        42.359758 -71.092064
    "Sorbonne"   48.848527   2.343494
    "Pompeu Fab" 41.378946   2.179807
    end
    
    geoinpoly lat lon using "geo2xy_world_coor.dta"
    
    merge m:1 _ID using "geo2xy_world_data.dta", ///
        keep(master match) keepusing(geounit) nogen
    
    list
    and the results
    Code:
    . list
    
         +----------------------------------------------------------------------+
         | university         lat          lon   _ID                    geounit |
         |----------------------------------------------------------------------|
      1. | Pompeu Fab   41.378946     2.179807    50                      Spain |
      2. |   Sorbonne   48.848527     2.343494    56                     France |
      3. |        MIT   42.359758   -71.092064   169   United States of America |
      4. |     U of M   42.276933   -83.738204   169   United States of America |
         +----------------------------------------------------------------------+
    
    .

    Comment


    • #3
      Thank you for your answer, it works perfectly!

      Comment

      Working...
      X