Syntax for bootstrap estimates from ttest command

2k views Asked by At

I am attempting to demonstrated characteristics of various tests for small samples of data. I would like to demonstrate the performance of the t-test, t-test with bootstrap estimation and the ranksum test. I am interested in obtaining the p-value for each test on multiple sets of data using simulate. However, I cannot obtain t-test estimates using the bootstrap prefix and ttest command.

The data is generated by:

clear
set obs 60
gen level = abs(rnormal(0,1))
gen group = "A"
replace group = "B" if [_n] >30

bootstrap, reps(100): ttest level, by(group)
bootstrap _b, reps(100): ttest level, by(group)
bootstrap boot_p = e(p), reps(100): ttest level, by(group)

The errors for each of the procedures in order are:

  1. expression list required

  2. invalid expression: _b

  3. 'e(p)' evaluated to missing in full sample

These results are not consistent with the documentation for the bootstrap prefix. Is there some problem with specification of e or r class objects and ttest ?

Edit:

Understanding now that r-class is the correct group of scalars, I still do not generate a variable 'p' given the code provided in the solution. Additionally:

clear
set more off

set obs 60

gen level = abs(rnormal(0,1))
gen group = "A"
replace group = "B" if [_n] >30

bootstrap p=r(p), reps(100): ttest level, by(group)
    display r(p)

does not return the p-value.

1

There are 1 answers

2
Roberto Ferrer On

ttest is an r-class command and stores its reults in r(). You seem to expect for it to save results in e(), like an e-class command. The norm is that the latter kind fit models; ttest is not in this category.

The two-sided p-value is stored in r(p), as indicated in help ttest:

clear
set more off

set obs 60

gen level = abs(rnormal(0,1))
gen group = "A"
replace group = "B" if [_n] >30

bootstrap p=r(p), reps(100): ttest level, by(group)