* 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 ***************.