Announcement

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

  • Matching coordinates to NUTS regions

    Dear All,

    I need to match some coordinates to NUTS regions. An example of data is reported below:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(_Y _X)
    48.57238 13.521522
    51.18266  4.280047
    50.87523   2.82095
       50.75      5.25
    51.46054  4.773229
       50.75      4.25
    51.12978 3.7325006
    51.11182  5.639076
    51.17033  5.223158
    50.80076  3.295098
    51.50127   4.77865
      51.223  4.747021
    51.15796  3.246377
    51.09604 2.8189075
    49.75336  5.662157
    50.35294  6.161546
    50.26442  5.735323
    50.70091   5.71087
    50.27581  4.296569
    49.97693  4.347059
    end
    I generated stata files from a shapefile of European regions, i.e. NUTS_RG_01M_2013_shp and NUTS_RG_01M_2013. Then I use:

    Code:
    geoinpoly _Y _X using Data\NUTS_RG_01M_2013_shp, unique
    merge m:1 _ID using "Data\NUTS_RG_01M_2013"
    Surprisingly, I cannot get any match

    Code:
    . merge m:1 _ID using "Data\NUTS_RG_01M_2013"
    
        Result                      Number of obs
        -----------------------------------------
        Not matched                           340
            from master                        20  (_merge==1)
            from using                        320  (_merge==2)
    
        Matched                                 0  (_merge==3)
        -----------------------------------------
    I have been using the same files to match other data and it worked perfectly. Furthermore, if I check the coordinates manually, I can locate them into regions that are surely in the used data NUTS_RG_01M_2013.

    Any help you may provide would be extremely useful.

    Best

    Dario


  • #2
    geoinpoly is from SSC, as you are asked to explain (FAQ Advice #12).

    I have been using the same files to match other data and it worked perfectly. Furthermore, if I check the coordinates manually, I can locate them into regions that are surely in the used data NUTS_RG_01M_2013.
    By using the -unique- option of geoinpoly, you have been lucky that the kept _IDs have been among the list of _IDs in the NUTS dataset. This time, that's not the case. Just match the _IDs and then enforce uniqueness thereafter.

    Code:
    clear
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(_Y _X)
    48.57238 13.521522
    51.18266  4.280047
    50.87523   2.82095
       50.75      5.25
    51.46054  4.773229
       50.75      4.25
    51.12978 3.7325006
    51.11182  5.639076
    51.17033  5.223158
    50.80076  3.295098
    51.50127   4.77865
      51.223  4.747021
    51.15796  3.246377
    51.09604 2.8189075
    49.75336  5.662157
    50.35294  6.161546
    50.26442  5.735323
    50.70091   5.71087
    50.27581  4.296569
    49.97693  4.347059
    end
    
    geoinpoly _Y _X using "NUTS_RG_01M_2013_shp.dta"
    merge m:1 _ID using "NUTS_RG_01M_2013.dta", keep(master match) nogen
    bys _Y _X (NUTS_ID): keep if _n==_N
    Res.:

    Code:
    . l, sep(0)
    
         +--------------------------------------------------------------------------------------------------------+
         |       _Y         _X   _ID         _CX         _CY   NUTS_ID   STAT_L~_      SHAPE_AREA       SHAPE_LEN |
         |--------------------------------------------------------------------------------------------------------|
      1. | 48.57238   13.52152    28   13.965244   48.137106      AT31          2   1.44816965541   9.05992138981 |
      2. | 49.75336   5.662157    99   5.5135181   49.961698      BE34          2   0.55906176038   5.29974091702 |
      3. | 49.97693   4.347059    81   3.9591946   50.469705      BE32          2   0.48233510434   6.58550285784 |
      4. | 50.26442   5.735323    93   5.7364932   50.520485      BE33          2   0.48931586862   5.45486444456 |
      5. | 50.27581   4.296569    81   3.9591946   50.469705      BE32          2   0.48233510434   6.58550285784 |
      6. | 50.35294   6.161546    93   5.7364932   50.520485      BE33          2   0.48931586862   5.45486444456 |
      7. | 50.70091    5.71087    93   5.7364932   50.520485      BE33          2   0.48931586862   5.45486444456 |
      8. |    50.75       4.25    90   4.5905852    50.87273      BE24          2   0.27045113077   5.07494248323 |
      9. |    50.75       5.25    43    5.429272   50.991386      BE22          2   0.31061510108   4.13543385490 |
     10. | 50.80076   3.295098    69    3.057505    51.01164      BE25          2   0.40624553343   3.81836317041 |
     11. | 50.87523    2.82095    69    3.057505    51.01164      BE25          2   0.40624553343   3.81836317041 |
     12. | 51.09604   2.818907    69    3.057505    51.01164      BE25          2   0.40624553343   3.81836317041 |
     13. | 51.11182   5.639076    43    5.429272   50.991386      BE22          2   0.31061510108   4.13543385490 |
     14. | 51.12978   3.732501    62   3.8166761   51.036484      BE23          2   0.38556706193   4.24719556979 |
     15. | 51.15796   3.246377    69    3.057505    51.01164      BE25          2   0.40624553343   3.81836317041 |
     16. | 51.17033   5.223158    39   4.7199705   51.229475      BE21          2   0.36967018325   4.09575864710 |
     17. | 51.18266   4.280047    62   3.8166761   51.036484      BE23          2   0.38556706193   4.24719556979 |
     18. |   51.223   4.747021    39   4.7199705   51.229475      BE21          2   0.36967018325   4.09575864710 |
     19. | 51.46054   4.773229    39   4.7199705   51.229475      BE21          2   0.36967018325   4.09575864710 |
     20. | 51.50127    4.77865    39   4.7199705   51.229475      BE21          2   0.36967018325   4.09575864710 |
         +--------------------------------------------------------------------------------------------------------+

    Comment


    • #3
      Andrew Musau Thanks a lot. It worked fine. In my dataset, I was not able to match just 4 or 5 coordinates, but this is just something I can do quickly-

      Comment

      Working...
      X