* Version 1: Does not work
SELECT IF (gender = "female").
EXECUTE.
* Version 2: Does work
SELECT IF (gender = 1).
EXECUTE.
For clarity, and to avoid typing/lookup errors, I'd prefer to express
comparisons via value labels rather than numeric codes. Any hints how to
achieve this?
P.S. The example is, of course, made up. I get the data from a larger
database that uses numbers to encode nominal values.
--
Andreas Jaeger
MMF GmbH, Herdecke, Germany
(Mail: use my surname at domain supplied)
Another way:
STRING sex (A6).
RECODE gender (1 = "male")(2 = "female") INTO sex.
(Hope it works ...)
Peter Sopp
Well that surely works, but is not what I desire. Because I do have
numeric codes, I cannot redesign the data import. And I do not want to
recode the numeric codes into strings, either, because that would mean
to write down all the value label associations.
The intention is to work with enumeration names instead of numbers, as
it is much more secure (and even works after changing the codes). The
following is more prone to errors, and less stable
DO IF (gender = 1).
COMPUTE menopause = "n/a".
ELSE IF (age_category >= 4).
COMPUTE menopause = "yes".
ELSE.
COMPUTE menopause = "no".
END IF.
than this version
DO IF (gender = "male").
COMPUTE menopause = "n/a".
ELSE IF (age_category >= "old").
COMPUTE menopause = "yes".
ELSE.
COMPUTE menopause = "no".
END IF.
> DO IF (gender = "male").
> COMPUTE menopause = "n/a".
> ELSE IF (age_category >= "old").
> COMPUTE menopause = "yes".
> ELSE.
> COMPUTE menopause = "no".
> END IF.
As the above does not work, I'm looking for something along the lines of
DO IF (LBL(gender) = "male").
COMPUTE menopause = "n/a".
ELSE IF (age_category >= VAL("old")).
good luck
Andy W
>On 14.07.2010 14:24, Andreas Jaeger wrote:
>
>> DO IF (gender = "male").
>> COMPUTE menopause = "n/a".
>> ELSE IF (age_category >= "old").
>> COMPUTE menopause = "yes".
>> ELSE.
>> COMPUTE menopause = "no".
>> END IF.
>
>As the above does not work, I'm looking for something along the lines of
>
>DO IF (LBL(gender) = "male").
> COMPUTE menopause = "n/a".
>ELSE IF (age_category >= VAL("old")).
- without a clever, context-sensitive IF, that function
for VAL would have to say VAL("age_category", "old").
> COMPUTE menopause = "yes".
>ELSE.
> COMPUTE menopause = "no".
>END IF.
( I think of that sort of language processing as being
a feature of LISP, say. I don't think of it as being part of
any stat-pack, yet. That could be nice for documenting,
but I imagine that it is some years in the future.)
What occurs to me is that you might set up a
number of "constants", though SPSS does not lend
itself to that practice very readily. For instance,
COMPUTE male= 1.
COMPUTE female= 2.
COMPUTE yes=1.
compute no= 2.
compute m_age= 50.
... and then you can carry out your tests
and assignments using the variables.
NOTES.
- I would not want to assign my new variables,
like menopause, to have names that are literals,
rather than numbers. That is highly inconvenient for
most of the procedures. (Menopause example, above.)
- This becomes unsafe if there are different values
needed for "Male" or "yes" , etc., depending on which
question is asked. Then you could use the ad-hoc
adjustment of having m_yes, or whatever; but that is
something else to lose track of.
- To keep the assignments from being carried out for
every case, you *could* start every name with a "#"
and use a DO IF <case 1> to introduce the set of
computations that assign permanent values. #yes will
keep the same value on the second case, if it is not
redefined. (I'm assuming that this obscure feature still
exists.) Distinguishing these effective "constants" by
a peculiar prefix would also be a virtue for reading the
program, in the long run.
--
Rich Ulrich