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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Thu, 26 Feb 2009 20:46:35 +0100 |

<> -set seed- to get one @ obs no 4 ************* clear input x 1 2 3 4 5 6 7 8 9 10 end set seed 100173 gen y = x[round(_N*uniform(),1)+1] l ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Jeph Herrin Gesendet: Donnerstag, 26. Februar 2009 20:41 An: statalist@hsphsun2.harvard.edu Betreff: Re: AW: st: random draw of single variable, not whole data You're right about the missings; I didn't get any but I could have. Maybe gen y = x[ceil(_N*uniform())] as long as uniform() never returns precisely 0, which I've never seen - can it? But certainly there's no reference to the values that x takes; a random observation number is generated in (1,...,_N) and y is set equal to that observation on x. So yes, it handles whatever x looks like, I'm merely sampling from the list of observation numbers. J Martin Weiss wrote: > <> > > > Your "with replacement" method leads to missings every now and then. Apart > from that, if Florian had an irregularly spaced list of numbers to sample > from, which also need not be integers, would your method be capable of > handling that? > > > > HTH > Martin > > > -----Ursprüngliche Nachricht----- > Von: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Jeph Herrin > Gesendet: Donnerstag, 26. Februar 2009 20:20 > An: statalist@hsphsun2.harvard.edu > Betreff: Re: st: random draw of single variable, not whole data > > > 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 > > > Florian Wakolbinger wrote: >> Dear all, >> >> is it possible to randomly draw numbers out of a variable x and write it >> into another variable y >> >> i.e. if >> >> x >> 1 >> 2 >> 3 >> 4 >> 5 >> >> then y could be, for instance >> >> y >> 3 >> 5 >> 3 >> 2 >> 4 >> >> all numbers in y are randomly drawn from x. how is it possible to >> construct such a variable y in stata? >> >> thanks, and kind regards >> florian >> >> * >> * 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/ > > > * > * 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/ * * 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/

**References**:**st: random draw of single variable, not whole data***From:*Florian Wakolbinger <wakolbinger@drei-e.at>

**Re: st: random draw of single variable, not whole data***From:*Jeph Herrin <junk@spandrel.net>

**AW: st: random draw of single variable, not whole data***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: AW: st: random draw of single variable, not whole data***From:*Jeph Herrin <junk@spandrel.net>

- Prev by Date:
**Re: AW: st: random draw of single variable, not whole data** - Next by Date:
**Re: st: 64-bit Stata for Mac now available** - Previous by thread:
**Re: AW: st: random draw of single variable, not whole data** - Next by thread:
**Re: st: random draw of single variable, not whole data** - Index(es):

© Copyright 1996–2022 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |