LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 21 Jun 2007 14:04:14 -0500
Reply-To:     "Marks, Jim" <Jim.Marks@lodgenet.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Marks, Jim" <Jim.Marks@lodgenet.com>
Subject:      Re: Converting scale value into binary columns
Content-Type: text/plain; charset="US-ASCII"

Here is a solution-- I assume you have multiple contacts per row.

*** sample data. DATA LIST LIST (",") /id (f8.0) contact_1 TO contact_4 (4moyr8). BEGIN DATA 1 , JAN 2002, MAY 2002, JUL 2002, AUG 2002 2 , MAR 2003, APR 2003, 3 , FEB 2002, JUN 2002, OCT 2002, DEC 2002 END DATA.

**** create a variable for each contact date with the month of the contact. DO REPEAT x = contact_1 to contact_4 /y = cmth_1 to cmth_4. COMPUTE y = xdate.month(x). END REPEAT.

EXECUTE.

*** loop thru the contact months and create a month variable mth_1 = January).

VECTOR cm = cmth_1 TO cmth_4. VECTOR mth_(12F8.0). LOOP #j = 1 TO 4. LOOP #i = 1 TO 12. IF cm(#j) = (#i) mth_(#i) = 1. END LOOP. END LOOP.

RECODE mth_1 to mth_12 (sysmis = 0). EXECUTE.

The loop for #j and the do repeat should match the nbr of contacts per row

Cheers --jim

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Juliana Sent: Thursday, June 21, 2007 9:29 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Converting scale value into binary columns

It would be great if anyone could help me out with the following:

I have a series of contact dates such as

Jan02 May02 July02 Aug02

I would eventually like to convert this into binary coding month-by-month such that if a contact occurred in a given month the value is 1 and otherwise it is 0. I calculated the difference between the contact dates (in months) such that I have the following:

datediff1 datediff2 datediff3 datediff4 1 4 2 1

I would like to conver this into a new series of columns with (n-1) zeroes in between ones such that the above would become:

1 0 0 0 1 0 1 1

This would reflect the months January to August, with a 1 for a contact and a 0 for no contact.

Again, if anyone can help me out, I would appreciate it. Thanks!


Back to: Top of message | Previous page | Main SPSSX-L page