Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Bootstrap resampling across a subset of data
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Bootstrap resampling across a subset of data
Date
Thu, 19 Sep 2013 13:31:56 +0200
On Thu, Sep 19, 2013 at 1:01 PM, George Murray wrote:
> I have 3 variables, Time / Var1 / Var2, with time going from t=1 to
> 100. Var1 has no missing observations, but Var2 only has observations
> from t=26 to t=75 inclusive.
>
> I want to create 1000 bootstrap samples (sample with replacement) of
> Var2 from t=26 to t=75 *only*, and create a new variable for each of
> the samples, which will contain 50 observations each. So for each of
> these bootstrap samples, there will be missing values at
> t=1,…,25,76,…,100; and t=26 to 75 will contain the draws from a given
> sample (with replacement) of the 50 non-missing observations in Var2.
You typically don't want to save the bootstrap samples, as for
bootstraping you only need to store the coefficients and storing those
is typically a lot more efficient. However, you can do it:
*------------------ begin example ------------------
clear
set obs 100
gen t = _n
gen x = rnormal() in 26/75
tempfile orig result
save `orig'
save `result'
forvalue i = 1/1000 {
use `orig'
bsample if x < .
replace t = _n + 25
rename x x`i'
merge 1:1 t using `result'
drop _merge
save `result', replace
}
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )
-- Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/