Id when a case, wihtin same id value, ever equals a value within a variable

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Id when a case, wihtin same id value, ever equals a value within a variable

cfishernyc
I need to be able to create a variable that will indicate, across multiple cases that have the same ID variable value, whether a case type variable ever equaled a certain value.

So, in the example below of what i want to get, the syntax would create EverSEC and ONLYSEC, with 1=yes and 0=NO.

Example

ID         Type    EverSEC   ONLYSEC
123       SEC     1             0
123       SEC     1             0
123       NSD     1             0
456       SEC     1              1
456       SEC     1              1
456       SEC     1              1
789       NSD     0              0
789       NSD     0              0
Reply | Threaded
Open this post in threaded view
|

Re: Id when a case, wihtin same id value, ever equals a value within a variable

ViAnn Beadle
This approach sets a numeric variable to 1 if type is equal to SEC.
Aggregate then computes the min and max of that variable for each group of
ids.
MODE=ADDVARIABLES assigns the min and max of the group to each case within
the group.

RECODE Type ('SEC'= 1)(ELSE = 0) into TypeNUM.

DATASET ACTIVATE DataSet0.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=ID
  /TypeNUM_min=MIN(TypeNUM)
  /TypeNUM_max=MAX(TypeNUM).

*initialize vars.
COMPUTE EverSEC = 0.
COMPUTE ONLYSEC = 0.

if TypeNUM_max eq 1 EverSEC=1.
if TypeNUM_max eq 1 and TypeNUM_min eq 1 ONLYSEC=1.
EXECUTE.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
cfishernyc
Sent: Thursday, March 19, 2009 3:13 PM
To: [hidden email]
Subject: Id when a case, wihtin same id value, ever equals a value within a
variable

I need to be able to create a variable that will indicate, across multiple
cases that have the same ID variable value, whether a case type variable
ever equaled a certain value.

So, in the example below of what i want to get, the syntax would create
EverSEC and ONLYSEC, with 1=yes and 0=NO.

Example

ID         Type    EverSEC   ONLYSEC
123       SEC     1             0
123       SEC     1             0
123       NSD     1             0
456       SEC     1              1
456       SEC     1              1
456       SEC     1              1
789       NSD     0              0
789       NSD     0              0
--
View this message in context:
http://www.nabble.com/Id-when-a-case%2C-wihtin-same-id-value%2C-ever-equals-
a-value-within-a-variable-tp22608426p22608426.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD