# repeat random sample from existing data

#### caveb003

##### New Member
Hi everyone,

I'm a novice with stata and am trying to figure out how to draw 2 sets of random samples from existing data 1000 times for a kind of quasi-simulation. The first set would just be a simple randomization; the second set has to be block-randomized. How do I do this?

#### bukharin

##### RoboStataRaptor
Sampling with or without replacement?
-help sample-
Or perhaps you want -help bootstrap- (or the related -bsample-)

#### caveb003

##### New Member
Sampling without replacement

#### bukharin

##### RoboStataRaptor
Okay, so -sample- it is.

Something like:
Code:
tempfile results // temporary file to store simulations
set seed 1 // ensures repeatable results
foreach simulation of 1/1000 {
preserve // preserves your original dataset
sample x // replace x with your sample %, or use the count option
gen group=rbinomial(1, 0.5) // randomises the sampled observations into two groups
(do your statistical procedure eg ttest y, by(group))
(+/- convert the results to a dataset)
gen simulation=simulation' // marks results with simulation #
capture append using results' // adds these results to the results dataset
save using results', replace
restore
}
use results', clear

Last edited:

#### bukharin

##### RoboStataRaptor
You may also want to investigate -simulate-