Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: local bootstrapping


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
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
    }
end

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

myboot 1000

sysuse sp500, clear
reg close volume
*--------------------------- end example ------------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Also see <http://blog.stata.com/2012/08/29/using-statas-random-number-generators-part-3-drawing-with-replacement/>

Hope this helps,
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index