1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
*(Q) I have ran a series of t tests on groups with unequal ns and would like to
 compute Cohen's d. I see that SPSS doesn't have option available. How do I
 compute the ds from the given SPSS output? Is there a macro available?

*(A) Posted by Marta to SPSSX-L list on 2002/06/05; improved on 2004/10/08.

* I have updated a code I posted to the list 2 years ago. It
* calculates Glass, Hedges & Cohen standardised effect sizes, with their
* standard errors. These values are then added to the dataset.
* Marta  2004/10/08 mailto:biostatistics@terra.es 

Cohen's d is simply=(mean1-mean2)/Sp.

Where Sp is the pooled standard deviation:

Sp=sqrt((n1-1)*var1+(n2-1)*var2)/(n1+n2-2)).

- var1=variance of sample 1 (Sd1^2)
- var2=variance of sample 2 (Sd2^2)

If the sample sizes in your study are small, then it's better to use an
unbiased estimator called Hedges' g:

hedges g=cohen&*(1-(3/(4*(n1+n2)-9)))

If variances are unequal, sometimes another standardized mean difference
is used, called

Glass' d=(mean1-mean2)/Sd2

(Sd2= standard deviation from control group).

You can get all the required information from the statistics table in
the output.

* Improved code (2004/10/08) *.

* Example dataset (replace by your own but keep variable names) *.
* Data for treatment group go first place, and control group 2nd.
DATA LIST LIST /test(A8) meantr sdtr(2F8.2) ntr(F8.0)
 meanco sdco(2F8.2) nco(F8.0).
BEGIN DATA
1 35   9 17 24    8 18
2 43  10 15 37    7 16
3 40 2.3 18 32 2.54 19
END DATA.
 
* Analysis *.
MATRIX.
GET test  /VAR=test.
GET mean1 /VAR=meantr.
GET sd1   /VAR=sdtr.
GET n1    /VAR=ntr.
GET mean2 /VAR=meanco.
GET sd2   /VAR=sdco.
GET n2    /VAR=nco.
PRINT {mean1,sd1,n1,mean2,sd2,n2}
 /FORMAT='F8.1'
 /TITLE='Original data'
 /RNAMES=test
 /CLABELS='Mean1','SD1','N1','Mean2','SD2','N2'.
COMPUTE n=n1+n2.
COMPUTE poolvar=((n1-1)&*(sd1&**2)+(n2-1)&*(sd2&**2))/(n-2) .
COMPUTE glass=(mean1-mean2)/sd2.
COMPUTE se_glass=SQRT((n/(n1&*n2))+((glass&**2)/(2&*(n2-1)))).
COMPUTE cohen=(mean1-mean2)/SQRT(poolvar).
COMPUTE se_cohen=SQRT((n/(n1&*n2))+((cohen&**2)/(2&*(n-2)))).
COMPUTE hedges=cohen&*(1-(3/(4&*(n)-9))).
COMPUTE se_hedge=SQRT((n/(n1&*n2))+((hedges&**2)/(2&*(n-3.94)))).
PRINT {glass,se_glass,cohen,se_cohen,hedges,se_hedge}
 /FORMAT='F8.3'
 /RNAMES=test
 /CLABELS='Glass','SE(D)','Cohen','SE(d)','Hedges','SE(g)'
 /TITLE='Standardized effects sizes'.
COMPUTE data={glass,se_glass,cohen,se_cohen,hedges,se_hedge}.
COMPUTE namevec={'glass','seglass','cohen','secohen','hedges','sehedges'}.
SAVE data /OUTFILE='c:\\temp\\data.sav' /NAMES=namevec.
END MATRIX.
 
MATCH FILES /FILE=*
 /FILE='c:\\temp\\data.sav'.
EXECUTE.