Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: local bootstrapping

From   Maarten Buis <>
Subject   Re: st: local bootstrapping
Date   Thu, 4 Oct 2012 10:04:31 +0200

On Wed, Oct 3, 2012 at 8:14 PM, Benjamin Villena wrote:
> I am trying to perform a local bootstrapping procedure that is as follows
> - Consider a bandwidth b
> - For every observation x=x0  in the sample, draw a random observation in the interval [x0-b,x0+b]
> - Label this draw x0=x0j and estimate a model reg y x0j
> - Repeat the procedure M times and compute average estimator, sd, and confidence intervals.

Here is how I would start such a project. I would than worry about the
observations that are at the corners such that  x0-b or x0+b are
outside the range of the data. Also I assumed that all observations
are equally far apart and that there are no gaps.

*-------------------------- begin example -----------------------
clear all

program define mydraw
    qui {
        drop _all
        set obs 245
        local b = 5
        gen obsno =  floor((`b'--`b' +1)*runiform() + (_n-`b'))
        tempfile todraw
        save `todraw'
        sysuse sp500
        sort date
        gen obsno = _n
        merge 1:m obsno using `todraw', keep(match) nogen

program define myboot
    tempname memhold
    tempfile results
    postfile `memhold' b cons using `results'
    nois _dots 0, title(Bootstrap) reps(`1')
    forvalues i = 1/`1' {
        capture {
            reg close volume
            post `memhold' (_b[volume]) (_b[_cons])
        noi _dots `i' `=_rc > 0'
    postclose `memhold'
    use `results', clear
    centile, centile(2.5 97.5)

myboot 1000

sysuse sp500, clear
reg close volume
*--------------------------- end example ------------------------
(For more on examples I sent to the Statalist see: )

Also see <>

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index