0

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.

Siguza
  • 21,155
  • 6
  • 52
  • 89
Todd D
  • 258
  • 1
  • 13
  • `return list` after `bootstrap` does not contain `r(p)`,\will show you that `r(p)` is not returned by `bootstrap`, so your last command will produce an error. – Steve Samuels Jun 24 '15 at 00:50

1 Answers1

2

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)
Roberto Ferrer
  • 11,024
  • 1
  • 21
  • 23
  • This solution is not working as noted above in the edited query. – Todd D Jun 19 '15 at 20:59
  • 1
    `bootstrap` has its own help file and you have easy access to it with `help bootstrap`. There you can find that the bootstrap result is in `e(b)`. Run `matrix list e(b)` to display it. Regarding your desire to create a variable, if you want intermediate results check the `saving()` option for `bootstrap`. If you want to save the final result, you now know how to access it. See `help postfile` on saving results to a Stata dataset. My recommendation is to make a better use of the `help files` and Stata manuals. (You can make any answer irrelevant, modifying your question just enough.) – Roberto Ferrer Jun 19 '15 at 22:29