[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"David Harrison" <david.harrison@icnarc.org> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Generating random samples, with replacement |

Date |
Fri, 25 Feb 2005 15:28:06 -0000 |

To just draw a single bootstrap sample, the command is -bsample-. I find the -weight()- option to -bsample- can be a very useful thing to speed up these procedures - this stores the bootstrap sample using frequency weights rather than replacing the data in memory, e.g. gen bsw=. forvalues i=1/10 { bsample, weight(bsw) logistic y x1 x2 [fw=bsw] } David -----Original Message----- From: Elaine Thomas [mailto:e.thomas@cphc.keele.ac.uk] Sent: 25 February 2005 15:12 To: statalist@hsphsun2.harvard.edu Subject: st: Generating random samples, with replacement 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 : e.thomas@keele.ac.uk * * 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/ * * 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/

- Prev by Date:
**Re: st: two-way error component model** - Next by Date:
**RE: st: Calling a scalar within a command.** - Previous by thread:
**st: Generating random samples, with replacement** - Next by thread:
**st: Upcoming NetCourses** - Index(es):

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