Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to calculate sums across duplicate rows in SPSS 11.5

213 views
Skip to first unread message

sheree

unread,
Jan 21, 2004, 10:44:33 AM1/21/04
to
I have a dataset in SPSS that looks like this:

StudyID Time Temp DegMins
01-35-001 1 36.9 13.5
01-35-001 2 36.2 3
01-35-001 3 34.9 -16.5
01-35-001 4 35.6 -6
01-35-001 5 35.5 -7.5
01-35-002 1 36.5 7.5
01-35-002 2 36.5 7.5
01-35-002 3 36.4 6
01-35-002 4 35.8 -3
01-35-003 1 36.9 13.5
01-35-003 2 36.8 12
01-35-003 3 36.7 10.5

Where the StudyID will repeat across several rows -- this is the same
person, with measurements at different times. What I want to do, is
create a new variable that sums the DegMins values **for each
StudyID**, but only when the DegMins are a negative number. For
example, for StudyID=01-35-001, Sum=(-16.5)+(-6)+(-7.5)=-30. For
StudyID=01-35-002, Sum=(-3)=-3. For StudyID=01-35-003, Sum=0 (since
there are no negative values for this person). Notice also that the
number of rows that exist for each StudyID will vary.

Ideally, I would like to know the SPSS syntax for how to do this, but
any way to get this answer & store it would be great.

Thank you very much for your suggestions!
-sheree

Moshe Braner

unread,
Jan 21, 2004, 11:24:22 AM1/21/04
to
compute negonly = max(degmins,0).
aggregate outfile=* /break=studyid /sumneg=sum(negonly).

Rich Ulrich

unread,
Jan 21, 2004, 11:46:19 AM1/21/04
to

You don't have to save the Recode, so you just don't
even need to set up a temporary variable to use. Just -

recode DegMins(0 thru hi=0).

- and Aggregate, by StudyID, saving the new file
which computes a SUM as its variable.
That gives you one record for each StudyID, with
the sum of whatever was negative.

Right?

--
Rich Ulrich, wpi...@pitt.edu
http://www.pitt.edu/~wpilib/index.html
"Taxes are the price we pay for civilization."

0 new messages