Bookmark and Share

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: select three non-identical random elements


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: select three non-identical random elements
Date   Thu, 4 Apr 2013 11:09:33 +0100

-levelsof- is a command, not a macro. See e.g.

http://www.stata.com/statalist/archive/2008-08/msg01258.html

Here's an example of one way to do it.

sysuse auto
egen tag = tag(rep78)
sort tag
levelsof rep78 in -3/L

You might well want to introduce more randomness that you could control.

If this problem arose again and again for me, and no one suggested a
better solution, I'd write a Mata-based command.
Nick
[email protected]


On 4 April 2013 10:42, Tomáš Houška <[email protected]> wrote:
> Dear Statalist,
>
> I have list of items create by -levelsof- macro and I would like to select
> three items from that list at random and for them to be non-repetitive
> (i.e. each one can appear only once in the selection).
>
> Lets say I have a list -local list "one two three four five six"- and I
> would like to get
> local random1 =
> local random2 =
> local random3 =
>
> where each one is a random selection from the local list and each item
> appears at max once.
> I would appreciate any help on how to do that.
>
> Thank you!
> Tomas
> *
> *   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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index