[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/