Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: not repeating the 'if' command


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: not repeating the 'if' command
Date   Fri, 1 Aug 2003 15:27:30 -0500

----- Original Message ----- 
From: "Scott Merryman" <smerryman@kc.rr.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, August 01, 2003 1:26 PM
Subject: Re: st: not repeating the 'if' command


> ----- Original Message ----- 
> From: "Fred Wolfe" <fwolfe@arthritis-research.org>
> To: <statalist@hsphsun2.harvard.edu>
> Sent: Friday, August 01, 2003 1:13 PM
> Subject: Re: st: not repeating the 'if' command
> 
> 
> > At 02:04 PM 8/1/2003 -0400, you wrote:
> > >I know that in SPSS there is way to set a filter for a series of commands 
> > >using a 'do if' statement.  Is there a way to do this in STATA?  For 
> > >example, I want to perform a large set of analyses on a set of groups 
> > >(group == 1....group == 50).  Do I have to continue to type if group == 1 
> > >after each command?  ex:
> > >
> > >tab race     if group == 1
> > >tab sex      if group == 1
> > >tab race sex if group == 1
> > >
> > >tab race     if group == 2
> > >tab sex      if group == 2
> > >tab race sex if group == 2
> > >
> > >or, is there a way to globally set off group == 1 for all analyses then a 
> > >command to globally set off group == 2 for all analyses, and so 
> > >on...?   The above code seems too cumbersome.
> > There are a number of approaches you can use:
> > 
> > 1) bys group: tab race * etc */
> > 
> > 2) forvalues i = 1/ [put the highest value of group here]{
> >        */ all of your analyses here */
> >        tab race     if group == `i'
> >        tab sex      if group ==`i'
> >        tab race sex if group == `i'
> > }
> > 
> > Fred Wolfe
> > 
> 
> 
> In addition, if you group variable is not composed of  consecutive numbers:
> 
> levels group, local(levels)
> foreach l of local levels {
> tab sex
> tab race
> tab race sex
> } 
> 
> Scott


That should be:

levels group, local(levels)
foreach l of local levels {
    tab sex if group == `l'
    tab race if group == `l'
    tab race sex if group == `l'
} 


Scott


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