I'm trying to use geonear to identify the nearest neighbors within a dataset at the household-day level.

I've got longitude with a level of precision ranging between the 4-6 decimal place. I've got latitude to the 6th decimal place always.

I ran a do-file, which produces the six nearest neighbors, four times. The first two times I ran it, they produced the same results. The second two times I ran it they varied in the final neighbor identification.

Is there a place where I can expect this type of variation in output to occur? Is it less likely if I specify a within()?

For what it is worth, here is my code.

Code:
preserve

rename hhd_id nbor_index
sort nbor_index, stable
tempfile nbor
save `nbor'

restore

sort hhd_id, stable
geonear hhd_id lat lon using `nbor', n(nbor_index lat lon) ign wide near(6)