SPSS tips and tricks for the initiated

advertisement
SPSS tips and tricks
for the initiated
Ways of working
• Use menus to run commands
• Use menus, paste commands, run
• Write commands, run
• Your main product: ”The Syntax File” !!
29.05.2016
H.S.
2
Viewer
• Contains all output
– Show/hide or delete elements
– Double-click to edit element
– Double-click on chart to start Chart Editor
29.05.2016
H.S.
3
Select and Filter
Select if (age>50).
Compute ff=(age>50).
Filter by ff.
…
Filter off.
Temporary
Select if (age>50).
command.
29.05.2016
H.S.
4
Compute and If
If (age<=50) old=0.
If (age>50) old=1.
Compute old=(age>50).
Comp oldMale=0.
If (age>50 and sex=1)
oldMale=1.
Compute oldMale=
(age>50 and sex=1).
Compute id=$casenum.
29.05.2016
H.S.
5
Recode
recode age (missing=sysmis) (lowest thru 29=1)
(30 thru 39=2) (40 thru highest=3) into ageGr3.
or
comp ageGr3=1+(age>=30) +(age>=40).
variable label ageGr3 ’Age in 3 groups’.
value label ageGr3 1’29 years’ 2’30-39 years’ 3’40 years’.
Rank age /ntiles(3) into ageGr3.
Examine age by ageGr3 /plot=none.
29.05.2016
H.S.
6
Missing
• System missing
– Empty values are marked ”.” and called
sysmis
• User missing
– Set to missing:
– Set to value:
missing age (999).
missing age ().
• Selection
– Remove sysmis:
select if (not sysmis(age))
– Remove all missing: select if (not missing(age))
29.05.2016
H.S.
7
Set to missing
• Make new variable
compute miss=1.
recode miss (1=sysmis).
• Use the miss variable
If (age>120) age=miss.
29.05.2016
H.S.
8
Functions that ignore missing
• Sum function
compute s1=a1+a2+a3.
compute s1=Sum(a1,a2,a3).
compute s1=Sum.2(a1,a2,a3).
• Function list
– Sum, Product, Min, Max, Mean
29.05.2016
H.S.
9
Execute.
–Edit, Options, Data,
• Calculate values immediately / before used
• Example
Transformations pending
compute a=1.
execute.
compute b=a+1.
freq b.
29.05.2016
H.S.
10
Long and wide data
• Data, Restructure
Long:
id
1
1
2
Blood
0.1
0.2
0.4
29.05.2016
Wide:
Fat
4.1
4.2
4.5
id
1
2
H.S.
Blood1
0.1
0.4
Blood2
0.2
.
Fat1
4.1
4.5
Fat2
4.2
.
11
Variable order
• Variable order and display
– Edit, Options, General,
• Alphabetical / File
• Labels / Names
• Save workfile
save outfile= ’h:\Data\file1.sav’ /Keep=id age sex educ…
29.05.2016
H.S.
12
Download