Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Sampling with replacement or bootstrapping in Mata


From   Michael Manti <[email protected]>
To   [email protected]
Subject   Re: st: Sampling with replacement or bootstrapping in Mata
Date   Fri, 04 Nov 2005 11:13:38 -0500

On Friday, November 04, 2005, at 10:40AM, Vince Wiggins, StataCorp <[email protected]> wrote:

>Michael Manti <[email protected]> answered his own question about how to sample
>with replacement (i.e., bootstrap sample) a vector in Mata.  As he shows, a
>three line Mata function will accomplish the task,
>
>        real vector sample(real vector x) {
>                real scalar n
>                n = length(x)
>                return(x[ceil(n * uniform(n, 1))])
>        }
>
>Moreover, the line declaring n, -real scalar n-, is not required, but is good
>programming practice.  Michael's solution is close to one suggested by Scott
>Merryman <[email protected]> a few weeks ago.
>
>Referring to Bill Gould's <[email protected]> comment that the "process is not
>easy [...]", Michael asks,
>
>> Bill, your comment makes me think that I've missed some subtlety of
>> either random number generation or sampling or both. [...]
>
>Just to reassure, Michael, you have missed nothing.  Your solution is both
>elegant and correct.  Bill was thinking about what is required in Stata to
>implement sampling with replacement, specifically that an expansion of the
>vector (data) is required after selecting the replicates and counting the
>number of times to replicate each.  He simply had not hit upon how easily this
>can be avoided in Mata.
>
>
>-- Vince
>   [email protected]
>
>*
>*   For searches and help try:
>*   http://www.stata.com/support/faqs/res/findit.html
>*   http://www.stata.com/support/statalist/faq
>*   http://www.ats.ucla.edu/stat/stata/
>
>

Vince,

Thank you for the reassurance and the clarification. I missed Scott Merryman's solution in my search of the statalist archives.

BTW, I'm pretty new to both Stata and Mata, and I'm quite enjoying both. The combination of the two really hits a sweet spot in richness of functionality, ease of use, and power of extensibility that other statistical software misses.

Michael Manti
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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