selecting based on multiple variables

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

selecting based on multiple variables

Pam Greenwood
I don't see a way to select cases based on more than one variable.  For example, if I want to exclude cases who performed below a certain level on several variables, how would I do that?  The "If" statement only seems to take 1 variable.  Thanks
Reply | Threaded
Open this post in threaded view
|

Re: selecting based on multiple variables

Bruce Weaver
Administrator
Pam Greenwood wrote
I don't see a way to select cases based on more than one variable.  For
example, if I want to exclude cases who performed below a certain level on
several variables, how would I do that?  The "If" statement only seems to
take 1 variable.  Thanks
It sounds like you want to exclude cases that are below a given level on ALL of the variables in some set, is that right?  It might keep the logic clearer in your head if you first compute a variable that flags the cases you want to exclude, and then select the cases that are NOT so flagged.  E.g.,

compute excluded = (v1 LT cut1) and
                            (v2 LT cut2) and ... and
                            (vx LT cutx).
select if NOT excluded.
exe.

OR, if you want to set a filter (rather than delete the cases from the file):

compute excluded = (v1 LT cut1) and
                            (v2 LT cut2) and ... and
                            (vx LT cutx).
compute kept = NOT excluded.
filter by kept.
exe.

Here's a more general approach that might be tidier if the number of variables is large.

compute excluded = 1. /* initialize excluded flag to 1 .
format excluded (f1.0).
do repeat v = v1 v2 v3 v4 v5 / c = cut1 cut2 cut3 cut4 cut5 .
- if (v GE c) excluded = 0. /* if any V GE C, set exclude flag to 0 .
end repeat.
select if NOT excluded.
exe.

Replace "cut1 cut2 cut3 cut4 cut5" with the actual cutoff values for the 5 variables.  If the cutoff is the same in all cases, you could simply things a bit, as follows:

compute excluded = 1. /* initialize excluded flag to 1 .
format excluded (f1.0).
do repeat v = v1 v2 v3 v4 v5.
- if (v GE cut) excluded = 0. /* replace "cut" with the actual value .
end repeat.
select if NOT excluded.
exe.

If the cutoff the value is the same for all variables, I think another option would be to use COUNT.  Something like:

count numGEcut = v1 v2 v3 v4 v5 (cut thru HI). /* replace "cut" with actual cutoff value .
select if (numGEcut GE 1).
exe.

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

Re: selecting based on multiple variables

ViAnn Beadle
I suspect that the OP is talking about the dialog box to select cases. To
create a logical expression based upon more than one variable, click on the
second radio button which takes you to an expression building dialog box.
There you can specify a compound logical expression built from individual
variables and values  to create your filter variable. Note that Bruce's
examples use the COMPUTE command to build the expression via straight
syntax. The dialog box does as well.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Wednesday, December 02, 2009 7:29 AM
To: [hidden email]
Subject: Re: selecting based on multiple variables

Pam Greenwood wrote:
>
> I don't see a way to select cases based on more than one variable.
> For example, if I want to exclude cases who performed below a certain
> level on several variables, how would I do that?  The "If" statement
> only seems to take 1 variable.  Thanks
>
>

It sounds like you want to exclude cases that are below a given level on ALL
of the variables in some set, is that right?  It might keep the logic
clearer in your head if you first compute a variable that flags the cases
you want to exclude, and then select the cases that are NOT so flagged.
E.g.,

compute excluded = (v1 LT cut1) and
                            (v2 LT cut2) and ... and
                            (vx LT cutx).
select if NOT excluded.
exe.

OR, if you want to set a filter (rather than delete the cases from the
file):

compute excluded = (v1 LT cut1) and
                            (v2 LT cut2) and ... and
                            (vx LT cutx).
compute kept = NOT excluded.
filter by kept.
exe.

Here's a more general approach that might be tidier if the number of
variables is large.

compute excluded = 1. /* initialize excluded flag to 1 .
format excluded (f1.0).
do repeat v = v1 v2 v3 v4 v5 / c = cut1 cut2 cut3 cut4 cut5 .
- if (v GE c) excluded = 0. /* if any V GE C, set exclude flag to 0 .
end repeat.
select if NOT excluded.
exe.

Replace "cut1 cut2 cut3 cut4 cut5" with the actual cutoff values for the 5
variables.  If the cutoff is the same in all cases, you could simply things
a bit, as follows:

compute excluded = 1. /* initialize excluded flag to 1 .
format excluded (f1.0).
do repeat v = v1 v2 v3 v4 v5.
- if (v GE cut) excluded = 0. /* replace "cut" with the actual value .
end repeat.
select if NOT excluded.
exe.

If the cutoff the value is the same for all variables, I think another
option would be to use COUNT.  Something like:

count numGEcut = v1 v2 v3 v4 v5 (cut thru HI). /* replace "cut" with actual
cutoff value .
select if (numGEcut GE 1).
exe.



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context:
http://old.nabble.com/selecting-based-on-multiple-variables-tp26609016p26609
780.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
Reply | Threaded
Open this post in threaded view
|

Re: selecting based on multiple variables

Bruce Weaver
Administrator
ViAnn Beadle wrote
I suspect that the OP is talking about the dialog box to select cases. To
create a logical expression based upon more than one variable, click on the
second radio button which takes you to an expression building dialog box.
There you can specify a compound logical expression built from individual
variables and values  to create your filter variable. Note that Bruce's
examples use the COMPUTE command to build the expression via straight
syntax. The dialog box does as well.

Good catch, ViAnn--after re-reading the OP, I suspect you are right!

--
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/).