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 at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: sampling with replacement


From   "Alok K. Bohara" <bohara@unm.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: sampling with replacement
Date   Mon, 4 Feb 2013 05:38:57 +0000

Thanks Joerg.   


Alok K. Bohara,
UNM


________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Joerg Luedicke [joerg.luedicke@gmail.com]
Sent: Friday, January 25, 2013 9:05 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: sampling with replacement

One possibility could be:

*------------------------------
mat swr = J(100,2,.)
mat colnames swr = ndraw draw

clear
set obs 4
gen x4 = _n*10+1

forval i = 1/100 {
        cap drop u
        gen u = runiform()
        sort u
        loc d = x4[1]
        mat swr[`i',1] = `i'
        mat swr[`i',2] = `d'
}

mat li swr
*------------------------------

But have a look at Bill Gould's nice blog postings on random number
generation in Stata, especially part 3:

http://blog.stata.com/2012/08/29/using-statas-random-number-generators-part-3-drawing-with-replacement/


Joerg


On Fri, Jan 25, 2013 at 10:30 AM, Alok K. Bohara <bohara@unm.edu> wrote:
> Hello:
>
> How can I use stata to draw a sample with replacement?
>
> I have 4 tokens marked;   X4: (11, 21, 31, 41).  Say, I want to draw it randomly (with replacement) 100 times, and store (and save) them as a vector of X100.
>
> Thanks
> Alok Bohara
> UNM
>
> *
> *   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/



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