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
*(Q)	My sample has 40% males and 60% females. 
	My population has 49% males and 51% female.
	I would like to automatically weight my sample cases in order to
	approximate my population.

*(A)  Posted to SPSSX-L list by Raynald Levesque on 2002/09/13.
	Note that dispersion and confidence interval statistics produced by 
	SPSS are not valid for a sample weighted like this.



DATA LIST FREE /sex.
BEGIN DATA
1 2 1 2 2
END DATA.
LIST.
SORT CASES BY sex.
SAVE OUTFILE='c:\\temp\\original data.sav'.


AGGREGATE OUTFILE=*
	/PRESORTED
	/BREAK=sex
	/wsex=N.
FLIP.

SELECT IF RTRIM(case_lbl)="WSEX".
COMPUTE popmale=49.
COMPUTE popfem=51.

COMPUTE sampmale=100*var001/(var001 + var002).
COMPUTE sampfem =100*var002/(var001 + var002).

COMPUTE wgtmale=popmale/sampmale.
COMPUTE wgtfem =popfem /sampfem.

FLIP VARIABLES=wgtmale wgtfem  .
COMPUTE sex=2.
IF case_lbl="WGTMALE" sex=1.

MATCH FILES TABLE=*
	/FILE='c:\\temp\\original data.sav'
	/BY=sex
	/DROP=case_lbl.
FORMATS wsex(F5.4).
WEIGHT BY wsex.