From | Christopher F Baum <[email protected]> |
To | [email protected] |
Subject | st: Re: if then else |
Date | Thu, 18 Dec 2003 07:51:56 -0500 |
On Dec 18, 2003, at 2:33 AM, Richard wrote:
Richard has indicated that SPSS "short-circuits" on an IF/THEN/ELSE, breaking out of the construct whenever one of the conditions is satisfied. Some programming languages do that, and some do not. All the more reason to have some very explicit logic (that does not depend on the rules that a specific piece of software follows). My solution was a literal translation of his evaluating several conditions in turn, but without the understanding of how his software will deal with multiple satisfied conditions. If code is to be portable and readable, that understanding becomes part of the documented scheme.No, something is wrong there; on case 4, my SPSS code would result in y =And for an obtuse solution: . g c1=3*(x1==1 & x2==3) . g c2=4*(x3==2 & x4==17) . g y= cond(max(c1,c2),max(c1,c2),5) . list x1-x4 y +-----------------------+ | x1 x2 x3 x4 y | |-----------------------| 1. | 1 3 0 0 3 | 2. | 0 0 2 17 4 | 3. | 1 2 3 4 5 | 4. | 1 3 2 17 4 | 5. | 1 2 3 4 5 | +-----------------------+
3, not y = 4 like you have it.
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |