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]

st: generating random numbers without replacement


From   Michael McCulloch <mm@pinestreetfoundation.org>
To   statalist@hsphsun2.harvard.edu
Subject   st: generating random numbers without replacement
Date   Fri, 24 May 2013 14:30:32 -0700

Hello,
I wish to generate random numbers between 1 and 5, without replacement. I have located the following Mata code, but have not yet learned Mata. Is it possible to rewrite this to create the variable a?

mata
a=J(100,1,.)
for(i=1;i<=100;i++) a[i,1]=i
a=a,runiform(100,1)
a=sort(a,2)
a
end

Best wishes,
Michael McCulloch, LAc MPH PhD

--
Pine Street Foundation, since 1989
124 Pine Street | San Anselmo | California | 94960-2674  
P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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