ID variable

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

ID variable

Sam Ballard
Hi All,

I have a dataset with duplicate cases and I'm trying to create a new
variable (see below). I want the new variable equal to one if VAR1 equaled
one for any of the ID's. Does anyone know a simple way to do this?

ID     var1   new
101     0     1
101     0     1
101     1     1
102     0     0
102     0     0
103     1     1
103     0     1
103     0     1

Thanks,
Sam
SDCCD

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: ID variable

Maguin, Eugene
Sam,

There are at least two ways (and maybe more) to do this.

My usual way would be this.

Sort cases by id (a) var1 (d).
Compute new=0.
Do if ($casenum eq 1 or id ne lag(id)).
+  if (var1 eq 1) new=1.
Else.
+  if (lag(new) eq 1) new=1.
End if.


But another way that others may have suggested is this. I haven't use this
method but it should work.

Aggegate outfile=* mode=addvariables/break=id/new=fgt(var1,0).

Recode new(0=0)(else=1).


Gene Maguin




>>I have a dataset with duplicate cases and I'm trying to create a new
variable (see below). I want the new variable equal to one if VAR1 equaled
one for any of the ID's. Does anyone know a simple way to do this?

ID     var1   new
101     0     1
101     0     1
101     1     1
102     0     0
102     0     0
103     1     1
103     0     1
103     0     1

Thanks,
Sam
SDCCD

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: ID variable

Bruce Weaver
Administrator
In reply to this post by Sam Ballard
Sam Ballard wrote
Hi All,

I have a dataset with duplicate cases and I'm trying to create a new
variable (see below). I want the new variable equal to one if VAR1 equaled
one for any of the ID's. Does anyone know a simple way to do this?

ID     var1   new
101     0     1
101     0     1
101     1     1
102     0     0
102     0     0
103     1     1
103     0     1
103     0     1

Thanks,
Sam
SDCCD
* IF 0 and 1 are the only possible values for VAR1,
* and if the cases are already sorted by ID,
* let NEW = the maximum value of VAR1 within each ID.

aggregate / break = id / new = max(var1).
list.

The output:

 ID var1 new

101    0   1
101    0   1
101    1   1
102    0   0
102    0   0
103    1   1
103    0   1
103    0   1

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).