MICS Data Processing Workshop

advertisement
Multiple Indicator Cluster Surveys
Data Processing Workshop
SPSS general commands
Overview
MICS4 Data Processing Workshop
SPSS Statistics
– Statistical Package for the Social Sciences
– SPSS is a full-featured data analysis program that
offers a variety of applications including data base
management, statistical analysis and graphics
– The SPSS program runs on a wide variety of
mainframe, mini, and microcomputers
– The most recent version is SPSS 20, which runs
on both Windows and Macintosh computers
MICS4 Data Processing Workshop
Data management using the SPSS
Statistics command language
– Data bases:
• FILE_NAME.SAV
– IN MICS: HH.sav, TN.sav, HL.sav, WM.sav,
CH.sav, BH.sav, FG.sav and MN.sav
•
•
•
•
•
Getting Data into SPSS Statistics
Merging data
Aggregating data
Weighting data
And many more
MICS4 Data Processing Workshop
Programming with SPSS Statistics
– SPSS syntax files:
• FILE_NAME.SPS
• Build and run command syntax
• Get data, add new variables, and append cases to the active
dataset
• Create new datasets
• Concurrently access multiple open datasets
• Get output results
• Create tables
• And many more
MICS4 Data Processing Workshop
Programming with SPSS Statistics
• Although many of the tasks can be performed
with the menus and dialog boxes, some very
powerful features are available only with
command syntax
MICS4 Data Processing Workshop
Creating Command Syntax Files
• An command file is a simple text file. You can
use any text editor to create a command syntax
file, but SPSS Statistics provides a number of
tools to make your job easier
• Use the Paste button. Make selections from
the menus and dialog boxes, and then click
the Paste button instead of the OK button. This
will paste the underlying commands into a
command syntax window.
MICS4 Data Processing Workshop
Creating Command Syntax Files
• SPSS program commands follow very specific
syntax rules, which are described in various
SPSS publications:
• All commands must begin in the first column
of a line and be spelled correctly
MICS4 Data Processing Workshop
Creating Command Syntax Files
• Most commands include additional
information (e.g., names of variables the
command is to be applied to, options for
processing data, displaying results, etc.)which
may be continued on the same line using the
appropriate delimiter (e.g., blank space, comma,
slash)
• or continued on an additional line(s) provided
that the continuation begins after column 1
MICS4 Data Processing Workshop
Creating Command Syntax Files
• Commands can be typed in either upper or
lower case
• Most SPSS commands have default
specifications, i.e., the options that will be used
unless you tell SPSS to use something else
MICS4 Data Processing Workshop
Overview of the commands
–
–
–
–
Data definition
File interfaces
Analyze data
Modify data
MICS4 Data Processing Workshop
Data definition
– These commands:
(1) bring raw data into SPSS, either from
another file, or by typing it in yourself,
and
(2) enter descriptive information about the
data.
MICS4 Data Processing Workshop
Data definition
Commands:
DATA LIST
VARIABLE LABELS
VALUE LABELS
MISSING VALUES
MICS4 Data Processing Workshop
Data list
EX:
DATA LIST
FILE='C:\MICS4\SPSS\MYHH.DAT'
RECORDS=1
MICS4 Data Processing Workshop
Variable and value labels
EX:
variable label type "Main source of drinking
water".
value label type
1 "Improved sources"
2 "Unimproved sources".
MICS4 Data Processing Workshop
File interfaces
• These commands access and save
SPSS system files
MICS4 Data Processing Workshop
File interfaces
Commands:
GET FILE
SAVE OUTFILE
MICS4 Data Processing Workshop
Get file
EX:
get file = 'hh.sav'.
Set outfile = 'hh.sav'.
MICS4 Data Processing Workshop
Analyze data
• These commands actually do
statistical analysis
ex.
frequencies
variables=hc2 hc3 hc4 hc5 hc6 hc8 hc8a
hc9a hc9b hc9c hc9d hc9e hc9f hc9g hc9h hc9i hc9j hc9k hc9l hc9m hc9n hc9o
hc10a hc10b hc10c hc10d hc10e hc10f
hc11 hc12 hc13 hc14a hc14b hc14c hc14d hc14e hc14f
ws1 ws2 ws7
/statistics=stddev mean
/order=analysis .
MICS4 Data Processing Workshop
Modify data
• These commands alter data and
change file characteristics.
MICS4 Data Processing Workshop
Modify data
• These commands alter data and
change file characteristics.
MICS4 Data Processing Workshop
Modify data
Commands:
COMPUTE
RECODE
IF
SELECT IF
MICS4 Data Processing Workshop
Compute
Ex.
compute persroom = 99.
if (hc2 < 98) persroom = hh11/hc2.
variable label persroom 'Persons per sleeping rooms'.
missing values persroom (99).
MICS4 Data Processing Workshop
Recode
Ex.
recode improved (100 = 1) (else = 2) into type.
variable label WS1 "".
variable label type "Main source of drinking water".
value label type
1 "Improved sources"
2 "Unimproved sources".
MICS4 Data Processing Workshop
IF
compute improved = 0.
if (WS1 = 11 or WS1 = 12 or WS1 = 13 or WS1 = 14 or WS1 = 15 or
WS1 = 21 or WS1 = 31 or WS1 = 41 or
WS1 = 51) improved = 100.
if ((WS2 = 11 or WS2 = 12 or WS2 = 13 or WS1 = 14 or WS1 = 15 or
WS2 = 21 or WS2 = 31 or WS2 = 41 or
WS2 = 51) and WS1 = 91) improved = 100.
variable label improved "Percentage of household population using
improved sources of drinking water *".
MICS4 Data Processing Workshop
SELECT IF
select if (hh9 = 1).
select if (wm7 = 1).
select if (uf9 = 1).
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• 4 – 8 SPSS MICS4 data files are produced for each
survey, corresponding to the main units of analysis:
• Households - hh.sav
• Household members - hl.sav
• Women in reproductive age (15-49 years of age) –
wm.sav
• Children under the age of five – ch.sav
• FGM – fg.sav
• Birth history – bh.sav
• Treated nets – tn.sav
• Men in reproductive age (15 – 59 years of age) – mm.sav
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• hh.sav
• Relations with:
hl.sav, wm.sav, ch.sav, bh.sav, fg.sav, tn.sav, mm.sav
• Base key variables:
HH1 (cluster number) and
HH2 (household number)
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• hl.sav
• Relations with: wm.sav, ch.sav, mm.sav, bh.sav, fg.sav
• Base key variables:
HH1 (cluster number),
HH2 (household number) and
HL1 (member’s line number)
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• wm.sav, ch.sav, mn.sav
• Relations with: hh.sav, hl.sav
• Base key variables:
HH1 (cluster number),
HH2 (household number) and
LN (HL1) (member’s line number)
IMPORTANT NOTE: variable HL1 in hl.sav data file is named LN in wm.sav ,ch.sav
and mn.sav files. Renaming of the variable is required prior to merging.
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• bh.sav
• Relations with: hh.sav, hl.sav, wm.sav
• Base key variables:
HH1 (cluster number),
HH2 (household number) and
HL1 (member’s line number)
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• tn.sav
• Relations with: hh.sav, hl.sav
• Base key variables:
HH1 (cluster number),
HH2 (household number) and
HL1 (member’s line number)
MICS4 Data Processing Workshop
MERGING FILES IN MICS4
• mn.sav
• Relations with: hh.sav, hl.sav
• Base key variables:
HH1 (cluster number),
HH2 (household number) and
HL1 (member’s line number)
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
• Make sure both files are sorted in ascending order
by key variables before trying to merge.
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
• From the menus choose: Data…. Merge Files…. Add
Variables...
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
• Select the file you wish to merge:
If the file is already open select it from the list of „an open dataset“, and if it is not then browse
for the file.
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
• Select the file you wish to merge:
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
• SPSS will give you a warning regarding sorted key
variables. Make sure both files were sorted in
ascending order before trying to do a file merge.
MICS4 Data Processing Workshop
Example on how to merge hh.sav onto a
wm.sav
* open the women file.
get file ="wm.sav“.
* sort cases by ID variables.
sort cases HH1 HH2 LN.
save outfile = "wm.sav".
* open the household file.
get file ="hh.sav".
* sort cases by ID variables.
sort cases HH1 HH2.
save outfile = "hh.sav".
* merge the household data file onto the women file.
match files
/file = "wm.sav"
/table = 'hh.sav'
/by HH1 HH2 .
*save the women's file.
save outfile = 'wm.sav'.
MICS4 Data Processing Workshop
Aggregate data
• Aggregate data aggregates groups of cases in the active
dataset into single cases and creates a new, aggregated
file or creates new variables in the active dataset that
contain aggregated data
• Cases are aggregated based on the value of zero or
more break (grouping) variables. If no break variables
are specified, then the entire dataset is a single break
group
MICS4 Data Processing Workshop
Aggregate data
DATASET ACTIVATE DataSet1.
DATASET DECLARE aggr.
AGGREGATE
/OUTFILE='aggr‘
/BREAK=HH1 HH2
/HL6_mean_1=MEAN(HL6).
MICS4 Data Processing Workshop
Download