Editing Data

advertisement
SPSS 18
Calculcate, Code and Edit Data
Sheila Dixon & Diane Skinner – September 2010
Editing Data
Go to Case
Adding a variable
If you have alterations to make to a case you can go
directly to the relevant case (row) number using the Go
to Case command.
1.
Position the active cell in the column to the right of
that to be inserted.
1.
2. Click on the Insert Variable button.
Select Go to Case from the Edit menu.
2. Enter the Data Editor row number for the case.
3. Change to variable view to alter the
variable type, column width etc.
3. Click on Go.
Adding a Case
Data Labels
Cases are normally added in the order they are
received, however if you wish to add a case into a row
of the data editor:
There are two types of labels that can be added:
1.
Value labels are useful if you have numeric codes
representing textual data, for instance 1 for Yes, 2 for
No - can be up to 60 characters.
Position your active cell in the row
below where you want to insert.
Variable labels can be 256 characters, rather than
the 8 allowed for the variable name enabling you to
give a better description of the contents.
2. Click on the Insert Case button
3. A blank row is inserted for a new case to be
entered.
Adding Value labels
Removing a Case
1.
If a case has been entered erroneously it can be
deleted.
1.
2. Click in the Label column in the relevant variables
row
Right click on the Case number at the left of the
data editor window.
3. Enter the label.
2. Select Clear from the Edit menu.
Adding Variable labels
Sorting Cases
1.
Double click on the variable name (or change to
Variable View).
1.
Select Sort Cases from the Data menu.
2. Highlight the variable to be sorted by.
Double click on the variable name (or change to
Variable View).
2. Click in the Values column for the relevant
variable.
3. Click on the arrowhead to add the variable to the
sort by box.
3. Click on the button to the right of the cell.
4. Enter the Value and Value label and click on Add.
5.
When all have been entered click OK.
Click to display
the dialog box
4. Select ascending or descending.
5.
If your labels do not appear in data view, choose Value
Labels from the View menu.
Click OK
ICT Learning
1
v_S18_02/1
Deleting a Variable Label
Calculating variables
1.
If the numerical data you have obtained isn’t quite
what you want to analyse, you can compute variables
from existing ones. i.e. if you want to analyse an
improvement in results, or difference in
measurements.
Double click on the variable name (or change to
Variable View).
2. Delete the text from the Label column for the
variable.
Deleting Value Labels
1.
1.
Double click on the variable name (or change to
Variable View).
2. Click in the Values column for the relevant
variable.
2. Type a name for
the variable to
be calculated in
the Target
Variable box.
3. Click on the button to the right of the cell.
4. Select the value to be deleted from the list
displayed at the bottom of the dialog box.
5.
Select Compute
Variable... from
the Transform
menu.
Click the Remove button, then OK
Viewing/Hiding Labels
1.
When transforming variables it is good practice to
create a new variable rather than overwriting the
existing one, that way if anything goes wrong you
still have the original.
Select Value Labels from the View menu.
User Missing Values
3. Add a variable and/or constants to the Numeric
Expression box.
If a value is missing it could just be left blank as SPSS
treats all blanks as missing values. However sometimes
it is useful to determine why the variable is blank, it
might be that the question was not relevant to the case,
or that the person refused to answer a question.
4. Add one of the numerical operators.
Plus
Missing values must be appropriate for the data type of
the variable, a numeric value for a numeric variable, a
text value for a string variable (missing values for
string variables must not be more than 8 characters
long).
Minus
Multiply
may be needed i.e.
3+2*6
gives the result
15
(3+2)*6
gives the result
30
Divide
To the power of
Defining Missing values
1.
Brackets
Double click on the variable name (or change to
Variable View).
5.
Repeat steps 3 and 4 until the formula for the
calculation is complete.
2. Click in the Values column for the relevant
variable.
6. Click OK.
3. Click on the button to the right of the cell.
Using a Function to calculate a variable
A function is a built-in equation available from within
SPSS. There are approximately 150 different functions.
They are used to perform mathematical, statistical,
textual or logical calculations.
4. In the dialog box, select
Discrete missing values
and enter the values
that represent missing
variables.
1.
Select Compute Variable... from the Transform
menu.
2. Add a name for the variable to be calculated.
3. Select the function to be used and double click to
add it to the expression box.
5.
Click OK.
4. Add the arguments for the function.
5.
ICT Learning
2
Click OK.
v_S18_02/1
Calculating using Date Functions
Recoding Data Variables
As well as using formulas you create yourself you can
use built in functions to calculate new variables.
Recoding variables allows you to group together ranges
of values for analysis. For example individuals ages
could be grouped up to 10, 11 to 20 etc.
Calculating an age
1.
The example below calculates the age at death of a
patient using two variables: dod (date of death), dob
(date of birth).
2. Add the variable to be recoded to the Input
Variable-->Output Variable box.
This involves a number of steps. SPSS stores dates and
times as the number of seconds since October 15th
1582, so the first task is to convert the date of birth
field into the number of days.
1.
From the Transform menu select Recode Into
Different Variables...
3. Enter the name of the Output variable (with a label
if required) and click on Change.
4. Click on the Old and New Values button.
Select Compute Variable... from the Transform
menu.
2. Type days as the target variable name.
3. Look through the list of functions, highlighting the
CTIME.DAYS(timevalue) function.
4. Paste it to the expression field (click the
button), or double click the highlighted function.
5.
With the ? between the brackets highlighted Add
the variable containing the end date:
CTIME.DAYS(dod)
Enter the minus sign and repeat the process above
with the dob variable. Click OK.
5.
Enter a range and the new value. Click on Add.
Type the group name
Choose
the
Lowest
through
option
An extra variable will have been added with the
heading “days” and each row will contain the
number of days the patient has been alive.
Now you have the number of days, the number of
years can be calculated by dividing by the number
of days in a year.
6. Select Compute Variable... from the Transform
menu, click Reset and type years as the Target
Variable.
7.
6. Repeat step 6 until all the ranges have been added.
7.
Click Continue and then OK.
Locate the TRUNC function (to display only the
whole years i.e. the ages) and add it to the
expression field. As the argument for the function,
type days/365. The function should be
TRUNC(days/365).
8. Click OK.
ICT Learning
3
v_S18_02/1
Download