Bookmark and Share

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]

st: Re: help with STATA macros


From   Nick Cox <[email protected]>
To   [email protected]
Subject   st: Re: help with STATA macros
Date   Sun, 6 Jan 2013 10:36:05 +0000

There are several mistakes here. I don't believe your assertion that
your syntax works with commands other than -sdtest- and -ttest-.  The
several problems with your code don't arise from how either test
command works.

1. "a-d" could not be the name of a local macro

2. Even if it could you have not defined it.

3. -foreach- supports -of varlist- but -in varlist- means something
different and is almost always going to be wrong.

4. You don't include a reference to `var' within the loop for the
second example, which is necessary for your problem.

foreach var in a b d  {
        ttest `var', by(c)
}

should work.

For more complicated examples,

foreach var of varlist <varlist> {
     ttest `var', by(c)
}

is a possible form.

Nick

NB: advice in Statalist about not sending to active people and on the
spelling of "Stata".

On Sun, Jan 6, 2013 at 10:22 AM, Sprindzuk Matvey <[email protected]> wrote:

> I need to run ttest in STATA on many variables (a, b, c, d) in a foreach
> loop
>
> I try:
>
> foreach var in varlist `a-d'{
> ttest `var', by(c)
> }
>
> and
>
> foreach var of in varlist `a-d'{
> ttest `a-d', by(c)
> }
>
> But these code patterns work well only with some other tests, but not with
> ttest and sdtest.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index