Date: Wed, 28 Mar 2012 06:27:58 -0700
Reply-To: Bruce Weaver <bruce.weaver@hotmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Bruce Weaver <bruce.weaver@hotmail.com>
Subject: Re: Summing a variable.
In-Reply-To: <1332939721601-5600405.post@n5.nabble.com>
Content-Type: text/plain; charset=us-ascii
I was thinking of CREATE with the CSUM function, but David's solution is a
lot neater. Note that it is the use of SUM that makes it work. I.e., the
following would not work, because LAG(GOALSUM) = SYSMIS on the first row.
COMPUTE GOALSUM=GOAL + LAG(GOALSUM).
Here's a more complete example of the difference.
data list list (",") / goal minutes.
begin data
1, 3
, 4
, 5
1, 6
1, 7
, 8
1, 9
1, 10
1, 11
, 12
, 13
, 14
, 15
, 16
1, 17
1, 18
, 19
1, 20
, 21
1, 22
end data.
COMPUTE GOALSUM1=SUM(GOAL,LAG(GOALSUM1)). /* David's method.
COMPUTE GOALSUM2= GOAL + LAG(GOALSUM2). /* Simple addition rather than
SUM().
COMPUTE LagGS1 = LAG(goalsum1).
COMPUTE LagGS2 = LAG(goalsum2).
FORMATS all(f5.0).
LIST.
OUTPUT:
goal minutes GOALSUM1 GOALSUM2 LagGS1 LagGS2
1 3 1 . . .
. 4 1 . 1 .
. 5 1 . 1 .
1 6 2 . 1 .
1 7 3 . 2 .
. 8 3 . 3 .
1 9 4 . 3 .
1 10 5 . 4 .
1 11 6 . 5 .
. 12 6 . 6 .
. 13 6 . 6 .
. 14 6 . 6 .
. 15 6 . 6 .
. 16 6 . 6 .
1 17 7 . 6 .
1 18 8 . 7 .
. 19 8 . 8 .
1 20 9 . 8 .
. 21 9 . 9 .
1 22 10 . 9 .
Number of cases read: 20 Number of cases listed: 20
David Marso wrote
>
> Once again, LAG is your friend.
> COMPUTE GOALSUM=SUM(GOAL,LAG(GOALSUM)).
>
>
> drfg2008 wrote
>>
>> SPSS 20 Windows
>>
>> I have the variable "goals", which measures the goals at each time (see
>> below: one goal at each time) and I just want the variable "goals" to be
>> added up (like in the variable "GoalSum").
>>
>> Goal GoalSum Minutes
>>
>> 1 1 3
>> . 1 4
>> . 1 5
>> 1 2 6
>> 1 3 7
>> . 3 8
>> 1 4 9
>> 1 5 10
>> 1 6 11
>> . 6 12
>> . 6 13
>> . 6 14
>> . 6 15
>> . 6 16
>> 1 7 17
>> 1 8 18
>> . 8 19
>> 1 9 20
>> . 9 21
>> 1 10 22
>>
>>
>> Thanks for help.
>>
>> Frank
>>
>
-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."
NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Summing-a-variable-tp5600280p5600471.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
This email is intended only for the use of the individual or entity to which it is addressed and may contain information that is privileged and confidential. If the reader of this email message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is prohibited. If you have received this email in error, please notify the sender and destroy/delete all copies of the transmittal. Thank you.
This email is intended only for the use of the individual or entity to which it is addressed and may contain information that is privileged and confidential. If the reader of this email message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is prohibited. If you have received this email in error, please notify the sender and destroy/delete all copies of the transmittal. Thank you.
=====================
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