Statalist The Stata Listserver


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

RE: st: Subsample Bootstrap


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: Subsample Bootstrap
Date   Fri, 20 Jan 2006 21:40:19 +0000 (GMT)

Tim R. Sass was estimating a model that took long to run when estimated on a large number of
observations, but a lot faster on a portion of his data. He wanted to use the bootstrap in order
to get standard errors, but this was not feasable for the entire sample. I suggested that he
partitioned the data and estimate his model and bootstraped s.e.s on each partition, and combine
the results using meta analysis techniques. I did not rember the formulas, but now I looked them
up. Each estimate gets a weight of 1/(se^2), and the combined estimate is a weighted mean using
those weigths. The combined s.e. is sqrt(1/sum(weights)). I have writen some example code below
that implements it. 

HTH,
Maarten  

*----------begin example------------------
capture drop _all
set mem 20m
set more off
cd c:\temp

/*devide dataset in 10 parts*/
forvalues i = 1/10 {
	sysuse citytemp, clear
	local j = `i'-1
	set seed 12345
	gen rand = 10*uniform()
	keep if rand <`i' & rand >= `j'
	save part`i'.dta, replace
}

/*do a bootstrap on each part and store the results*/
tempname memhold
tempfile results
postfile `memhold' b se using `results'

forvalues i = 1/10 {
	quietly {
		use part`i'.dta, clear
		bootstrap "reg tempjan tempjuly" _b, reps(1000)
	        post `memhold' (_b[b_tempjuly]) (_se[b_tempjuly])
		erase part`i'.dta 
	}
}
postclose `memhold'
use `results', clear

/*show the results of partial datasets*/
list

/*combine estimates*/
/*notice that the se is a lot smaller*/
gen w = 1/se^2
sum b [aweight=w]
di sqrt(1/r(sum_w))

/*do the bootstrap on the entire dataset*/
/*notice that the se is close to the combined estimate*/
sysuse citytemp, clear
bootstrap "reg tempjan tempjuly" _b, reps(1000)
*---------------end example-------------------------


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
*
*   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–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index