Statalist The Stata Listserver


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

st: RE: accumulating t-test results


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: accumulating t-test results
Date   Mon, 12 Feb 2007 16:22:57 -0000

You could check out -makematrix- from SSC. But the 
do-it-yourself approach has attractions too. 

Nick 
n.j.cox@durham.ac.uk 

Jeremy Reynolds
 
> I would like to accumulate the results of multiple t-tests into a 
> matrix.  Below is a piece of code I have written to 
> accomplish the task, 
> but my suspicion is that there is a better way to collect the 
> results of 
> an r-class command.  The creation and manipulation of the 
> matrices, in 
> particular, seems awkward.  Can anyone point me in the right 
> direction?
> 
> Thanks,
> 
> Jeremy
> 
> *Create a matrix
> matrix input ttestmat = (0)
> 
> *Calculate t-tests comparing five variables at three points 
> in time and 
> save the results in the matrix
> forvalues i = 1(1)2 {
>     local j=`i'+1
>             foreach stub in var1_ var2_ var3_ var4_ var5_ {
>                    quietly: ttest `stub'1==`stub'`j', unpaired
>                        matrix ttestmat= (ttestmat\r(t))
>                  }
>      }
> 
> *Extract the submatrices with results (the first row contains 
> zeros) and 
> re-organize the matrix
> matrix ttestmat = ttestmat[2..6,1], ttestmat[7..11,1]
> matrix colnames ttestmat = 1v2 1v3
> matrix rownames ttestmat = var1_ var2_ var3_ var4_ var5_
> 
> *List the results
> matrix list ttestmat

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