[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Bootstrapping vectors of statistics
Rob Williams <email@example.com> asks about bootstrapping many results
that are stored in variables:
> I have a program that calculates a large number of statistics for each
> income quintile in my sample. To make this manageable, I store the
> estimates as variables--each statistic that I've calculated is a variable,
> and there are 5 observations, one for each quintile. I want to bootstrap
> the results, using the bstrap command. But it appears that bstrap only
> works for outputs that are scalars. I could break up the variables into
> scalars, so that the post command that ends the bootstrap program would be
> something like
> post `1' (stat1) (stat1) (stat1) (stat1) (stat1) (stat2)
> (stat2) etc, etc, etc
> but that would be incredibly tedious, because there are a lot of statistics.
> Is there any way to simplify this by posting variables (or vectors) of
> I should note that I'm quite new to Stata programming, so I could be missing
> an obvious way to do this.
Doing this with -bstrap- prior to Stata 8 would take a decent amount of
In Stata 8 there is the new -bootstrap- command, which has the same expression
syntax as -jknife-; i.e. _b and _se. For example, we can now bootstrap all
the coefficients from a regression:
. bootstrap "regress mpg weight length ..." _b
To take advantage of this syntax, Rob will have to modify his program to make
it an -eclass- command that posts the values of interest into -e(b)- instead
of placing them in variables. Then Rob could do something like:
. bootstrap "robscmd ..." _b, reps(100)
-ereturn post- requires a variance matrix. The way around this is to
post a square matrix of zeros (that has equal row and column names).
Here is a bare-bones example that posts the vector (1,2,3,4) to e(b)
and the zero matrix to e(V).
program define jj, eclass
tempname bb vv
matrix `bb' = 1,2,3,4
matrix `vv' = 0*I(colsof(`bb'))
local cn : colnames `vv'
matrix rownames `vv' = `cn'
ereturn post `bb' `vv'
Here is a log of the result:
***** BEGIN log
. mat li e(b)
c1 c2 c3 c4
y1 1 2 3 4
***** END log
* For searches and help try: