Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: bysort problem

From   "Austin Nichols" <>
Subject   Re: st: Re: bysort problem
Date   Mon, 26 Feb 2007 12:22:17 -0500

Sergiy Radyakin--
Yes, there is a guarantee of the type you desire.  By construction,
obs ranges from 1 to the number of observations to be made distinct.
Thus a different number will be added to each obs.  Your solution of
adding noise is not guaranteed to work, but would fail with a small

The numbers added are intended to be small enough to have a negligible
effect on the mean of var2 in almost all cases, though the technique
could be improved on for the somewhat implausible limiting cases:

bys var1 var2: gen obs=_n-(_N+1)/2
replace var2=var2+c(epsfloat)*obs

On 2/26/07, Sergiy Radyakin <> wrote:
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

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.
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index