    # Re: st: Mean Test

 From n j cox To statalist@hsphsun2.harvard.edu Subject Re: st: Mean Test Date Thu, 19 Jan 2006 22:06:35 +0000

I have to wonder about what is being proposed here on
various grounds.

George Box pointed out in Biometrika in 1953 that the
t-test was more robust than testing for variance
equality. His message was that doing a preliminary
test for variances was like putting to sea in
a dinghy to test whether it was safe for a liner
to leave port. So, this goes against statistical
wisdom, setting on one side the detail of how
you decide from -oneway- which variances are
deemed equal.

Additionally, doing every possible pairwise t-test
raises a whole heap of standard issues, such
as how to interpret the P-values. As your
categorical variable is ordered in any case,
other analyses should be more respectful of
the information in your data, say a Jonckheere-Terpstra
test.

Fixing the code to do what you want is not the key issue if the enterprise appears misconceived.

Nick
n.j.cox@durham.ac.uk

Rijo John

I have around 30 variables for which I need to do a mean test
(ttest for the differences in mean). However, I have three categories.
Lets say I want to find the differences in mean of var1 between Low
Income, middle income and high income. Ideally I need to do a ttest
for the mean of var1 between
1) Low Income Vs Middle Income
2) Low Income Vs High Income
3) Middle Income Vs High Income
And similarly for var2,...,var30.
One problem is that the mean test procedure is different when the
variances are different. So I first test for the equality of variance
and then apply the formula accordingly. My problem is that I am able
to do this with a small macro when my category is a binary variable.
(Lets say only low income and high income.) How can I do the same in
the case above with three categories? Below is what I do when the
category is a binary.

Local items ``var1, var2,...,var30"
foreach X of local items{
oneway var`X' BinaryVar [aw=weight], tabulate
}
I then identify the variables with equal variances and not. (I'm sure
there are more efficient ways of doing it. But my programming skills
are a big zero)

local equalsig "varX, vary,..., varZ"
local unequalsig "VarA, varB,...,varC"

foreach X of local equalsig{
display "Summary Statistics for for bs`X'"
summ bs`X' [aw=hmul] if BinaryVar==0
qui ret list
local mean1 = `r(mean)'
local sd1 = `r(sd)'
local obs1 = `r(N)'
summ bs`X' [aw=hmul] if BinaryVar==1
qui ret list
local mean2 = `r(mean)'
local sd2 = `r(sd)'
local obs2 = `r(N)'
display "Two sample T-Test for euqality of means (equal
variance): var`X'"
ttesti `obs1' `mean1' `sd1' `obs2' `mean2' `sd2', level(95)
}
macro drop obs1 mean1 sd1 obs2 mean2 sd2
foreach X of local unequalsig{
display "Summary Statistics for var`X'"
summ bs`X' [aw=hmul] if BinaryVar==0
qui ret list
local mean1 = `r(mean)'
local sd1 = `r(sd)'
local obs1 = `r(N)'
summ bs`X' [aw=hmul] if BinaryVar==1
qui ret list
local mean2 = `r(mean)'
local sd2 = `r(sd)'
local obs2 = `r(N)'
display "Two sample T-Test for euqality of means (unequal
variance): var`X'"
ttesti `obs1' `mean1' `sd1' `obs2' `mean2' `sd2', unequal
welch level(95)
}

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