Select Page

Here is syntax to calculate Cohen’s d in SPSS. The final table provides a t-statistic, associated p-value and Cohen’s d.

**Assuming two variables in the SPSS data file labeled.
** IV – Independent variable (Groups 1 & 2);.
** DV – Dependent variable.

**First we conduct a t-test.
T-TEST
GROUPS=iv(1 2)
/VARIABLES=dv
/CRITERIA=CIN(.95) .
**The next step gives a graph with 95% CI.
GRAPH/ERRORBAR(CI 95)=DV BY IV
/TITLE=’Confidence Intervals for Means’.

**In the next step, make sure that the data is saved.
**because it changes the current data file.
AGGREGATE/OUTFILE=*/BREAK=iv/m2=MEAN(dv)/sd2=SD(dv)/n2=N.
COMPUTE N1=LAG(N2,1).
COMPUTE M1=LAG(M2,1).
COMPUTE sd1=LAG(sd2,1).
EXECUTE.
SELECT IF(IV=2).
EXECUTE.

* Compute Statements for Cohens d.
COMPUTE SP2=(((N1-1)*(sd1**2))+((N2-1)*(sd2**2)))/(N1+N2-2).
COMPUTE T=(M1-M2)/SQR(SP2*((1/N1)+(1/N2))).
COMPUTE DF=(N1+N2-2).
COMPUTE P = CDF.T(t,df) .
COMPUTE d=T*SQR((1/N1)+(1/N2)).
COMPUTE d=ABS(d).

FORMATS ALL(F8.2) DF N1 N2(F8.0) P(F8.4).
SUMMARIZE
/TABLES=d T DF P N1 N2
/FORMAT=NOLIST TOTAL
/TITLE=’t test and cohens d’
/CELLS=FIRST.