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

Re: st: using multiple variable lists in ancova

From   "Joseph Coveney" <>
To   "Statalist" <>
Subject   Re: st: using multiple variable lists in ancova
Date   Mon, 12 Nov 2007 01:19:04 +0900

Cathy L. Antonakos wrote:

This question relates to the use of multiple variable lists (parallel

I have a dataset with many physiologic measures collected at two time
There are three grouping variables (gp1, gp2, gp3).


I can use -foreach- to call each group variable separately, saving some
time, as follows:

   local gp "gp1 gp2 gp3"

   foreach var of varlist `gp' {
     anova bt at `var'
     anova btx atx `var'
     anova btz atz `var'

But I'd like to figure out a way to call the lists of variables to reduce
the number of anova commands, something like:

   anova `var2' `var1' `gp', cont(`var1')

Is there a way to do that?


You mention parallel lists at first, but what you ask for looks more
like nested loops.  You can loop over pretest-posttest variables and
grouping variables in a nested structure as follows:

foreach response of varlist b* {
   local baseline = subinstr("`response'", "b", "a", 1)
   foreach groupvar of varlist gp* {
       anova `response' `baseline' `groupvar', continuous(`baseline')

This assumes that all variables in your dataset beginning with "b" are
response variables with a corresponding baseline that is named identically
with the exception of the first letter, which is "a".  Note that there's
also a macro extended function for the string substitution.  -help
extended_fcn- and scroll down to the section titled, "Macro extended
functions for parsing".

For parallel lists, see the FAQ "How do I process parallel lists?" at .

Joseph Coveney

P.S. I assume that you're aware of Roger Newson's -smileplot-
and -multproc-. -findit smileplot- if not.

P.P.S. You might be able to gain some efficiency with -sureg-.

*   For searches and help try:

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