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
*(Q) How can I calculate 95%CI for the median with SPSS?

* (A) Answer by Marta Garcia-Granero 2002/03/11.
*There are two ways.

* Dummy data.

INPUT PROGRAM.
- VECTOR V(1).
- LOOP #I = 1 TO 100.
-   COMPUTE V(1) = uniform(10).
-  END CASE.
- END LOOP.
- END FILE.
END INPUT PROGRAM.
execute.

* Solution #1 (only with SPSS 11).

TEMPORARY.
COMPUTE constant=1.
RATIO STATISTICS v1 WITH constant
 /PRINT =  CIN(95) MEDIAN .

* Solution #2 (any version of SPSS).

DEFINE CIMED95(!POSITIONAL !TOKENS(1)).
* Save original file for later.
SAVE OUTFILE='\\cimed__.sav'.
SORT CASES BY !1 (A).
COMPUTE ID=$CASENUM.
RANK  VARIABLES=!1 (A) /N INTO n /PRINT=NO .
* Lower bound position.
COMPUTE l=TRUNC(((n+1)/2-(n<=284)*(0.9789*sqrt(n)))-(n>284)*(0.98*sqrt(n))).
* Exception handling (two cases).
IF n=17 l=5.
IF n=67 l=26.
* Upper bound position.
COMPUTE u=n+1-l.
* Getting lower and upper bound values.
SELECT IF((id=l) or (id=u)).
EXECUTE .
* Report.
STRING limits (A12).
IF ($CASENUM=1) limits = '95% Lower:' .
IF ($CASENUM=2) limits = '95% Upper:' .
REPORT FORMAT=LIST AUTOMATIC ALIGN(CENTER)
 /VARIABLES=limits !1
 /TITLE 'Approximate 95% CI for median'.
* Restore original file.
GET FILE='cimed__.sav'.
!ENDDEFINE.

* Macro call.
cimed95 v1.