LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2011)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 20 Jun 2011 10:36:20 +0100
Reply-To:     Garry Gelade <garry@business-analytic.co.uk>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Garry Gelade <garry@business-analytic.co.uk>
Subject:      Re: Running in total
Comments: To: DEBOER <ronnysentongo@HOTMAIL.COM>
In-Reply-To:  <1308490459708-4503507.post@n5.nabble.com>
Content-Type: text/plain; charset="us-ascii"

I'm not exactly sure what you want from looking at your example. However, first of all I'd number your cases by something like:

COMPUTE const = 1. COMPUTE casenum =$casenum. SORT CASES by orgnr year casenum. split file orgnr year. create splitcasenum=csum(const).

(casenum is only there to ensure you don't inadvertantly screw up the original case order)

Then calculate the maximum number of cases within each split (splitcasemax) using AGGREGATE wih /BREAK = orgnr year using MODE = addvariables and /splitcasemax = MAX(splitcasenum).

Then something like: DO IF (splitcasemax - splitcasenum) > 6. COMPUTE desire2 = 0. ELSE. COMPUTE desire2 = desire. END IF.

You will then have the last 6 values in each split in desire2, and you can calculate a running sum. split file orgnr year. create cumdesire=csum(desire2).

Hope this helps.

Garry Gelade

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of DEBOER Sent: 19 June 2011 14:34 To: SPSSX-L@LISTSERV.UGA.EDU Subject: Running in total

Hi all, I have a problem to solve. I want to calculate the running total, but for only the last 6 cases (in points) with respect to orgnr and year. I solved the cumulative variable as follow.

sort cases by orgnr year. split file orgnr year. create cumulative=csum(points). execute.

The question is how can I create the desire variable so that we only calculate the last six cases in the variable of points? Please see below at the desire variable <<thanks in advance.

orgnr points year cumulative desire variable(last 6) 1 1 2 004 1 1 1 2 004 2 1 -3 2 004 -1 1 -5 2 004 -6 1 5 2 004 -1 1 7 2 004 6 1 2 2 004 8 1 1 5 2 004 13 8 1 3 2 004 16 19 1 2 2 004 18 36 1 3 2 004 21 60 1 4 2 004 25 82 1 5 2 004 30 101 1 7 2 004 37 123 1 8 2 004 45 147 1 4 2 005 4 1 2 2 005 6 1 3 2 005 9 1 - 2 005 9 1 3 2 005 12 1 7 2 005 19 1 8 2 005 27 59 1 9 2 005 36 82 1 3 2 005 39 112 1 -4 2 005 35 142 1 -3 2 005 32 168 1 3 2 005 35 188 1 2 2 005 37 204 1 5 2 005 42 214 1 4 2 005 46 220 2 1 2 004 1 2 1 2 004 2 2 -3 2 004 -1 2 -5 2 004 -6 2 5 2 004 -1 2 5 2 004 4 2 2 2 004 6 -1 2 5 2 004 11 4 2 3 2 004 14 13 2 2 2 004 16 28 2 3 2 004 19 50 2 3 2 004 22 70 2 5 2 004 27 88 2 7 2 004 34 109 2 8 2 004 42 132 2 4 2 005 4 2 2 2 005 6 2 3 2 005 9 2 - 2 005 9 2 3 2 005 12 2 7 2 005 19 2 8 2 005 27 59 2 1 2 005 28 82 2 3 2 005 31 104 2 -4 2 005 27 126 2 -3 2 005 24 144 2 3 2 005 27 156 2 2 2 005 29 164 2 5 2 005 34 166 2 4 2 005 38 172

-- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Running-in-total-tp4503507p450 3507.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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


Back to: Top of message | Previous page | Main SPSSX-L page