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
*(Q) I have a data set that includes HS graduates who have enrolled in college
	(InSchool=1) and those who have not (InSchool=0). The data set also includes
	Gender and TypeSchl (indicating 4-Year, 2-Year, or LT-2Yr programs).  I
	would like to do a bar graph that shows the breakdown for TypeSchl within
	Gender, conditioned on InSchool=1. Thus, the first panel would show the % in
	each TypeSchl category for females enrolled in college, and the next panel
	would do the same for males enrolled in college.  Those not enrolled are
	excluded from the analysis.  In each panel, the percentages need to sum to
	100 percent.

* (A) posted by rlevesque@videotron.ca to SPSSX-L list on 2002/01/29.

INPUT PROGRAM.
LOOP id=1 TO 200.
COMPUTE inschool=UNIFORM(1)<.5.
COMPUTE gender=UNIFORM(1)<.5.
COMPUTE typeschl=TRUNC(1+UNIFORM(3)).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
LIST /CASES=FROM 1 TO 10.

SELECT IF inschool=1.

* Calculate number in each category.
AGGREGATE
  /OUTFILE=*
  /BREAK= gender typeschl
  /id_1 = N(id).

* Weight file to have equivalent of the original file.
WEIGHT BY id_1.

* Calculate the total males and females.
AGGREGATE
  /OUTFILE='c:\\temp\\temp.sav'
  /BREAK= gender
  /id_g = N(id_1).

* Add the total number of males & females to the file.
MATCH FILES /FILE=*
 /TABLE='C:\\Temp\\temp.sav'
 /BY gender.

* Compute then graph the percents (each sex add up to 100%).
COMPUTE pc=id_1/id_g.
VARIABLE LABEL pc 'Percent'.

GRAPH
  /BAR(GROUPED)=MEAN(pc) BY gender BY typeschl
  /MISSING=REPORT.