How to "groupsum" consecutive values within a variable according to conditions

16 messages
Open this post in threaded view
|

How to "groupsum" consecutive values within a variable according to conditions

 This post was updated on . Hello community I'm struggling with the following problem in SPSS Version 23. It's about the duration of days without any rainfall. The data is sorted according to DATE. I would like to sum up consecutive values in one binary variable called "Trockentag" [0,1] (drydays in english) from top to down - "grouped" - meaning, that values should be consecutively added and puted as a value in a new variable, until a next following value of "Trockentag" is 0 (a day when its raining again). The adding of values should start again, when a value is 1 and add consecutively, till a next value is 0 again. And so on. The result should be a new variable called "duration of drydays" in a new dataset which shows them grouped summed values per values in "YR" [2015, 2014, 2013, ..., 1980] and "Station" [503, 502, 402, 401, 301, etc]. See attached graphic. Thank you so much in an advance! Greetings Jonas
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 Administrator Two approaches come to mind: 1. SPLIT FILE followed by CREATE using CSUM. 2. Use LAG function and COMPUTE with IF statement. Note file should be SORTED Ascending by Year and Station for first solution. --- Jonas Steiner wrote Hello community I'm struggling with the following problem in SPSS Version 23. I would like to sum up consecutive values in one binary variable called "Trockentag" [0,1] from top to down - "grouped" - meaning, that values should be consecutively added and puted as a value in a new variable, until a next following value of "Trockentag" is 0. The adding of values should start again, when a value is 1 and add consecutively, till a next value is 0 again. And so on. The result should be a new variable in a new dataset which shows them grouped summed values (say 1,1,3,3,1,6,5,4,1 and so on) per values in "YR" [2015, 2014, 2013, ..., 1980] and "Station" [503, 502, 402, 401, 301, etc]. I hope you can relate to the definition of my problem and Thank you so much in an advance! Greetings Jonas 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?"
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

In reply to this post by Jonas Steiner
will this suit?
var is binary

comp w= w+var.
if not var w= 0.
leave w.
exec.

20.10.2016 10:58, Jonas Steiner пишет:
```Hello community

I'm struggling with the following problem in SPSS Version 23.

I would like to sum up consecutive values in one binary variable called
"Trockentag" [0,1] from top to down - "grouped" - meaning, that values
should be consecutively added and puted as a value in a new variable, until
a next following value of "Trockentag" is 0. The adding of values should
start again, when a value is 1 and add consecutively, till a next value is 0
again. And so on.

The result should be a new variable in a new dataset which shows them
grouped summed values (say 1,1,3,3,1,6,5,4,1 and so on) per values in "YR"
[2015, 2014, 2013, ..., 1980] and "Station" [503, 502, 402, 401, 301, etc].

<http://spssx-discussion.1045642.n5.nabble.com/file/n5733327/Problem_jonas.png>

I hope you can relate to the definition of my problem and Thank you so much

Greetings
Jonas

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-groupsum-consecutive-values-within-a-variable-according-to-conditions-tp5733327.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

```

 Это сообщение проверено на вирусы антивирусом Avast. www.avast.com

===================== 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
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 Administrator Nice one! Except you need IF NOT(var) ... And probably deal with the YR Station transitions? Kirill Orlov wrote will this suit? var is binary comp w= w+var. if not var w= 0. leave w. exec. 20.10.2016 10:58, Jonas Steiner пишет: > Hello community > > I'm struggling with the following problem in SPSS Version 23. > > I would like to sum up consecutive values in one binary variable called > "Trockentag" [0,1] from top to down - "grouped" - meaning, that values > should be consecutively added and puted as a value in a new variable, until > a next following value of "Trockentag" is 0. The adding of values should > start again, when a value is 1 and add consecutively, till a next value is 0 > again. And so on. > > The result should be a new variable in a new dataset which shows them > grouped summed values (say 1,1,3,3,1,6,5,4,1 and so on) per values in "YR" > [2015, 2014, 2013, ..., 1980] and "Station" [503, 502, 402, 401, 301, etc]. > > > > > I hope you can relate to the definition of my problem and Thank you so much > in an advance! > > > Greetings > Jonas > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-groupsum-consecutive-values-within-a-variable-according-to-conditions-tp5733327.html> Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > 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 > --- Это сообщение проверено на вирусы антивирусом Avast. https://www.avast.com/antivirus===================== 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 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?"
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 I managed to do the following: DO IF \$casenum=1.     COMPUTE Tr_addiert=Trockentag.         ELSE IF Trockentag=0.             COMPUTE Tr_addiert=0.         ELSE IF LAG(Trockentag) GT 0.             COMPUTE Tr_addiert=1+LAG(Tr_addiert).         ELSE.             COMPUTE                 Tr_addiert=Trockentag + LAG(Tr_addiert). END IF. EXECUTE. ... what counts up the days with "Trockentage" (dry days in english) in a consecutive order. But that's not exactly what I'm going for. I want to know the time spans in days (summed up consecutive values=1, intervened by values=0) in "Trockentage") per "Station" and "YR".
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 This problem, which seems like it ought to have been pretty simple, has been a small saga. Jonas, I think it would have been and would now be helpful to go back to your original post and show the desired computational result. You describe it but to me it's not very understandable. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jonas Steiner Sent: Friday, October 21, 2016 9:13 AM To: [hidden email] Subject: Re: How to "groupsum" consecutive values within a variable according to conditions I managed to do the following: DO IF \$casenum=1.     COMPUTE Tr_addiert=Trockentag.         ELSE IF Trockentag=0.             COMPUTE Tr_addiert=0.         ELSE IF LAG(Trockentag) GT 0.             COMPUTE Tr_addiert=1+LAG(Tr_addiert).         ELSE.             COMPUTE                 Tr_addiert=Trockentag + LAG(Tr_addiert). END IF. EXECUTE. ... what counts up the days with "Trockentage" (dry days in english) in a consecutive order. But that's not exactly what I'm going for. I want to know the time spans in days (summed up consecutive values=1, intervened by values=0) in "Trockentage") per "Station" and "YR". -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-groupsum-consecutive-values-within-a-variable-according-to-conditions-tp5733327p5733350.htmlSent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 ===================== 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
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 In reply to this post by Maguin, Eugene I updated my original post and illustrated it with some new pictures. I think the relation to the content of my data seems helpful. It should be clear now.
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

 It is not quite right an action to update greatly your initial question on the site - because we are mailing list, not a wiki site. You could post the update as an answer in the threadof your question (better) or post an entirely new question. 24.10.2016 15:14, Jonas Steiner пишет: ```I updated my original post and illustrated it with some new pictures. I think the relation to the content of my data seems helpful. It should be clear now. ``` ===================== 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
Open this post in threaded view
|

Re: How to "groupsum" consecutive values within a variable according to conditions

Open this post in threaded view
|