Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: create unique random number variable

From (Brendan Halpin)
Subject   Re: st: create unique random number variable
Date   Tue, 24 Apr 2012 11:08:22 +0100

On Tue, Apr 24 2012, raoul reulen wrote:

> I'm trying to generate a random number variable like this:
> .set seed 12345
> .gen x = int(1000*uniform())
> However, the random numbers in variable x are not unique. Is there a
> way to ensure they are unique?

set seed 12345
set obs 1000
gen x = _n
gen so = uniform()
sort so
drop so

That's one way; you will need to do it separately from the main data set
and merge it in afterwards (-merge 1:1 _n using randomnumber- or

Brendan Halpin,   Department of Sociology,   University of Limerick,   Ireland
Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-009 x 3147    ULSociology on Facebook:         twitter:@ULSociology
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index