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   Steven Samuels <ssamuels@albany.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: how can I tell Stata to draw many random samples without replacement
Date   Mon, 19 Sep 2005 12:32:24 -0400

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

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'"
list
forvalues j=2/`nsamps' {
append using "`t`j''"
}

sum
sort pick
drop u
save d01, replace








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