Hello,

I am trying to use geoinpoly to extract countries from coordinates. I am using the 'PDSI - Monthly Mean: self-calibrated' data from NOAA, which can be found here: https://psl.noaa.gov/data/gridded/data.pdsi.html#detail. I then use Panoply.exe to extract the netcdf file to a .csv file, which is then imported into stata and has a pair of latitude and longitude coordinates. I keep only the coordinates where the key variable (pdsi) is not missing.

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double date float(lat lon pdsi)
4.733856e+11 -53.75 -73.75  -.8622768
4.733856e+11 -53.75 -71.25  -4.905787
4.733856e+11 -53.75 -68.75  -2.884902
4.733856e+11 -53.75 -66.25  -.5601953
4.733856e+11 -51.25 -73.75  -.6036547
4.733856e+11 -51.25 -71.25  -3.588632
4.733856e+11 -51.25 -58.75 -1.3314766
4.733856e+11 -48.75 -76.25  -.1892304
4.733856e+11 -48.75 -73.75 -.56877613
4.733856e+11 -48.75 -71.25 -2.1497626
4.733856e+11 -48.75 -68.75   -2.14897
4.733856e+11 -48.75 -66.25 -1.9930106
4.733856e+11 -48.75  68.75  -.3168081
4.733856e+11 -46.25 -76.25 -4.6985755
4.733856e+11 -46.25 -73.75  -5.249196
4.733856e+11 -46.25 -71.25 -3.9030654
4.733856e+11 -46.25 -68.75 -1.0852239
4.733856e+11 -46.25 166.25  -3.616439
4.733856e+11 -46.25 168.75 -3.9492075
4.733856e+11 -43.75 -73.75    -5.1826
4.733856e+11 -43.75 -71.25 -4.5318255
4.733856e+11 -43.75 -68.75  -2.567297
4.733856e+11 -43.75 -66.25 -1.0807338
4.733856e+11 -43.75 146.25   2.757163
4.733856e+11 -43.75 168.75  -.8358558
4.733856e+11 -43.75 171.25 -1.3733033
4.733856e+11 -43.75 173.75  2.0661316
4.733856e+11 -41.25 -73.75  -3.731872
4.733856e+11 -41.25 -71.25  -2.983261
4.733856e+11 -41.25 -68.75  1.4202592
4.733856e+11 -41.25 -66.25  1.3901818
4.733856e+11 -41.25 -63.75   .7631465
4.733856e+11 -41.25 143.75  2.2810497
4.733856e+11 -41.25 146.25   2.860601
4.733856e+11 -41.25 171.25  -1.000528
4.733856e+11 -41.25 173.75  1.5783185
4.733856e+11 -41.25 176.25 -1.3318152
4.733856e+11 -38.75 -73.75  -3.987925
4.733856e+11 -38.75 -71.25 -2.2837498
4.733856e+11 -38.75 -68.75   2.637683
4.733856e+11 -38.75 -66.25    3.00341
4.733856e+11 -38.75 -63.75   .8945818
4.733856e+11 -38.75 -61.25  .07772385
4.733856e+11 -38.75 -58.75 -2.3103743
4.733856e+11 -38.75 141.25  1.9664747
4.733856e+11 -38.75 143.75   -.532143
4.733856e+11 -38.75 146.25  2.3114488
4.733856e+11 -38.75 148.75   3.021299
4.733856e+11 -38.75 173.75  -.9413062
4.733856e+11 -38.75 176.25  -.7882169
4.733856e+11 -36.25 -73.75 -3.6424384
4.733856e+11 -36.25 -71.25 -1.7606176
4.733856e+11 -36.25 -68.75   2.042183
4.733856e+11 -36.25 -66.25  1.9240352
4.733856e+11 -36.25 -63.75  1.0326267
4.733856e+11 -36.25 -61.25  .11875542
4.733856e+11 -36.25 -58.75 -2.3584473
4.733856e+11 -36.25 136.25  2.1486964
4.733856e+11 -36.25 138.75   3.532063
4.733856e+11 -36.25 141.25   3.095695
4.733856e+11 -36.25 143.75   3.218915
4.733856e+11 -36.25 146.25  -.4469681
4.733856e+11 -36.25 148.75   2.965404
4.733856e+11 -36.25 173.75  -1.857902
4.733856e+11 -33.75 -71.25    .330117
4.733856e+11 -33.75 -68.75  1.1416228
4.733856e+11 -33.75 -66.25  1.5281847
4.733856e+11 -33.75 -63.75    .716531
4.733856e+11 -33.75 -61.25  -2.745389
4.733856e+11 -33.75 -58.75  -2.730287
4.733856e+11 -33.75 -56.25 -1.8756796
4.733856e+11 -33.75 -53.75 -2.0038304
4.733856e+11 -33.75  18.75   3.066416
4.733856e+11 -33.75  21.25   .4042225
4.733856e+11 -33.75  23.75 -.51310474
4.733856e+11 -33.75  26.25   3.193037
4.733856e+11 -33.75  28.75  -1.773607
4.733856e+11 -33.75 116.25 -1.5471634
4.733856e+11 -33.75 118.75  -.2362924
4.733856e+11 -33.75 121.25  -2.767646
4.733856e+11 -33.75 123.75 -1.6566436
4.733856e+11 -33.75 133.75 -.06925482
4.733856e+11 -33.75 136.25  -.2209172
4.733856e+11 -33.75 138.75   .3293644
4.733856e+11 -33.75 141.25  .09760648
4.733856e+11 -33.75 143.75   .1191175
4.733856e+11 -33.75 146.25   3.368574
4.733856e+11 -33.75 148.75  -.8078451
4.733856e+11 -33.75 151.25  -.9469776
4.733856e+11 -31.25 -71.25 -.22133857
4.733856e+11 -31.25 -68.75  2.0080686
4.733856e+11 -31.25 -66.25  1.6745914
4.733856e+11 -31.25 -63.75  1.4677007
4.733856e+11 -31.25 -61.25  -.3303558
4.733856e+11 -31.25 -58.75 -1.0560408
4.733856e+11 -31.25 -56.25  -.5111065
4.733856e+11 -31.25 -53.75  -.9953581
4.733856e+11 -31.25 -51.25  -.9996645
4.733856e+11 -31.25  16.25  -.2985082
4.733856e+11 -31.25  18.75   2.862094
end
format %tc date
I then use geoinpoly to extract countries from coordinates with the TM_WORLD_BORDERS-0.3 shapefile. The countries of interest are Australia, Belgium , Canada, Switzerland, Germany, Denmark, Finland, France, United Kingdom, Greece, Israel, Japan, Netherlands, New Zealand, Portugal, Brazil, Chile, China, Indonesia, India, South Korea, Mexico, Malaysia, Peru, Phillipines, Poland, Russia, Thailand, Turkey, and South Africa.

There are results for all countries except for Netherlands, which is a key country in my dataset. I am wondering if it is a problem with overlapping polygons and how to fix this? I have shown a picture below which was created in QGIS. The shaded squares represent the pdsi datapoints from the netcdf file and the colored map is the shapefile. As you can see, the squares around the Netherlands are not completely within the country's borders. However, I think these points should still be considered as a data point within the Netherlands. Additionally, most of the pdsi data points per country do not match the original sample I am trying to recreate, so I am not sure what to do. Any help or guidance on this issue would be greatly appreciated.

Array