Statalist


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

Re: st: Table output


From   "Carole J. Wilson" <carolejwilson@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Table output
Date   Tue, 10 Jul 2007 15:31:23 -0500

How about:


qui{
noi di "Variable`=char(9)'Mean`=char(9)'p-value"
foreach var of varlist x1-x11 {
cap ttest `var'==0
noi di as text "`var'`=char(9)'" as result  %8.4f `r(mu_1)'
"`=char(9)'" %8.4f `r(p)'
}
}


_________________________________
      Carole J. Wilson
University of Texas at Dallas
School of Economic, Political,
     and Policy Sciences
     Phone: 972.883.4957
      Fax: 972.883.6571
    cjwilson@utdallas.edu
http://www.utdallas.edu/~cjwilson
__________________________________



On 7/10/07, Nuno <liststata@gmail.com> wrote:
Hi everyone,

I wanted to build a table that summarizes the output of several ttest on
different variables on a single table. To do this I've written a small piece
of code, that isn't displaying the table exactly as I intended:

di "Variable`=char(9)'Mean`=char(9)'p-value"
foreach var of varlist x1-x11 {
cap ttest `var'==0
di as text "`var'`=char(9)'" as result  %8.4f `r(mu_1)' "`=char(9)'" %8.4f
`r(p)'
}

The output is the following:

Variable       Mean    p-value

. foreach var of varlist x1-x11 {
 2. cap ttest `var'==0
 3. di as text "`var'`=char(9)'" as result  %8.4f `r(mu_1)' "`=char(9)'"
%8.4f `r(p)'
 4. }
x1    0.0926          0.1880
x2    0.0502          0.1763
x3   -0.0078          0.5102
x4    0.0114          0.5810
x5    0.0012          0.9515
x6    0.0094          0.5713
x7   -0.0199          0.1522
x8   -0.0332          0.0668
x9   -0.0255          0.1281
x10  -0.0508          0.0051
x11   0.1434          0.0529

The desired output is:
Variable       Mean    p-value
x1    0.0926          0.1880
x2    0.0502          0.1763
x3   -0.0078          0.5102
x4    0.0114          0.5810
x5    0.0012          0.9515
x6    0.0094          0.5713
x7   -0.0199          0.1522
x8   -0.0332          0.0668
x9   -0.0255          0.1281
x10  -0.0508          0.0051
x11   0.1434          0.0529

Is there a way for Stata not to display the foreach...

Best,

Nuno

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



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