<<

SPSS SAS Format discussed point-and-click syntax syntax in this help sheet (To see syntax, use point- (others may and-click commands, exist) click on “paste.” Pastes syntax for command in a new window.) Work environment Data/variable view Program editor for programming (data Command window OR Do file for manipulation and analyses) programming Pull-down menus for data manipulation and Log shows data analyses run and any Log file contains log and results analyses messages

Output contains log and Output contains results results Missing values for Largest value Smallest value Largest value numeric variables (.)

Case, spacing, (syntax not case-sensitive, Case and spacing between words don’t Case and spacing matter - Stata abbreviations except when recoding matter commands in lower case string variables) Cannot abbreviate commands Can abbreviate (underlined in documentation) End of line (syntax uses a period) Semi-colon (;) Carriage return is default. If you use delimiter this default, keep typing code on one line. Can use /// at the end of line or set a different delimiter. If you want a semi-colon, type “#delimiter ;” Keeping a record of Save output file when you Save log file and output when you are Start log file at beginning of session; your session are finished with session finished with session close log file at end

1

SPSS SAS Stata Getting data into File Æ Open Æ Data… Æ libname mydata “f:\data”; use “f:\data\wave1.dta”, program (when Click Open data a; set mydata.wave1; clear data is formatted for program)

Create/save new File Æ Save As Æ Click data new; set old; save “f:\data\wave1a.dta” data set from old Save run; or overwrite old data set File Æ Save Æ Click Save data new; set new; save “f:\data\wave1a.dta” run; , replace • use if wave1a.dta already exists, but you want to overwrite it

Merge data Data Æ Merge files Æ proc sort data = a; Data set that is open will be master file Add variables Æ by id; run; onto which other data set is merged Choose an SPSS data (data sets must be sorted by common file to merge onto active proc sort data = b; variable first). data set Æ Choose by id; run; variables to include and sort id variable (like id) to data ; merge id using “f:\b.dta” merge by Æ OK merge a b; by id; run; Concatenate data Data Æ Merge files Æ data c; Data set that is open will be master file Add cases Æ Choose an set a b; run; onto which other data set is merged. SPSS data file to merge onto active data set Æ append using “f:\b.dta” Choose variables to include. Æ OK Description of data Variable view proc contents; run; describe set (variables included)

2

SPSS SAS Stata List values of Analyze Æ Reports Æ OK proc print; variables Case Summaries var x1 x2; list x1 x2 • Unselect boxes run; • for all cases “Limit cases to first…” and “Show proc print data=wave1 only valid cases” (obs=100); list x1 x2 in 1/100 • Select box “Limit var x1 x2; • for specific cases to first…” run; number of cases

Keep/drop In data or variable view, data wave1 (keep=x1 x2); keep x1 x2 variables can select variable’ set wave1; column or row; right run; click; click on Clear to drop variables. data wave1 (drop=x1 x2); drop x1 x2 set wave1; run; Keep/select Data Æ Select cases Æ data wave1; keep if male==1 observations that Click button “If set wave1; meet some condition is satisfied” Æ if male=1; criterion Click “If” Æ Type run; (e.g. keep only “male = 1” in box. Æ males) OK

3

SPSS SAS Stata Value labels In Variable View, click on 1: Define values 1: Define values Value for variable. Enter value and label, proc format; label define sex 1 “male” click add, etc. value sex 2 “female” 1=“male” label define likert 1 “sd” 2 =“female”; 2 “d” 3 “nad” 4 “a” 5 run; “sa”

2: Assign value labels to variables in 2: Assign value labels to variables data step. label values gender sex data new; set new; label values var1 likert format gender sex.; label values var2 likert run; Create new Transform Æ Compute variables variable Æ Type name of generate gender = b3 new variable (gender) in gender = b3; Create variable box “Target variable”; gender that is Type name of old variable (b3) in “Numeric same as existing expression” box Æ OK

variable b3 Transform Æ Compute generate var2 = x1*1000 Create variable x2 variable Æ Type name of x2 = x1*1000; that equals new variable (x2) into existing variable “Target variable”; Type x1*1000 expression x1*1000 Æ OK

Transform Æ Recode into Create variable different variables Æ Enter male (1=male, new variable name and old generate male = 1 variable name Æ Enter old male =.; replace male = 0 if sex==2 0=female) from and new values by clicking variable sex if sex=1 then male = 1; “Old and new values” Æ else if sex = 2 then male (1=male, Specify “if” conditions if = 0; 2=female) necessary by clicking “If” button Æ OK

4 SPSS SAS Stata Commands with When computing and 1st: condition 1st: command “if” recoding variables, 2nd: something happens 2nd: condition SPSS allows you to if…then… generate … if … specify “if” conditions if gender=1 then male=1; else if gender=2 then male=0; Reverse code Transform Æ Recode into if x1 = 1 then x1r = 5; recode x1 x2 (1=5) (2=4) variables different variables (or if x1 = 2 then x1r = 4; (3=3) (4=2) (5=1) same variables) Æ Enter if x1 = 3 then x1r = 3; new variable name and if x1 = 4 then x1r = 2; old variable name Æ if x1 = 5 then x1r = 1; Enter old and new values by clicking “Old and new values” Æ Specify “if” conditions if necessary by clicking “If” button Æ OK

Transform Æ Compute x1r = 6 – x1; generate x1r = 6 – x1 variable Æ Enter name of new variable and numeric expression (e.g. x1r = 6 – x1) Æ OK Recode multiple With point-and-click, must data new; set new; foreach i in x1 x2 x3 { numeric missings recode individually array miss {3} x1 x2 [enter] to “.” x3; replace `i' = . if `i' == do i = 1 to 3; 99 [enter] if miss{i} = 99 then } miss{i} = .; end; (left ` on “i” is key to run; left of “1” on keyboard) Frequencies Analyze Æ Descriptive proc freq; tab x1 x2 x3 Æ Frequencies tables x1 x2 x3; Æ Choose variables & run; options Æ OK

5

SPSS SAS Stata Descriptive Analyze Æ Descriptive proc means; summarize x1 x2 x3 statistics statistics Æ Frequencies/ var x1 x2 x3; Descriptives/Explore run; etcÆ Choose variables • gives N, mean, std. deviation, min, & options Æ OK max summarize x1 x2 x3, detail proc univariate; var x1 x2 x3; codebook var1 var2 var3 run; • gives above stats, plus more

Cross-tabulation Analyze Æ Descriptive proc freq; tab2 x1 x2 statistics Æ Crosstabs Æ tables x1*x2; Choose variables & run; options Æ OK • w/ chi-squared (for chi-squared, choose proc freq; tab2 x1 x2, chi2 “chi-square” under tables x1*x2/chisq; statistics. run; Correlation Analyze Æ Correlate Æ proc corr; pwcorr x1 x2, obs sig Bivariate Æ Choose var x1 x2; run; variables & options Æ OK Independent Analyze Æ Compare proc ttest; ttest x1, by(gender) sample t-test means Æ Independent- class gender; e.g. compare means Samples T Test Æ Choose var x1; run; on variable x1 variables & options Æ OK for males versus females ANOVA (one-way) Analyze Æ Compare proc anova; anova x1 race e.g. Compare Means Æ One-way class race; means of x1 for ANOVA Æ Choose model x1 = race; racial groups. variables & options Æ OK means race/tukey; means race/bon; run;

6

SPSS SAS Stata Simple linear Analyze Æ Regression Æ proc reg; reg y1 x1 x2 x3 regression Linear Æ Choose variables model y1 = x1 x2 x3; e.g. DV = y1, IVs = & options Æ OK run; x1-x3 Analyze Æ Regression Æ proc logistic descending; logistic y2 x1 x2 x3 e.g. dichotomous Binary Logistic Æ Choose model y2 = x1 x2 x3/expb; DV = y1, IVs = x1- variables & options Æ OK run; x3

Resources: Acock, A. C. (2005). SAS, Stata, SPSS: A Comparison. Journal of Marriage and Family, 67, 1093-1095.

Blanchett, D. Stata for the Struggling SAS Mind. (http://www.cpc.unc.edu/services/computer/presentations/sas_to_stata/Stata_for_the_Struggling_SAS_Mind.pdf)

Delwiche, L. D. & Slaughter, S. J. (2003). The Little SAS Book: A Primer, 3rd Ed. Cary, NC: SAS Institute, Inc.

Mitchell, M. M. (2007). Strategically using General Purpose Statistics Packages: A Look at Stata, SAS and SPSS. UCLA ATS Statistical Consulting Group, Technical Report Series, Report #1. (http://www.ats.ucla.edu/stat/technicalreports/number1_editedFeb_2_2007/ucla_ATSstat_tr1_1.1_0207.pdf)

Also see Programming Tools on CFDR webpage (http://www.bgsu.edu/organizations/cfdr/page36022.html)

7