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

Re: st: RE: how can I tell Stata to draw many random samples without replacement (2)


From   Alejandro Delafuente <[email protected]>
To   [email protected]
Subject   Re: st: RE: how can I tell Stata to draw many random samples without replacement (2)
Date   Tue, 20 Sep 2005 10:05:18 +0100 (BST)

Many many thanks for all your insights Clive, Scott and Steven. In the coming 
days I will be working more on this issue and will keep you posted on further 
details.
Alejandro
In message <[email protected]> 
[email protected] writes:
> 
> To avoid a lot of output, add "quietly" to the first "forvalues" 
> statement.
> 
> Here's another way:
> 
> /* draw 'nsamps' random samples of size 'sampsize' from a population of 
> size 'popsize */
> set more off
> capture log close
> log using rsamp, text replace
> 
> clear
> set seed  234568888
> 
> local sampsize  3
> local popsize   5
> local nsamps    2
> 
> quietly forvalues j=1/`nsamps' {
>       clear
>       set obs `popsize'    // population size
>       tempfile t`j'
>       gen pick=_n
>       gen u=uniform()
>       sort u
>       keep in 1/`sampsize'
>       gen sample=`j'
>       save "`t`j''"
> }
> 
> use "`t1'"
> 
> forvalues j=2/`nsamps' {
>      append using "`t`j''"
> }
> label var pick "Obs Number to Pick"
> 
> sort pick
> drop u
> save d01, replace
> 
> 
> 
> 
> 

-- 
Alejandro de la Fuente
QEH/Department of International Development
Oxford University
*
*   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