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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Overriding a loop if 0 observations using tabstat


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

Many thanks Maarten for your advice. I managed to resolve it with the
following code:

forv i=0/5 {
foreach y in male singlet{
forv s=0/1{
di "myga==`i' & `y'==`s'"
qui su bwtg if myga==`i' & intab1==1 & admit_ic==1 & bwtg<. & `y'
	if r(N)!=0{	
tabstat bwtg if myga==`i' & intab1==1 & admit_ic==1 & bwtg<., stat(n
mean median p25 p75 min max ) by(`y') col(stat) f(%9.0g) notot nosep

}
}
}
}



On Tue, Apr 27, 2010 at 12:56 PM, Maarten buis <maartenbuis@yahoo.co.uk> wrote:
>
> --- On Tue, 27/4/10, sara khan wrote:
>> I just tried this but the output only shows the display
>> results and nothing from tabstat.
> <snip>
>
> -capture- works for me:
>
> *----------------- begin example ---------------------
> sysuse auto, clear
> forvalues i = 0/5 {
>        capture noisily tabstat mpg if rep78== `i', ///
>                s(n mean) by(foreign)
> }
> *-------------------- end example -------------------
>
> In order to debug your loop I would build it step by step:
> step 1: no looping, no locals, no -if- just a single -tatstat- command
> step 2: add -capture noisily-
> step 3: add some -if- conditions
> step 4: build a single loop (e.g. over i but not over y)
> etc. etc.
>
> Hope this helps,
> Maarten
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>
>
>
>
> *
> *   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/
>

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