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

RE: st: RE: Taking averages, etc.


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Taking averages, etc.
Date   Wed, 17 Dec 2003 15:01:39 -0000

Richard Williams

> >Let's not lose sight of where we started.
> >Stata has standard constructs
> >
> >if ... {
> >
> >}
> >else {
> >
> >}
> >
> >too; the point is that the conditional
> >testing cannot be vectorised.
> 
> Just so I'm clear as to what you mean:  If I understand 
> this correctly, if 
> the statement is something like
> 
> if x1==1 {
> 
> and x1 = 1 for the FIRST case, then the statement is true, 
> otherwise false; 
> it won't matter what x1 = for the 2nd case.  So, this kind 
> of structure is 
> not useful for case by case changes. It is useful for 
> things like your earlier
> 
> if r(N) == 0 su mpg
> 
> where the value of r(N) (or whatever) is not going to 
> change case by case.  Sound right?

That is correct. Some examples of this -if- in programs 
are 

1. testing a string 

if "`option'" != "" { 
	// some option was specified, so
	...
} 
else { 
	...
}

2. testing a result 

qui count if `touse'
if r(N) == 0 error 2000 

3. testing an observation value 

if x[1] < 0 { 
	...
} 

This last kind of thing might 
make sense, especially after 
a -sort-. It's perhaps more 
common to do something more 
like 

su x, meanonly 
if r(min) < 0 { 
	...
}  

Nick 
n.j.cox@durham.ac.uk 

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