| Date: | Thu, 28 Oct 2004 18:19:59 -0500 |
| Reply-To: | Richard Ristow <wrristow@mindspring.com> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Richard Ristow <wrristow@mindspring.com> |
| Subject: | Re: Finding the oldest child or assigning maximum value among
five variables |
|
| In-Reply-To: | <000201c4bd2f$42589270$6701a8c0@MSquaredGroup> |
| 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'
4 '11-15'
5 '16-17'.
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.
END LOOP.
If the variables aren't contiguous, you can use similar code with DO
REPEAT. This code, by the way, treats missing counts as 0.
|