SPSS SELECT IF – Tutorial & Examples
In SPSS, SELECT IF permanently removes
a selection of cases (rows) from your data.
SELECT IF in SPSS basically means “delete all cases that don't satisfy one or more conditions”. Like so, select if(gender = 'female'). permanently deletes all cases whose gender is not female. Let's now walk through some real world examples using bank_clean.sav, partly shown below.
Example 1 - Selection for 1 Variable
Let's first delete all cases who don't have at least a Bachelor's degree. The syntax below:
*Show values and value labels in new output tables.
set tnumbers both.
*Run minimal frequencies table.
*Select cases with a Bachelor's degree or higher. Delete all other cases.
select if(educ >= 4).
As we see, our data now only contain cases having a Bachelor's, Master's or PhD degree. Importantly, cases having
on education level have been removed from the data as well.
Example 2 - Selection for 2 Variables
The syntax below selects cases based on gender and education level: we'll keep only female respondents having at least a Bachelor's degree in our data.
*Inspect contingency table sex and education.
crosstabs educ by gender.
*Select females having a Bachelor's degree or higher.
select if(gender = 0 & educ >= 4).
*Reinspect contingency table.
crosstabs educ by gender.
Example 3 - Selection for (Non) Missing Values
Selections based on (non) missing values are straightforward if you master SPSS Missing Values Functions. For example, the syntax below shows 2 options for deleting cases having fewer than 7 valid values on the last 10 variables (overall to q9).
*Select cases having at least 7 non missing values out of last 10 questions.
select if(nvalid(overall to q9) >= 7)./*At least 7 valid values or at most 3 missings.
*Alternative way, exact same result.
select if(nmiss(overall to q9) < 4)./*Fewer than 4 missings or more than 6 valid values.
Tip 1 - Inspect Selection Before Deletion
Before deleting cases, I sometimes want to have a quick look at them. A good way for doing so is creating a FILTER variable. The syntax below shows the right way for doing so.
*Create filter variable holding only zeroes.
compute filt_1 = 0.
*Set filter variable to 1 for cases we want to keep in data.
if(nvalid(overall to q9) >= 7) filt_1 = 1.
*Move unselected cases to bottom of dataset.
sort cases by filt_1 (d).
*Scroll to bottom of dataset now. Note that cases - will be deleted because they have 0 on filt_1.
*If selection as desired, delete other cases.
Quick note: select if(filt_1). is a shorthand for select if(filt_1 <> 0). and deletes cases having either a zero or a missing value on filt_1.
ResultCases that will be deleted are at the bottom of our data. We also readily see we'll have cases left after doing so.
Tip 2 - Use TEMPORARY
A final tip I want to mention is combining SELECT IF with TEMPORARY. By doing so, SELECT IF only applies to the first procedure that follows it. For a quick example, compare the results of the first and second FREQUENCIES commands below.
*Make sure case deletion only applies to first procedure.
*Select only female cases.
select if(gender = 0).
*Any procedure now uses only female cases. This also reverses case selection.
frequencies gender educ.
*Rerunning frequencies now uses all cases in data again.
frequencies gender educ.
First off, parentheses around conditions in syntax are not required. Therefore, select if(gender = 0). can also be written as select if gender = 0. I used to think that shorter syntax is always better but I changed my mind over the years. Readability and clear structure are important too. I therefore use (and recommend) parentheses around conditions. This also goes for IF and DO IF.
Right, I guess that should do. Did I miss anything? Please let me know by throwing a comment below.
Thanks for reading!
SPSS IF – A Quick Tutorial
In SPSS, IF computes a new or existing variable
for a selection of cases. For analyzing a selection of cases, use FILTER or SELECT IF instead.
Data File Used for Examples
All examples use bank.sav, a short survey of bank employees. Part of the data are shown below. For getting the most out of this tutorial, we recommend you download the file and try the examples for yourself.
Example 1 - Flag Cases Based on Date Function
Let's flag all respondents born during the 80’s. The syntax below first computes our flag variable -born80s- as a column of zeroes. We then set it to one if the year -extracted from the date of birth- is in the RANGE through
*Create new variable holding only zeroes.
compute born80s = 0.
*Set value to 1 if respondent born between and
if(range(xdate.year(dob),,)) born80s = 1.
*Optionally: add value labels.
add value labels born80s 0 'Not born during 80s' 1 'Born during 80s'.
Example 2 - Replace Range of Values by Function
Next, if we'd run a histogram on weekly working hours -whours- we'd see values of hours and over. However, weeks only hold (24 * 7 =) hours. Even Kim Jong Un wouldn't claim he works hours per week!
We assume these respondents filled out their monthly -rather than weekly- working hours. On average, months hold (52 / 12 =) weeks. So we'll divide weekly hours by but only for cases scoring or over.
*Sort cases descendingly on weekly hours.
sort cases by whours (d).
*Divide or more hours by (average weeks per month).
if(whours >= ) whours = whours /
We could have done this correction with RECODE as well: RECODE whours ( = )( = ). Note, however, that RECODE becomes tedious insofar as we must correct more distinct values. It works reasonably for this variable but IF works great for all variables.
Example 3 - Compute Variable Differently Based on Gender
We'll now flag cases who work fulltime. However, “fulltime” means 40 hours for male employees and 36 hours for female employees. So we need to use different formulas based on gender. The IF command below does just that.
*Compute fulltime holding only zeroes.
compute fulltime = 0.
*Set fulltime to 1 if whours >= 36 for females or whours >= 40 for males.
if(gender = 0 & whours >= 36) fulltime = 1.
if(gender = 1 & whours >= 40) fulltime = 1.
*Optionally, add value labels.
add value labels fulltime 0 'Not working fulltime' 1 'Working fulltime'.
means whours by gender by fulltime
/cells min max mean stddev.
Our syntax ends with a MEANS table showing minima, maxima, means and standard deviations per gender per group. This table -shown below- is a nice way to check the results.
The maximum for females not working fulltime is below The minimum for females working fulltime is And so on.
SPSS IF Versus DO IF
Some SPSS users may be familiar with DO IF. The main differences between DO IF and IF are that
- IF is a single line command while DO IF requires at least 3 lines: DO IF, some transformation(s) and END IF.
- IF is a conditional COMPUTE command whereas DO IF can affect other transformations -such as RECODE or COUNT- as well.
- If cases meet more than 1 condition, the first condition prevails when using DO IF - ELSE IF. If you use multiple IF commands instead, the last condition met by each case takes effect. The syntax below sketches this idea.
DO IF - ELSE IF Versus Multiple IF Commands
*DO IF: respondents meeting both conditions get result_1.
else if(condition_2). /*excludes cases meeting condition_1.
*IF: respondents meeting both conditions get result_2.
if(condition_2) result_2. /*includes cases meeting condition_1.
SPSS IF Versus RECODE
In many cases, RECODE is an easier alternative for IF. However, RECODE has more limitations too.
First off, RECODE only replaces (ranges of) constants -such as 0, 99 or system missing values- by other constants. So something like recode overall (sysmis = q1). is not possible -q1 is a variable, not a constant- but if(sysmis(overall)) overall = q1. works fine. You can't RECODE a function -mean, sum or whatever- into anything nor recode anything into a function. You'll need IF for doing so.
Second, RECODE can only set values based on a single variable. This is the reason why you can't recode 2 variables into one but you can use an IF condition involving multiple variables: if(gender = 0 & whours >= 36) fulltime = 1. is perfectly possible.
You can get around this limitation by combining RECODE with DO IF, however. Like so, our last example shows a different route to flag fulltime working males and females using different criteria.
Example 4 - Compute Variable Differently Based on Gender II
*Recode whours into fulltime for everyone.
recode whours (40 thru hi = 1)(else = 0) into fulltime2.
*Apply different recode for female respondents.
do if(gender = 0).
recode whours (36 thru hi = 1)(else = 0) into fulltime2.
*Optionally, add value labels.
add value labels fulltime2 0 'Not working fulltime' 1 'Working fulltime'.
means whours by gender by fulltime2
/cells min max mean stddev.
This tutorial presented a brief discussion of the IF command with a couple of examples. I hope you found them helpful. If I missed anything essential, please throw me a comment below.
Thanks for reading!
To select cases for inclusion into analysis call up .
Several options are offered:
- All Cases (default initial setting) Use it to remove a filter you have defined.
- If condition is satisfied: selects cases that satisfy a condition () you specify after selecting the If button. This is the most important option; see further explanations below.
- Random Sample of Cases case selection based on a random sample. The Sample button lets you specify e.g. the percentage of cases to select. [This corresponds to the SAMPLE command]
- Based on time or case range Mainly useful with time series data. Select a specific period or analysis.
- Use filter variable Selection based on a filter variable: A dummy variable with 0's and 1's, where values of 0 are excluded and values of 1 included. [This corresponds to the FILTER command.
Towards the bottom you will find an Output box
- Filtered out unselected cases removes unselected cases from analysis, but not from the data matrix. A remains active until turned off by . When the filter is turned off, all initial cases are again available for analysis. [A the command language level this corresponds to the FILTER command]
- Delete unselected cases Deletes all cases unselected from the data matrix, i.e. actually removes them and creates a subset of the initial cases. If you want the original cases back, you will need to re-read the original file.[At the command language level this corresponds to the SELECT IF command]
- Copy selected cases to a new dataset copies the selected to a new , visible in a new data editor window; the original dataset is not changed and unselected cases are not copied to the new dataset.
Select cases IF
When you hit If this dialog comes up. Specify the condition using a logical expression. The example gender=2 selects women (coded as 2 in the gender variable.
Continue back to the first dialog, then Ok.
If you selected Filtered you turned a filter on. The effect can be seen in the , where the filtered out cases are marked with a diagonal line through the row number. When you look at the status line at the bottom of the screen you will see
showing clearly that a filter is currently active.
An active filter means that all subsequent analyses will be performed only on the selected cases (in our example women), until the filter is turned off by . Of course a filter is also turned of when you open a different data file.
Note if you wish to know what filter is currently active you can call up the dialog to see it.
The frame for each command in the shows, among other things, the filter that was active when the output has been produced.
I will do everything for this and hope that you will appreciate it in the end. The girl grimaced: - That's what kind of person you are, even with all this, you find such words that you don't even look ugly after this vile proposal. Okay, - she pushed her luxurious black hair behind her back with a movement of her head.
Select multiple conditions if spss
Up and down, with force sitting down with her wet, perfectly fucked pussy on the coveted dildo. When the power of orgasmic convulsions subsided a little, Sandy got off Igor with a tired groan. She staggered slightly, her legs were shaking, her hair was disheveled, and her skin glistened with sweat, but the whole body of the young. Woman simply sang from the received carnal pleasure.If Conditional variable in spss
That's fine, the voice continued. - The Queen will fall asleep sweet and deep sleep. Bring me the key. I will wait for you at dawn tomorrow.
You will also like:
- Creative arts emmy winners 2020
- Angel name meaning urban dictionary
- Mr clean freak reviews
- Wichita falls funeral homes
- 2007 f150 steering wheel cover
- X shot nerf guns
- Honkai impact tier list
- 1999 f250 power steering pump
- Salvation army in louisville kentucky
- Mod map for minecraft pe
- Virginia beach court cases search
In order not to get dirty with sperm, I had to swallow it. This did not disgust her, on the contrary, Galya became even more aroused and had already begun to imagine how the boy would finally fuck her and she. Would be able to cum. But the boy cuddled her a little more and calmed down: - Go, buy yourself a big butt plug, insert it and go all tomorrow.
After work my friends and I will take care of you to the fullest.