Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to visualize standard errors as the number of bootstrapreplications is increased


From   [email protected]
To   [email protected]
Subject   Re: st: How to visualize standard errors as the number of bootstrapreplications is increased
Date   Thu, 24 May 2007 22:28:50 +0800

Many thanks Uli, that's fantastic.

Your suggestion indeed works wonders (it was _bs_1 rather than _bs_2 in the
code you gave me). Other information can be extracted with the same method
from qreg, say the pseudo-R-square:

 bootstrap "qreg y x" e(sum_adev) e(sum_rdev), reps(100) saving(data)
replace
use data, clear
gen n = _n
gen mean = sum(_bs_1)/n
gen r2 = 1-_bs_1/_bs_2
graph twoway scatter mean n
graph twoway scatter r2 n

Patrick.
[email protected]


Ulrich Kohler <[email protected]>
Sent by: [email protected]
23/05/2007 10:56 AM ZE2Please respond [email protected]

To   [email protected]
cc
bcc
Subject   Re: st: How to visualize standard errors as the number of
bootstrap replications is increased


[email protected] wrote:
> I would like to visualize the standard errors associated with a
> bootstrapped regression as the number of replications is increased. The
> purpose of this is to assess how many replications to perform. I wrote
the
> following code designed for qreg regressions. I named it grbs for "graph
> bootstrap".
>
> -----------------------------
>  capture program drop grbs
>  program define grbs
>  version 9
>  postfile results n sa using data, replace
>  forvalues n=2(5)10{
>  noisily display "`n'" "`sa'"
>  set seed 123456789
>  quietly bootstrap "qreg $y $x" _b, reps(`n')
>  local n=e(N_reps)
>  local sa=e(sum_adev)
>  post results (`n') (`sa')
>  }
>  postclose results
>  end
>
>  use data, clear
>  graph twoway scatter sa n, xtitle("replications") ytitle("bootstrap
> standard error")
> -----------------------------
>
>
> I am no programmer -- the code was put together by using related bits of
> codes found here and there. There is clearly an error somewhere (or
> several) as the saved dataset "data.dta" appears with missing values.

I have three minor points and one more general. Let me start with the minor
ones.

(1) I don' think you need a program for this. You can simply do this in a
do-file.

(2) Where you have typed e(N_reps) you probably mean e(reps). e(reps) is a
matrix. You need to store the number of replications in a different way
before you can post them in your postfile. For example:

. matrix x = e(reps)
. local x = x[1,1]
. post results (`x')

(3) e(sum_adev) is stored by -qreg-, but you have called -qreg- with
-bootsrap- and -bootstrap- do not leave behind e(sum_adev).

My general point is to use a more direct approach:

. sysuse auto
. bootstrap "qreg rep weight" e(sum_adev), reps(10) saving(x)
. use x
. gen n = _n
. gen meansa = sum(_bs_2)/n
. graph twoway scatter meansa n


Uli

--
Ulrich Kohler
[email protected]
030/25491-361
*
*   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/

*
*   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