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 (2)


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   st: RE: how can I tell Stata to draw many random samples without replacement (2)
Date   Mon, 19 Sep 2005 13:00:14 -0400


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








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