Hello!
I am working with the household survey with the Household Geocodes displaced at 10km buffer and an external shapefile. I converted a shapefile from a raster file using QGIS and also used a stata command “shp2dta” to convert the shapefile into dta files. I would like to march the information stored in the variable “DN” to the nearest household. I understand that the command “geonear” can be used to calculate the nearest distance and then merge the data.

However, I am facing some difficulty in executing the task.
(1) One when I merge the file tz_data(shp) and tz_coordinates created by shp2dta file a lot of missing is generated.

(2) If I try to use the command “geonear ea_id lat_modified lon_modified using "Tz_coordinates.dta", n(_ID _X _Y)” the following error appears: “lat_modified or lon_modified not constant within ea_id group”. I also tried to use “geoinpoly lat_dd_mod lon_dd_mod using "Tanzania_coordinates.dta” command stata gives me the following error: Y (latitude) must be between -90 and 90 in coordinates file.
Could you please assist me on how I can go about it?.

Here is the sample of the data that I am using: The first and second is the shapefile and database file generated by “shp2dta”. and the last codes is for the household survey data.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long _ID double _X
1                  .
1 -647509.5603336413
1 -647259.5711087444
1 -647259.5711087444
1 -647509.5603336413
1 -647509.5603336413
2                  .
2 -646009.6249842601
2 -645759.6357593632
2 -645759.6357593632
2 -646009.6249842601
2 -646009.6249842601
3                  .
3 -637260.0021128698
3 -636760.0236630761
3 -636760.0236630761
3 -637260.0021128698
3 -637260.0021128698
4                  .
4 -636010.0559883855
4 -635260.0883136949
4 -635260.0883136949
4 -636010.0559883855
4 -636010.0559883855
5                  .
5 -633010.1852896231
5 -632760.1960647262
5 -632760.1960647262
5 -633010.1852896231
5 -633010.1852896231
end

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long _ID byte DN
 1 51
 2 51
 3 22
 4 22
 5 51
 6 44
 7 44
 8 51
 9 51
10 51
11 58
12 58
13 32
14 58
15 69
16 29
17 51
18 58
19 44
20 25
21 58
22 58
23 58
24 58
25 76
26 76
27 69
28 58
29 58
30 58
end






Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 y3_hhid double(lat_dd_mod lon_dd_mod) int(crops01 crops02)
"0001-001" -5.08575059837 35.8543891943 557 370
"0002-001" -5.08575059837 35.8543891943 557 370
"0003-001" -5.08575059837 35.8543891943 557 370
"0003-010" -6.86088773309 39.2519840813 756 458
"0005-001" -5.08575059837 35.8543891943 557 370
"0006-001" -5.08575059837 35.8543891943 557 370
"0007-001" -5.08575059837 35.8543891943 557 370
"0008-001" -5.08575059837 35.8543891943 557 370
"0009-001" -5.08575059837 35.8543891943 557 370
"0010-001" -6.45661888376 36.7228609724 619 442
"0011-001" -6.45661888376 36.7228609724 619 442
"0011-004" -6.40602581971 36.8375470998 645 429
"0012-001" -6.45661888376 36.7228609724 619 442
"0013-001" -6.45661888376 36.7228609724 619 442
"0014-001" -6.45661888376 36.7228609724 619 442
"0014-007" -6.45661888376 36.7228609724 619 442
"0015-001" -6.98727510065 36.8989578038 646 430
"0016-001" -6.45661888376 36.7228609724 619 442
"0017-001" -6.45661888376 36.7228609724 645 429
"0018-001" -6.45661888376 36.7228609724 621 435
"0019-001"  -6.6140094868  36.508662736 539 397
"0019-003"  -6.6140094868  36.508662736 539 397
"0020-001" -6.65111878938  36.385741194 524 388
"0021-001"  -6.6140094868  36.508662736 539 397
"0022-001"  -6.6140094868  36.508662736 539 397
"0023-001"  -6.6140094868  36.508662736 539 397
"0024-001"  -6.6140094868  36.508662736 539 397
"0025-001" -6.71165256022 38.7421347251 828 533
"0026-001"  -6.6140094868  36.508662736 539 397
"0027-001"  -6.6140094868  36.508662736 539 397
end