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
* How can I weight data based on 2 or more variables.
* Solution posted to SPSSX-L list by Joao Duarte ( jd@proade.com ) on 2004/10/19 .

***************   begin macro ***************.

DEFINE !pondx (!POSITIONAL !ENCLOSE('[',']'))
WEIGHT OFF.
!LET !nnn=1

!DO !var !IN (!1)
!LET !nnn2=!nnn
!IF (!nnn=1) !then !LET !varp=!var !IFEND

!IF (!nnn=2) !THEN
!LET !valp=!var
SORT CASES BY !varp.
COMPUTE pondt = pond.
IF !varp=LAG(!varp) pondt = pondt + LAG(pondt).
SORT CASES BY !varp (A) pondt (D).
IF !varp=LAG(!varp) pondt=LAG(pondt).
COMPUTE pond=pond * (!valp / pondt).
!IFEND

!IF (!nnn2=1) !THEN !LET !nnn=2 !IFEND
!IF (!nnn2=2) !THEN !LET !nnn=1 !IFEND

!DOEND
!ENDDEFINE.

****************  end macro ***************.


**************  demo **************.

* Create a sample data file.

DATA LIST LIST /quest var1 var2.
BEGIN DATA
1        1        1
2        1        1
8        1        1
9        1        1
3        2        2
4        2        2
5        1        2
5        2        3
6        2        3
7        2        3
END DATA.

COMPUTE pond=1.

IF var1=1 univ1=70.
IF var1=2 univ1=130.

IF var2=1 univ2=40.
IF var2=2 univ2=140.
IF var2=3 univ2=20.

****  univ1 , univ2 are the universe values.

!pondx [var1 univ1 var2 univ2].
!pondx [var1 univ1 var2 univ2].
!pondx [var1 univ1 var2 univ2].
* .....
* .....
!pondx [var1 univ1 var2 univ2].

*you can repeat the macro until you get an accurate result; you can use more than 2 vars .
*you can keep only pond and delete univ1 univ2 and pondt.

WEIGHT OFF.
FREQ VAR= var1 var2.

WEIGHT BY pond.
FREQ VAR= var1 var2.
*******************   end of demo ***************.