Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: create unique random number variable


From   brendan.halpin@ul.ie (Brendan Halpin)
To   statalist@hsphsun2.harvard.edu
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
similar). 

Brendan
-- 
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
mailto:brendan.halpin@ul.ie    ULSociology on Facebook: http://on.fb.me/fjIK9t
http://teaching.sociology.ul.ie/bhalpin/wordpress         twitter:@ULSociology
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index