Smith, Paul Bradley <[email protected]> is using the -bca- option of
-bootstrap- with his program, but is having trouble getting -estat bootstrap-
to display the BCa confidence limits:
> Thanks for a quick solution to that problem. The routine runs just
> fine with the false argument.
>
> In getting the routine to run, Because -stci- leaves a value for N in
> e(), the jackknife sample was limited to only part of the whole dataset.
> The jackknifing runs fine (producing no output), followed by the
> bootstrap, but then at the end, no bca confidence interval. When I
> issued -estat bootstrap, all--, I got:
>
> option bca requires BCa confidence intervals to be saved by the
> bootstrap prefix command
> r(198);
>
> The excerpt below shows only 100 replicates of the bootstrap to speed up
> the test, but I got the same error for 2000 replicates.
>
> I did the same test with a simple difference of means from -sum-,
> avoiding all the survival analysis overhead and the same issue arises --
> the estimates necessary for bca computation don't appear to be
> available.
I must admit that I didn't look at Brad's user command carefully. If I had, I
would have noticed that it would not work with -jackknife-, a requirement of
the -bca- option (see -help bootstrap-, and search for mention of the -bca-
option in the 'Description'.) -jackknife- requires that the prefixed command
pay attention to an -if- condition. This is not true of Brad's -myDifference-
command:
***** BEGIN:
program myDifference, rclass
version 9
*compute restricted mean survival times
stset duration_haddeath, f(haddeath=1)
stci if experimental==0 , rmean
local contime=r(rmean)
stci if experimental==1 , rmean
local exptime=r(rmean)
return scalar difference = `exptime'-`contime'
end
***** END:
Notice (as I should have in my first reply), -myDifference- ignores all
arguments that it may be passed. The following is code I wrote to reproduce
the spirit of what I think Brad wants.
***** BEGIN: mydiff.do
cscript
program mydiff, rclass
version 9
syntax varname [if] [, NONOPTION]
marksample touse
stci if `touse' & `varlist' == 0, rmean
local contime=r(rmean)
local n = r(N_sub)
stci if `touse' & `varlist' == 1, rmean
local exptime=r(rmean)
local n = `n' + r(N_sub)
return scalar difference = `exptime'-`contime'
return scalar N = `n'
cleareclass
end
program cleareclass, eclass
ereturn clear
end
sysuse auto
stset mpg
bs r(difference), bca reps(10): mydiff for
estat boot, all
***** END: mydiff.do
1. -mydiff- uses -syntax- to parse an optional -if- statement;
this is required in order to work properly with -jackknife-. Use
-marksample- to generate a variable that identifies the estimation
sample for all subsequent calculations.
2. I had to add '[, NONOPTION]' here. This is to avoid a parsing issue in
-jackknife- that will be fixed in the next ado-file update.
3. The variable supplied to -mydiff- identifies the indicator variable that I
think Brad wants to compare the mean survival time between. Note that I
combine this variable with `touse' to identify the subset of the
observations to compute each mean.
From Brad's original email, the new call to -bootstrap- would be:
stset duration_haddeath, f(haddeath=1)
bs difference=r(difference), reps(2000) bca: mydiff experimental
4. Since -mydiff- is an -rclass- command that uses a command that posts
results to -e()- (specifically, setting -e(N)- and -e(esample)-), I had to
add another short command -cleareclass- to clear the contents of -e()-
before -mydiff- exits. With this addition, the -nodrop- option is no
longer necessary.
5. -mydiff- also saves -r(N)-; this helps -jackknife- determine the validity
of a given replicate.
--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/