Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Bootstrapping vectors of statistics


From   [email protected] (Jeff Pitblado, Stata Corp.)
To   [email protected]
Subject   Re: st: Bootstrapping vectors of statistics
Date   Thu, 30 Jan 2003 17:56:56 -0600

Rob Williams <[email protected]> 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[1]) (stat1[2]) (stat1[3]) (stat1[4]) (stat1[5]) (stat2[1])
> (stat2[2])  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
> results?

> 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
programming.

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)

Technical note:

	-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
	version 8.0
	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'
end

	Here is a log of the result:

***** BEGIN log
. jj

. mat li e(b)

e(b)[1,4]
    c1  c2  c3  c4
y1   1   2   3   4
***** END log

--Jeff
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index