My friends, I'm with a problem to put aggregate into a loop, I need execute the aggregate in differents situations, for example, I gonna do too much select's if, and in each one I need run a aggregate, but aggregate cannot run in a LOOP, exist another way to do this?
DEFINE Gini (!POSITIONAL !TOKENS(1)) SORT CASES BY !1 (A). VECTOR Tri = Tri1 TO Tri199. LOOP #I=1 TO 199. SELECT IF Tri(#I) =1. AGGREGATE OUTFILE = * /PRESORTED /BREAK = !1 /persons = N . WEIGHT BY persons. COMPUTE brk = 1. AGGREGATE OUTFILE = 'C:\Rede_estagiário2\Gini\RENDAagg.sav' /BREAK = brk /sumRENDA = SUM(!1). END LOOP. EXECUTE. !ENDDEFINE. |
You could do functionally what you say you want with looping constructs within the macro (i.e. !DO !varname=start !TO finish). Given your incomplete code snippet I suspect there is an easier way (e.g. your multiple aggregates look to me like they could be amenable to one aggregate with a sum - possibly very easily done with MATRIX over the entire 199 Tri variables).
Maybe if you step back a bit and describe what you are trying to do the group can give better advice for a workflow. |
Administrator
|
Yes!!! Rather than expect others to sort and 'fix' through an undocumented mess which doesn't work, describe exactly what you are trying to do. As Andy stated, there is the !DO !DOEND in Macro.
MATRIX is another possibility depending upon the data size etc. I would just roll the data out using VARSTOCASES and use a SINGLE aggregate, or is that too simple? OTOH: You really don't provide any clue as to why you are doing this! CONTEXT pal! CONTEXT!!!
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?" |
In reply to this post by Leonardo Baltazar
Are you trying to get a
gini coefficient for each of 199 variables!?!
Art Kendall Social Research ConsultantsOn 9/13/2013 8:43 AM, Leonardo Baltazar [via SPSSX Discussion] wrote: My friends, I'm with a problem to put aggregate into a loop, I need execute the aggregate in differents situations, for example, I gonna do too much select's if, and in each one I need run a aggregate, but aggregate cannot run in a LOOP, exist another way to do this?
Art Kendall
Social Research Consultants |
On 9/13/2013 8:43 AM, Leonardo Baltazar [via SPSSX Discussion] wrote:
>I'm with a problem to put aggregate into a loop, >I need execute the aggregate in differents >situations, for example, I gonna do too much >select's if, and in each one I need run a >aggregate, but aggregate cannot run in a LOOP, exist another way to do this? You want to run with 199 different BREAK variables. Much the easiest way to do this (do I surprise anyone, here?) is to use CASESTOVARS to get *one* variable in 199 variable groups. Like this (but not tested): VARSTOCASES /MAKE V FROM V1 TO V199 /INDEX = Var#(199) /KEEP = ID /NULL = KEEP. AGGREGATE OUTFILE = * /BREAK = INDEX V /persons = N . WEIGHT BY persons. AGGREGATE OUTFILE = 'C:\Rede_estagiário2\Gini\RENDAagg.sav' /BREAK = INDEX /sumRENDA = SUM(V). ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Leonardo Baltazar
Sorry - CORRECTION to the code I posted: use Var#
instead of INDEX, in code that follows VARSTOCASES. (And still not tested, so there may be other problems.) VARSTOCASES /MAKE V FROM V1 TO V199 /INDEX = Var#(199) /KEEP = ID /NULL = KEEP. AGGREGATE OUTFILE = * /BREAK = Var# V /persons = N . WEIGHT BY persons. AGGREGATE OUTFILE = 'C:\Rede_estagiário2\Gini\RENDAagg.sav' /BREAK = Var# /sumRENDA = SUM(V). ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Art Kendall
Kendall,
The 199 variables are quarter's where I need calculate the Gini coefficiente for each, and to do this I need use agreggate in each quarter, but I didn't get do this with loop command, because the command has no support to aggregate, and I'm looking for another way. |
Administrator
|
Why don't YOU read through your thread and heed the advice several have proposed?
VARSTOCASES blah blah blah... Or do you insist on following your own dead end path with LOOP and AGGREGATE?
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?" |
Free forum by Nabble | Edit this page |