Ray, Bryan
>
> I am doing a simple difference of means test using the
> ttest function. I
> want to perform the test for several different groups that
> are defined by a
> variable called customer. However, for some customers the
> test cannot be
> performed because one of the samples does not exist. When
> this error is
> encountered the output is terminated. Is it possible to
> somehow suppress the
> error so that the output will not terminate? See below for
> the command that
> I am using and a snippet of the output. Thanks.
>
>
> by customer: ttest pos, by(dum)
>
> <ouputt removed>
>
> -> customer = Ten
> 1 group found, 2 required
One first stab is
bysort customer (dum) : gen OK = dum[1] != dum[_N]
by customer: ttest pos if OK, by(dum)
This may be rendered less cryptic by looking at
How do I list observations in a group that differ on a variable?
http://www.stata.com/support/faqs/data/diff.html
The potential problem with this is that it
will fail to give the desired result if the values
of -dum- for a customer are (1) all of one
non-missing value apart from (2) those that are missing.
This should a bit more robust (example assumes
values are 1 and 2):
bysort customer : egen one = sum(dum == 1)
by customer : egen two = sum(dum == 2)
by customer : ttest pos if one & two, by(dum)
There are other ways to do it, no doubt. Note
that
bysort customer : noisily capture ttest pos, by(dum)
is not one of them.
Nick
[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/