Hi,
I hope someone will have the patience to read this. Sorry for the long
post. 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)
}
Thanking in advance,
Rijo John.
*
* 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/