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

st: Generating random samples, with replacement


From   Elaine Thomas <[email protected]>
To   [email protected]
Subject   st: Generating random samples, with replacement
Date   Fri, 25 Feb 2005 15:12:04 +0000

Hi
I am trying to write a routine to apply a step-wise logistic modelling procedure to a number of samples from a core data set. I want the samples to be the same size as the original and be sampled with replacement. I know that bs and bstrap will perform bootstrapping on the coefficients of a standard logistic model, but I want to perform a step-wise procedure within each sample, rather than pre-define the model. How can I get Stata to produce, say, 200 random samples from my original data that I can then call on in a later program?

So far I have worked out how to reproduce a standard logistic model (logistic y x1 x2) and take the coefficients and then using forvalues (with dummy data) to move through my samples of data (bs1.dta, bs2.dta etc), each time adding the coefficients (_b[x1] _b[x2]) to a new datafile (t) as below

postfile `sort' x1 x2 using t, replace
forvalues i = 1(1) `n'{
use bs`i'.dta
logistic y x1 x2
post `sort' (exp(_b[x1])) (exp(_b[x2]))

I am building this process up as I dont do much programming. What i really want to do next is to generate the random samples within this loop, rather than having to have the datasets already formed and call on them. So I dont want not to use bstrap to bootstrap the coefficients, I want to be able to get it (or something akin to it) to generate random samples for me.

Any help, even knowing how to generate random samples, with replacement, that I can store as separate datasets would be helpful
Ta
Elaine

--
Dr Elaine Thomas
Lecturer in Biostatistics
Primary Care Sciences Research Centre
Keele University
North Staffordshire
ST5 5BG

Telephone : + 44(0)1782 583924
Fax : + 44(0)1782 583911 Email : [email protected]




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