problem merging 1:1


New Member
Hello all,

I'm trying to merge two data sets. Data 1 contains the following variables: interview date, household longitude and latitude, cortisone level. (each row is a respondent).
Data 2 contains: longitude and latitude for entire country, rain levels by geographical coordinate from 2009 onwards. Temporal resolution is dekadal (10 days) so each month has 3 data points.

My goal is to merge the files together in order to determine the rainfall for each respondent in the 12 decads prior to interview data. I think that I need to do a 1:1 matched merge by longitude and latitude. Is this correct?

sort latitude longitude
merge 1:1 latitude longitude using "data2"
ERROR: variables latitude longitude do not uniquely identify observations in the master

Some of my troubleshoot ideas:
longitude and latitude in data 1 are stored as float variables at 9%g while
longitude and latitude in data 2 are stored as double variables at 10%g

I tried changing the format with the following code:
recast double longitude
recast double latitude
format longitude %10.0g
format latitude %10.0g

2.) longitude and latitude variables are rounded to .1 in data 2, while in data 1 they are rounded to several decimal places, so perhaps the variables cannot be matched due to the different precision levels? I tried changing the precision to .1 with the following code:
gen roundlongitude= round(longitude, .1)
gen roundlatitude= round(latitude, .1)
drop latitude
drop longitude
rename roundlatitude latitude
rename roundlongitude longitude

No success with those attempts. I'm not quite sure where I'm going wrong here, or if I'm even on the right track. Any help would be much appreciated! Thanks in advance.



TS Contributor
The household longitude and latitude will never match the country's longitude and lattitude. So that is never going to work. You will probably need to merge on country rather than longitude and latitude, which will probably mean a m:1 or 1:m merge.


New Member
Hi there. Thank you for the response.

Both data sets are only referring to 1 country, Kenya. And there is no country variable. The only variables are those I listed. I need to merge based on a common variable, right? The household longitude and lattitudes do match up to country lattitude and longitudes, the only problem is that they aren't rounded or stored in the same format.