Thanks Kit and Ronan. One more thing - how can I include the overall
no of observations and mean (i.e. both groups of variable q2q6) in the
same table? It should look like:-
Variable N Mean N1 Mean1 N2 Mean2 p-value
Right now, I am doing it in two steps and entering the values of N and
Mean manually.
Step 1 - Subsamples N1 and N2
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(N_1)' "`=char(9)'"
%8.2f `r(mu_1)' "`=char(9)'" %8.0f `r(N_2)' "`=char(9)'" %8.2f
`r(mu_2)' %8.2f `r(p)';
};
};
Step 2 - Overall sample N (i.e. N1 + N2)
qui {;
noi di "Variable`=char(9)'N`=char(9)'Mean`=char(9)'";
foreach var of varlist q52-q61 {;
cap ttest `var'==0 if q2q6==1 | q2q6==2;
noi di as text "`var'`=char(9)'" as result %8.0f `r(N_1)' "`=char(9)'"
%8.2f `r(mu_1)' "`=char(9)'";
};
};
which gives me the output
for Step 1
Variable N1 Mean1 N2 Mean2 p-value
q52 117 3.06 14 2.71 0.20
q53 120 3.64 17 3.06 0.01
q54 105 1.34 16 1.69 0.08
q55 106 1.91 13 2.31 0.16
q56 109 3.01 16 2.88 0.60
q57 105 2.21 14 2.57 0.26
q58 106 2.80 16 2.81 0.97
q59 115 3.51 15 2.93 0.01
q60 106 1.58 14 2.14 0.02
q61 108 2.12 13 2.62 0.08
and Step 2
Variable N Mean
q52 131 3.02
q53 137 3.57
q54 121 1.39
q55 119 1.95
q56 125 2.99
q57 119 2.25
q58 122 2.80
q59 130 3.45
q60 120 1.65
q61 121 2.17
Thanks in advance,
Hugh
On 7/21/07, Kit Baum <[email protected]> wrote:
Hugh writes
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)'
}
}
If you do
sysuse auto
ttest price, by(foreign)
return list
you see that r(N_1) and r(N_2) contain the counts in the two
categories. There is no r(count).
You probably want to include both r(mu_1) and r(mu_2) in your display
statement if you want to
see the means of each category.
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* 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/
*
* 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/