Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Overriding a loop if 0 observations using tabstat


From   sara khan <sarakhanum84@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Overriding a loop if 0 observations using tabstat
Date   Tue, 27 Apr 2010 11:29:51 +0100

Dear Statalisters

I am having problems with a loop (1 below) that contains tabstat and
would appreciate any advice.

In the command below, there are 0 observations when `i'=0 and
`y'=male. I get a message saying no observations and the loop stops.

However, when I run the loop using the tab command (for example, 2
below), the loop does not terminate when there are 0 observations but
continues to cycle through all values.

How can I get the first command to override 0 observations?

Many thanks,




1.
foreach i in  0 1 2 3 4 5 {
foreach y in male singlet{
di "Var =`y' & GA=`i'"
tabstat bwtg if myga==`i' & intab1==1 & admit_ic==1 & bwtg<., stat(n
mean median) by(`y') col(stat) f(%9.0g) notot nosep

}

}


2.
foreach i in 0 1 2 3 4 5 {
foreach y in male singlet{

di "Var =`y' & GA=`i'"
 tab `y' if myga==`i' & intab1==1 & admit_ic==1 & bwtg<.
}

}
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index