Statalist


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

AW: st: random draw of single variable, not whole data


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: random draw of single variable, not whole data
Date   Thu, 26 Feb 2009 21:01:55 +0100

<> 

"...0 with probability about 1 in 4 billion"

Out of curiosity, how do you calculate that for a continuous random
variable?



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Austin Nichols
Gesendet: Donnerstag, 26. Februar 2009 20:59
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: random draw of single variable, not whole data

Jeph suggests the ceil() solution in a follow-up with the caveat "as
long as uniform() never returns precisely 0, which I've
never seen" --uniform() is 0 with probability about 1 in 4 billion, so
to be safe you could

gen y = x[ceil(_N*(1-uniform()))]

On Thu, Feb 26, 2009 at 2:33 PM, Austin Nichols <austinnichols@gmail.com>
wrote:
> With replacement:
>  gen y = x[round(_N*uniform(),1)+1]
>
> should be
>  gen y = x[round(_N*uniform()+.5)]
> or
>  gen y = x[ceil(_N*uniform())]
>
> I think.... (otherwise you can get _N+1 in the square brackets, for a
> missing y, and the prob of getting y[1] is too low)
>
> On Thu, Feb 26, 2009 at 2:19 PM, Jeph Herrin <junk@spandrel.net> wrote:
>>
>> It's not clear if you want sampling with or without replacement.
>>
>> With replacement:
>>
>>  gen y = x[round(_N*uniform(),1)+1]
>>
>> without replacement:
>>
>>  egen index=rank(uniform())
>>  gen y = x[index]
>>
>> hth,
>> Jeph
>

*
*   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/


*
*   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   |   What's new   |   Site index