Capture 20/40/80%

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Capture 20/40/80%

Peter Spangler
David,  
To make the percentage splits to capture the cases that compose 20/40/80% of the cumulative transaction value I made the following adjustments


SORT CASES BY Transaction_Value.
CREATE Cum_Value_of_Transactions=CSUM(Transaction_Value).
AGGREGATE OUTFILE=*  MODE=ADDVARIABLES
                /Total_Value_of_Transactions=SUM(Transaction_Value).

DO IF $CASENUM EQ 1.
+  DO REPEAT PCT= 20 40 80/V=#pct20 #pct40 #pct80.
+    COMPUTE V=PCT/100*Total_Value_of_Transactions.
+  END REPEAT.
END IF.

NUMERIC #Bin.
VECTOR #P=#Pct20 TO #Pct80.
DO IF #Bin LT 4.
+  IF  #P(#Bin+1) LT Cum_Value_of_Transactions #Bin=#Bin+1.
END IF.
COMPUTE Bin=#Bin+1.

FREQ Bin.
Reply | Threaded
Open this post in threaded view
|

Re: Capture 20/40/80%

David Marso
Administrator
DO IF #Bin LT 4.
??
Need to modify that appropriately as well (3).
Code will still yield same result but you will get error on vector subscript!

Peter Spangler wrote
David,
To make the percentage splits to capture the cases that compose 20/40/80%
of the cumulative transaction value I made the following adjustments


SORT CASES BY Transaction_Value.
CREATE Cum_Value_of_Transactions=CSUM(Transaction_Value).
AGGREGATE OUTFILE=*  MODE=ADDVARIABLES
                /Total_Value_of_Transactions=SUM(Transaction_Value).

DO IF $CASENUM EQ 1.
+  DO REPEAT PCT= 20 40 80/V=#pct20 #pct40 #pct80.
+    COMPUTE V=PCT/100*Total_Value_of_Transactions.
+  END REPEAT.
END IF.

NUMERIC #Bin.
VECTOR #P=#Pct20 TO #Pct80.
DO IF #Bin LT 4.
+  IF  #P(#Bin+1) LT Cum_Value_of_Transactions #Bin=#Bin+1.
END IF.
COMPUTE Bin=#Bin+1.

FREQ Bin.
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?"