## Monday, July 9, 2012

### Write your own bootstrap command.

* A similar function is also programmed in R.  See: http://www.econometricsbysimulation.com/2012/09/program-your-own-bootstrap-command-r.html

* The bootstrap resampling technique is one of the coolest techniques that have developed in econometrics/statistics in the last 50 years (that and maximum likelihood).  Bootstrap releases the user from strong assumptions about the underlying distribution of errors.

* As far as I understand the bootstrapping assumptions follow, so long as the data you draw are reasonable draws from the underlying distribution then resampling from that sample will give you a reasonable estimate of the populations underlying parameters. Note, this method is obviously related to Baysian methods.

* B Efron formalized the technique and termonology of Bootstrap in a paper in 1979.

* First let us define a program that will do our bootstrap
cap program drop bootme
program bootme

********
* First we will set up the data that we will use as a resource to draw from

* Preserve the current data
$nq preserve syntax anything [, Reps(integer 100) Command(string) Keep(string) Noisily] * Tell stata to display what it is doing or the default is not to if "noisily'" == "" local nq quietly if "noisily'" != "" local nq * Generate a variable that counts from 0 to _N-1 nq' gen bootmatcher = _n-1 * This is the number of observations to draw from. nq' gl boot_N=_N * We will save the data file to draw from first tempfile drawfile nq' save drawfile' , replace * Draw file set up ******** * Clear the memory nq' clear * Set the number of repetitions to that specified by the user nq' set obs reps' * Keep tells the bootstrap rountine what values from the estiamtion to keep foreach v in keep' { * Creates emptly variables to hold the coefficients of interest local vtemp=strtoname("vv'") nq' gen vtemp'=. } * Create a data file that will list the results of the bootstrap tempfile returnlist nq' save returnlist' , replace * Display the bootstraps progress di as text _newline "Bootstrap replications ({result:reps'})" di "----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5" * Loop through the number of repetitions in the bootstrap forv i=1/reps' { * First clear the data clear * Set the number of observations equal to the number to draw nq' set obs$boot_N
* Generate a variable that represents random draws.