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 <[email protected]> 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/