Statalist


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

Re: st: using multiple variable lists in ancova


From   "Cathy L. Antonakos" <cathya@umich.edu>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: using multiple variable lists in ancova
Date   Sun, 11 Nov 2007 13:20:56 -0500 (EST)

This is very helpful. It worked with one minor correction. I replaced gp* with `ivars2' which is the true local macro name for my grouping variables.

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

Thanks, again, and also for the other ideas, which I will look into.
Cathy

On Mon, 12 Nov 2007, Joseph Coveney wrote:

Date: Mon, 12 Nov 2007 01:19:04 +0900
From: Joseph Coveney <jcoveney@bigplanet.com>
Reply-To: statalist@hsphsun2.harvard.edu
To: Statalist <statalist@hsphsun2.harvard.edu>
Subject: Re: st: using multiple variable lists in ancova

Cathy L. Antonakos wrote:

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

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

[redacted]

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
http://www.stata.com/support/faqs/lang/parallel.html .

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