From | Richard Williams <[email protected]> |
To | rar <[email protected]>, Stata distribution list <[email protected]> |
Subject | Re: st: RE: Taking averages, etc. |
Date | Wed, 17 Dec 2003 08:03:49 -0500 |
At 12:38 PM 12/17/2003 +0000, Allan Reese wrote:
I'm not sure how that performs fewer tests. The if-then-else structure only performs as many tests as are necessary whereas the above would perform 2 tests for each case. In any event, I think I'd be more likely to make errors with syntax like this. But that may just be me!First point is to analyse the logic. Reforming a problem often speeds up the execution far more than fancy coding, and leads to insights. In this case: gen y=5 replace y=3 if x1==1 & x2==3 replace y=4 if y==5 & (x3==2 & x4==17) performs far fewer tests. The parentheses do not affect the result but emphasise the logic.
You must get Nick's messages faster in the UK! I look forward to what he has to say. Thanks Allan.Stata, as Nick has already replied, has a completely general control language that includes if/then/else, for and while. Unlike SPSS, where only data transformations can be put into DO IF and LOOP constructions, Stata allows any statements or blocks of statements. These may conveniently be written using an editor (provided it doesn't add a file extension!) and saved as .DO or .ADO on the fly.
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |