Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Produce a list of two-sided p-values of all t-tests in a loop
From 
 
Tim Wade <[email protected]> 
To 
 
[email protected] 
Subject 
 
Re: st: Produce a list of two-sided p-values of all t-tests in a loop 
Date 
 
Sun, 8 May 2011 23:06:33 -0400 
There are many ways to do this using different ways of storing
results, (see "help estimates", and the -estout- program from SSC).
However, -postfile- may be what you are looking for, here is an example:
sysuse auto.dta, clear
tempname memhold
tempfile ttests
postfile `memhold' str12 name pval using `ttests'
foreach var of varlist  price mpg rep78 headroom trunk {
ttest `var', by(foreign)
post `memhold' ("`var'") (r(p))
}
postclose `memhold'
clear
use `ttests'
. list
     +---------------------+
     |     name       pval |
     |---------------------|
  1. |    price   .6801851 |
  2. |      mpg   .0005254 |
  3. |    rep78   8.31e-08 |
  4. | headroom   .0110486 |
  5. |    trunk     .00166 |
     +---------------------
Tim
On Sun, May 8, 2011 at 6:16 PM, Jean-Marie Meier
<[email protected]> wrote:
> Dear Stata list users,
>
> for my data set I want create several tables with descriptive statistics. For these tables I want to test whether the mean and median value of variables are different from 0.
> I run the t-tests with the following loop. I now want that Stata produces a list of the two-sided p-values of all t-tests in the loop. the two sided p-value is saved as r(p) if the command ttest is used.
> Thus it should be possible to add a command to the loop, that the two-sided p-value is saved each time with a different name (such that not only one p-value is saved, which is constantly overwritten).
> However I do not know how to do that! It would be great if someone could help me.
>
> local j=0
> global global_name var1 var2 var3 ...
>
> foreach x in $global_name {
>
> local j=`j'+1
>
> ttest `x' == 0
>
> }
>
>
>
> Kind regards,
>
> Jean-Marie Meier
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/