Posted by
David Marso on
Jan 20, 2012; 7:12pm
URL: http://spssx-discussion.165.s1.nabble.com/extracting-Best-quota-fit-tp5133960p5161432.html
GauravSrivastava wrote
I have multiple variables over which I have to select my total sample. In other word, you can say best quota fit from the total sample. for example: I have total sample of 1100 out which I have to select 1000 sample based on 3 different variable Age, Gender, Region.
Gender: 500:500
Age: 250:300:300:150
Region: 334:333:333
Can anyone help me on this?Thanks in advance
Gaurav
Just tossing this into embers of the fire.
YMMV. Probably best to WEIGHT rather than delete cases.
This code downweights the 1100 to 1000 (WHY??)
(delete the 1000/N_TOT) in the code if you opt to not down weight.
*Simulation of your data*.
NEW FILE.
INPUT PROGRAM.
LOOP CASE=1 TO 1100.
COMPUTE G=TRUNC(UNIFORM(2)+1).
COMPUTE A=TRUNC(UNIFORM(4)+1).
COMPUTE R=TRUNC(UNIFORM(3)+1).
LEAVE G A R CASE.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
**** GET YOUR RAW DATA AND GO for it.
*I have used G A R for your variables gender age race so substitute as needed *.
SORT CASES BY G A R.
SAVE OUTFILE "SortedRawData.sav".
AGGREGATE OUTFILE */ BREAK G A R / N_Obs=N.
COMPUTE N_TOT=SUM(LAG(N_TOT),N_OBS).
SORT CASES BY N_TOT(D).
IF $CASENUM > 1 N_TOT=LAG(N_TOT).
SORT CASES BY G A R.
SAVE OUTFILE "Obs_table.sav" .
* Create a table of desired proportions/counts *.
NEW FILE.
INPUT PROGRAM.
LOOP G=1 TO 2.
LOOP A= 1 TO 4.
LOOP R= 1 TO 3.
COMPUTE CELL=1.
LEAVE G A R.
END CASE.
END LOOP.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
RECODE G (1=.5)(2=.5) INTO P_G
/ A (1=.25)(2,3=.3)(4=.15) INTO P_A
/ R (1=.34)(2,3=.33) INTO P_R .
COMPUTE P_C_DES = P_G * P_A * P_R .
COMPUTE F_C_DES=P_C_DES*1000.
SAVE OUTFILE "BaseTableProb.sav".
MATCH FILES / FILE "Obs_table.sav" / FILE "BaseTableProb.sav" / BY G A R.
COMPUTE P_OBS=N_OBS /N_TOT.
COMPUTE C_WEIGHT=(P_C_DES /P_OBS) * (1000/N_TOT).
MATCH FILES / FILE "SortedRawData.sav" /TABLE * / BY G A R.
WEIGHT BY C_WEIGHT.
FREQ G A R.
CROSS / TABLE G BY A BY R /CELLS= ALL.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"