SPSS Syntax - Data Services

Transcription

SPSS SyntaxFor Academics

What is Syntax? Instructions to SPSS Just a text file GUI is creating and runing syntax

Why use Syntax Faster– Faster to type than to click– Faster to run Easier– Easy to do the same thing with different variables– Easier to find errors Better– Features not available on the menues– Ensures Replicability

Pew Social Trends Click the Workshop Files Icon: Choose SPSS Workshop Files Choose Pew Social Trends-Family Bonds Open “PST 11-05c.sav”– Double-Click or File Open (if SPSS is open)

StructureCOMMAND/SUBCOMMAND KEYWORD.

Look at the Syntax for the Get File How many commands? Copy it to a new syntax file

Options: Viewer

Obtaining SyntaxFile New SyntaxFrom ViewerDouble-Click syntax areaSelect, Copy, and Paste

ax.sps

DATASET DATASET NAMEDATASET ACTIVATETemporary namesImportant if multiple datasets are open,irrelevant otherwise

Good Practices

FilesA0Raw DataA1ImportA2SetupB0Raw yzeC1C2

StyleSPSS words are CAPSVariables are lower caseUse parenthesesPut command onmultiple lines Indent

COMMENTCOMMENT The following is for SPSS with Syntax.OR* The following Is for SPSS with Syntax.**********************.**** Leave a Comment ***.

Specific Skills

Variables & LabelsRENAME VARIABLES (sex gender) .VARIABLE LABELS gender “Respondent’s Gender”.MISSING VALUES q2 (9).MISSING VALUES q3a TO q3j (7,9).

FrequenciesFREQUENCIES VARIABLES q2/ORDER ANALYSIS.FREQUENCIES q2.FREQUENCIES q2 q75.

ComputeCOMPUTE has pet (q75 1).COMPUTE FUNCTION(stuff).AND &OR EQ OperationsNOT NE GT GE LT LE

RecodeRECODE q2 (1 1) (2 1) (3 0) INTO is happy.RECODE q2 (1 THRU 2 1) (3 0) INTO is happy.RECODE q2 (1 2 1) (3 0) INTO is happy.RECODE q2 (1, 2 1) (3 0) INTO is happy.

Keywords for RecodingTHRULO / LOWESTHI / HIGHESTELSEMISSINGSYSMISCOPYINTOlist of values or caseslowest valuehighest valueall other valuesuser or system missing valuesystem missing valueoutputs the same valuepreceeds name of new variable

Syntax can be written different #2RENAME VARIABLES (var1 one) (var2 two) .RENAME VARIABLES (var 1 var2 one two) .RENAME VARIABLESvar1 onevar2 two.

EXECUTE Can be abbreviated: EXE.Many executes slow it down.Typically needed once per file.Can be run at any time

Combining CommandsVARIABLE LABELShas pet “Has a Pet?”/ is happy “Happy?”.ORVARIABLE LABELS has pet “Has a Pet?” .VARIABLE LABELS is happy “Happy?” .

Value LabelsVALUE LABELS has pet0 No Pet1 Has a Pet.VALUE LABELS is happy1 Happy.ADD VALUE LABELS is happy0 Not Happy.

Syntax can be written different #1val labels has pet0 “No Pet”1 “Has a Pet” .value lab has pet 1 ‘Has a Pet’ 0 ‘No Pet’.VALUE LABELS has pet0 No Pet1 Has a Pet.

CrosstabsAnalyze Descriptive Statistics Crosstabs

General KeywordsVariablesBYfor factorsWITH for covariatesALLall variablesTOvariable list

Subcommand Efficiency Subcommands only needed to change defaultsCompare to pasted syntax FREQUENCIES gender. CROSSTABS q76dog by is happy.CROSSTABS q76dog by is happy /CELL COL ROW/STA CHISQ .

Combining CommandsCROSSTABS/TABLES has pet is happy BY married gender/TABLES has pet BY gender/TABLES is happy BY married/FORMAT DVALUE TABLES/CELLS COUNT EXPECTED COLUMN.

Handling Errors

COMPUTE timezone UPPER(tz)FREQUENCIES timezone

Don’t PanicFix the FirstIgnore the number of errorsand focus on the first one SPSS doesn’t stop for errors Fixing the 1st may fix othersRead the messageError messages are long butoften informative Identifies location of problem Gives suggestions

Look for Common ErrorsCheck for EXECUTEChanges to the data require anexecute Look for “TransformationsPending” in the Status Bar Type “EXECUTE.” and run it Needed after COMPUTE,RECODE, IF, and othersCheck for periodsThe most common error ismissing or extra periods Each command ends with aperiod Each period must end acommand Blank lines are treated aperiods

TroubleshootingRun all FrequenciesCopy your variables from eachcommand and run frequencies Confirm names are correct Confirm expected valuesRun each CommandStarting at the top, run eachcommand alone, step by step Highlight the syntax youwant to run

Correct CodeSTRING timezone (A3).COMPUTE timezone UPCASE(tz).

Tips

Creating Syntax in Excel Use Excel “Fill Down” for RepetativeCommands See SPSS Syntax.xlsx

Advanced Topics http://spsstools.net/

SPSS words are CAPS Variables are lower case Use parentheses Put command on multiple lines Indent . COMMENT . COMMENT The following is for SPSS with Syntax. OR * The following Is for SPSS with Syn