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

From |
Joseph Coveney <jcoveney@bigplanet.com> |

To |
Statalist <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Pairwise comparisons repeated ANOVA (redux) |

Date |
Thu, 10 Apr 2003 00:57:50 +0900 |

Sven-Erik Johansson had asked about pairwise comparisons in conjunction with a one- way repeated-measures analysis of variance. George Hoffman and I responded, and later Al Feiveson provided a program for the Scheffé test using the pooled error term. After posting my response, I noted that I had initialized a cumulator matrix unnecessarily. In addition, I had neglected to clean up afterward--creating an interim matrix and not dropping it before exiting the do-file. In making the do-file more efficient, I discovered two features of Stata's programming language (perhaps rediscovered if others have observed them before). I'm posting them because I wonder whether it would be good practice to use them. The first is the ability to substitute a parenthetical presentation of a matrix in lieu of a matrix name as in the following: the online help file for matrix operations indicates that, to append a row vector to the bottom of an existing matrix A, first create matrix B and then -matrix A = A \ B-. But I found that I could use -matrix A = A \ (element1, element2, . . . ). This has the benefit of avoiding having to create two matrixes explicitly, possibly economizing very slightly. The second is that, in lieu of an -if . . . else- construction, I could define a macro in a - cond()- statement that contains for its value a Stata command as a string. And then I could "execute" the macro. (I suspect that this ability has been observed before.) I don't know off-hand of any advantage to this tactic unless -cond()- saves execution time vis-à-vis an -if . . . else- equivalent. Both of these features are illustrated below in the modified do-file, which runs and gives the same results as that in the earlier posting. My question is as to the wisdom of using either of these tactics in Stata programming. They both strike me as do a lot of analogous tricks in C, namely, clever-looking, but liable to create pitfalls. Joseph Coveney -------------------------------------------------------------------------------- set more off infile byte rctime1 byte rctime2 byte rctime3 byte rctime4 using /// http://www.uni-koeln.de/themen/Statistik/data/winer/win_228.txt, clear // ANOVA skipped this time local testno = 1 forvalues i = 1/3 { local j = `i' + 1 forvalues k = `j'/4 { quietly ttest rctime`i' = rctime`k' local command = cond(`testno' == 1, /// "matrix A = (`i', `k', r(p))", /// "matrix A = A \ (`i', `k', r(p))") `command' local rownamesA = "`rownamesA'" + "testpair`testno++' " } } matrix rownames A = `rownamesA' matrix colnames A = onedrug otherdrug unadjustp _mtest adjust A, mtest(holm) pindex(3) append matrix list r(result) exit -------------------------------------------------------------------------------- * * 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/

**Follow-Ups**:**st: programming tips, was Pairwise comparisons repeated ANOVA***From:*"Michael Blasnik" <michael.blasnik@verizon.net>

- Prev by Date:
**st: RE: RE: RE: -reshape-, or -by-?** - Next by Date:
**st: moving averages** - Previous by thread:
**st: RE: RE: RE: -reshape-, or -by-?** - Next by thread:
**st: programming tips, was Pairwise comparisons repeated ANOVA** - Index(es):

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