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

st: RE: how can I tell Stata to draw many random samples without replacement


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: how can I tell Stata to draw many random samples without replacement
Date   Sun, 18 Sep 2005 10:41:25 -0500

Here is one way using Mata's -jumble- function, see [M-5] sort()


clear
set seed 1234
set obs 100
gen byte S = cond( uniform()<.5 ==0,-1,1)

mata
S= st_data(.,"S")
rs=S
for (i =1; i <=10 ; i++) {
	rsi = jumble(rs)
	rs = rs, rsi
}
st_matrix("r(rs)",rs)
end
matrix rs = r(rs)
matrix rs = rs[., 2..11]
svmat rs

l in 1/10

Hope this helps,
Scott



> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Alejandro Delafuente
> Sent: Wednesday, September 14, 2005 12:49 PM
> To: [email protected]
> Subject: st: how can I tell Stata to draw many random samples without
> replacement
> 
> Dear statalisters, I have a probability distribution of a random variable
> with
> only two values [-1,1] each with the same density [0.5]. I would like to
> draw N
> number of random samples without replacement from my original sample S,
> such
> that each of these new samples keeps the existing balance of values only
> with
> different orderings. To illustrate the point:
> S    rs1     rs2    rs3
> 1     -1     -1      1
> -1    -1      1     -1
> -1     1     -1     -1
> 1      1      1      1
> Any thoughts on how to achieve this would be highly appreciated. Thanks.
> 


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