# Re: st: Re: bysort problem

 From "Sergiy Radyakin" To Subject Re: st: Re: bysort problem Date Mon, 26 Feb 2007 18:01:20 +0100

Is there a guarantee, that var2+c(epsfloat)*obs will be a unique value (will not overlap with the next value)? It is true in the example, but it is not a general case.

consider var1=0.5 and var2 equal to
c(epsfloat)
c(epsfloat)
c(epsfloat)
c(epsfloat)

This seems to be also a solution:
replace var2=var2+uniform()/100000

simply add a small random number (noise) to var2. Chances that there will be coincidences are also small, but they may not be ignored.

----- Original Message ----- From: "Austin Nichols" <austinnichols@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Monday, February 26, 2007 5:51 PM
Subject: Re: st: Re: bysort problem

```Nikolaos A. Patsopoulos--
No loop should be necessary, as this example demonstrates.  My guess
is that this exercise is also not necessary, but as your ultimate
desired outcome is not explicit, I cannot know if replacing values is
actually a good idea for you.

input var1 var2
.145 .14
.145 .15
.145 .15
.167 .15
1.89 .15
1.89 .16
1.89 .16
end
egen oldgroup=group(var1 var2)
bys var1 var2: gen obs=_n
replace var2=var2+c(epsfloat)*obs
egen newgroup=group(var1 var2)
li, noo clean

On 2/26/07, Nikolaos A. Patsopoulos <npatsop@cc.uoi.gr> wrote:
```
```The purpose of the code is to eliminate duplicate observations of var1 &
var2 (combination).
In the firest pass the algorithm fixes duplicates but new ones might
come-up, so it should run as long as noone is left. The correction is
too small for the real data (the ones here are dummy ones just to test
the code) and the possibility of duplicates very small but still present.

var2 is changed not var1. This was a mistake I made on earlier e-mail.
```
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
```*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```