Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Table for difference in means test


From   "Hugh Colaco" <hmjc66@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: Table for difference in means test
Date   Sat, 21 Jul 2007 19:35:33 -0400

Dear Statalisters,

I am doing a difference in means test and am having problems
displaying a table. My variables names are q52-q61. I have a
categorical variable q2q6 which takes the value 1 or 2. I need the
table in the following format, based on the categorical variable. N =
no of obs.

Variable        N1     Mean1      N2         Mean2       p-value


I tried using this code

qui {

noi di "Variable`=char(9)'N1`=char(9)'Mean1`=char(9)'N2`=char(9)'Mean2`=char(9)'p-value"

foreach var of varlist q52-q61 {
cap ttest `var', by (q2q6)

noi di as text "`var'`=char(9)'" as result  %8.0f `r(count)'
"`=char(9)'" %8.2f `r(mu_1)' "`=char(9)'" %8.2f `r(p)'
}
}

but got the following output

Variable        N1      Mean1   N2      Mean2   p-value
q52                 3.06            0.20
q53                 3.64            0.01
q54                 1.34            0.08
q55                 1.91            0.16
q56                 3.01            0.60
q57                 2.21            0.26
q58                 2.80            0.97
q59                 3.51            0.01
q60                 1.58            0.02
q61                 2.12            0.08

which only displays the values of Variable, Mean1 and the p-value. I
am not sure how to tackle the categorical variable.

Thanks in advance,

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



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index