« Return to Thread: creating new variables

Re: creating new variables

by ariel barak :: Rate this Message:

Reply to Author | View in Thread

Hi Abdulrahman,
 
The syntax below works with the data you posted and will take care of multiple repairs. If there are multiple repair types of 209 on a given day, the syntax would not work properly. Basically I wrote code to create a total cost for all repairs on a given day for an given ID number excluding the cost of repair type 209. I then added those variables to the original dataset matched by ID and repair date. If the repair type was not 209, I set the new variables to zero.
 
Let me know if this works for your dataset...if not, maybe I can tweak it a little.
 
Thanks,
Ari
 
 
DATA LIST LIST /ID (F8) RepairDate (ADATE10) RepairType (F8) Money (F8).
BEGIN DATA
16 04/30/2009 115 23
30 03/25/2009 103 62
30 01/24/2009 209 45
47 04/09/2009 101 69
47 04/09/2009 209 78
END DATA.
 
DATASET NAME Original.
 
SORT CASES BY ID RepairDate RepairType.
TEMP.
SELECT IF RepairType<>209.
DATASET DECLARE ExtraRepairs.
AGGREGATE
  /OUTFILE='ExtraRepairs'
  /BREAK=ID RepairDate
  /MoreJobsPlus=N
  /MoreMoneyPlus=SUM(Money).
 
MATCH FILES /FILE=*
  /TABLE='ExtraRepairs'
  /BY  ID RepairDate.
EXECUTE.
 
IF RepairType<>209 MoreJobsPlus=0.
IF RepairType<>209 MoreMoneyPlus=0.
EXE.
 
RECODE MoreJobsPlus MoreMoneyPlus (SYSMIS=0).
EXE.

2009/5/11 abdelrhman elmubarak <abdelrhmm@...>
thanks Melissa
I am finding difficulty if there are more than one possible extra repair on the same day , your synatx work very fine if there are one repair on the same day...any help is higly appreciated.
thanks
Abdulrahman
 

Date: Thu, 7 May 2009 09:14:37 -0500
From: mives@...
Subject: Re: creating new variables

To: SPSSX-L@...

One way would be to use the sort function so that the 209 record is last.  (it may help to create a dichotomy for rep209=1 or 0 if not--something like this would be needed if there are >2 repairs in a day)
Then do a lag function to create morejobs and moremoney.
 
THE FOLLOWING ASSUMES that no client has >2 repairs in a day AND 209 is the highest repair value.
 
sort cases by id repdate reptype.
if (id=lag(id) and repdate=lag(repdate) and reptype=209) morejobs=1.
if ((id ne lag(id) or repdate ne lag(repdate)) and reptype=209) morejobs=0.
if (id=lag(id) and repdate=lag(repdate) and reptype=209) moremoney=lag(money).
 
 
The actual syntax will differ if there are more than one possible extra repairs on the same date (i.e. one id could have 3+ per day), but similar logic should work.
 
HTH,
Melissa 
 

From: SPSSX(r) Discussion [mailto:SPSSX-L@...] On Behalf Of abdelrhman elmubarak
Sent: Thursday, May 07, 2009 3:36 AM
To: SPSSX-L@...
Subject: [SPSSX-L] creating new variables


  

Hi

my data looks as below

 

id

Repair Date

Repair Type

money

16

20090430

115

23

30

20090325

209

45

30

20090124

103

62

47

20090409

209

78

47

20090409

101

69


 

I want to create two more variables for those  who  did repair type 209…the purpose is to know did they did more jobs on the same day of their visit and what the money generated from that ….at the final my data should be look as below

 

id

Repair Date

Repair Type

money

more jobs plus

more money plus

16

20090430

115

23

 

 

30

20090325

209

45

0

 

30

20090124

103

62

 

 

47

20090409

209

78

1

69

47

20090409

101

69

 

 


 

I can explain more if it is required

Thanks in advance

 

Abdulrahman

 


Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!

Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.


What can you do with the new Windows Live? Find out

 « Return to Thread: creating new variables