|Date: ||Thu, 28 Oct 2004 18:19:59 -0500|
|Reply-To: ||Richard Ristow <firstname.lastname@example.org>|
|Sender: ||"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>|
|From: ||Richard Ristow <email@example.com>|
|Subject: ||Re: Finding the oldest child or assigning maximum value among
|Content-Type: ||text/plain; charset="us-ascii"; format=flowed|
At 03:46 PM 10/28/2004, Jason McNellis wrote:
>I have a dataset where each case is a family. Children ages are
>divided into five variables (0-2 years, 3-5 years, etc) where each
>variable shows the number of children in that age group (from 0-2
>children). I would like to set up a variable that indicates the
>oldest child's age group for each family. For example if a family
>(case) has three children, one each in the age ranges 0-2, 5-10, and
>16-17 I would like the variable oldest child to say 16-17.
So you have a list of five variables, which have an order meaningful to
you (i.e., age group), and you want the highest variable in the order
that has a non-zero value. It feels like there should be a
one-statement solution, but I can't think of one. Here's one using a
loop. (Code not tested. This is the most direct code. A loop running
'backwards', from high to low, and using BREAK, would be faster, but I
can't imagine that the difference would be detectable.)
Assuming your variables are
KDS00_02, KDS03_05, KDS06_10, KDS11_15, and KDS16_17,
and that they are contiguous in your file,
NUMERIC TOP_KID (F2).
VAR LABELS TOP_KID 'Age group of oldest child in family'.
VAL LABELS TOP_KID
0 'None '
1 ' 0- 2'
2 ' 3- 5'
3 ' 6-10'
VECTOR GRP_KDS=KDS00_02 TO KDS16_17.
COMPUTE TOP_KID = 0.
LOOP #AGE_GRP = 1 TO 5.
. IF (GRP_KIDS(#AGE_GRP) > 0)
TOP_KID = #AGE_GRP.
If the variables aren't contiguous, you can use similar code with DO
REPEAT. This code, by the way, treats missing counts as 0.