Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: create unique random number variable
From
[email protected] (Brendan Halpin)
To
[email protected]
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:[email protected] 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/