CSUM conditioned

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CSUM conditioned

Patrizio-5
Dear all,
I have the following data

condition progressive_time diff_time
PRE           0              0
PRE           10             10
PRE           20             10
....
POST          50             10
POST          60             10
....
PRE           100            10
PRE           110            10
...
POST          150            10
POST          160            10

etc

I need a new variable CUM_time cumulating the progressive_time of each
condition separately (PRE, POST, PRE, POST etc.).

I tried the CREATE CUM syntax but it is not possible to nest it within DO IF.

Thank you for your help

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

Re: CSUM conditioned

Richard Ristow
At 02:08 PM 4/19/2009, Patrizio wrote:

I have the following data

condition progressive_time diff_time
PRE           0              0
PRE           10             10
PRE           20             10
....
POST          50             10
POST          60             10
....
PRE           100            10
PRE           110            10
...
POST          150            10
POST          160            10

I need a new variable CUM_time cumulating the progressive_time of each condition separately (PRE, POST, PRE, POST etc.).

I tried the CREATE CUM syntax but it is not possible to nest it within DO IF.

No. CREATE is a procedure, and DO IF can only control transformation commands.

To have CSUM work within groups of cases rather than the whole file, use SPLIT FILE to split the cases into groups. For this, you need a subject ID as well as PRE/POST, so every group of cases to be summed has a unique identifier (subject, and condition).

|-----------------------------|---------------------------|
|Output Created               |26-APR-2009 23:48:06       |
|-----------------------------|---------------------------|
Subject condition progressive_time diff_time

    1   PRE                0             0
    1   PRE               10            10
    1   PRE               20            10
    1   POST              50            10
    1   POST              60            10
    2   PRE              100            10
    2   PRE              110            10
    2   POST             150            10
    2   POST             160            10

Number of cases read:  9    Number of cases listed:  9

 
SPLIT FILE BY Subject condition.

CREATE CUM_time = CSUM(progressive_time).

Create
|-----------------------------|---------------------------|
|Output Created               |26-APR-2009 23:48:06       |
|-----------------------------|---------------------------|
Created Series
|-------|---------|-|--------|----------------|-----|---------------|
|Subject|condition| |Series  |Case Number of  |N of |Creating       |
|       |         | |Name    |Non-Missing     |Valid|Function       |
|       |         | |        |Values          |Cases|               |
|       |         | |        |-----------|----|     |               |
|       |         | |        |First      |Last|     |               |
|-------|---------|-|--------|-----------|----|-----|---------------|
|1      |POST     |1|CUM_time|4          |5   |2    |CSUM(progressiv|
|       |         | |        |           |    |     |e_time)        |
|       |---------|-|--------|-----------|----|-----|---------------|
|       |PRE      |1|CUM_time|1          |3   |3    |CSUM(progressiv|
|       |         | |        |           |    |     |e_time)        |
|-------|---------|-|--------|-----------|----|-----|---------------|
|2      |POST     |1|CUM_time|8          |9   |2    |CSUM(progressiv|
|       |         | |        |           |    |     |e_time)        |
|       |---------|-|--------|-----------|----|-----|---------------|
|       |PRE      |1|CUM_time|6          |7   |2    |CSUM(progressiv|
|       |         | |        |           |    |     |e_time)        |
|-------|---------|-|--------|-----------|----|-----|---------------|

 
SPLIT FILE OFF.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |26-APR-2009 23:48:06       |
|-----------------------------|---------------------------|
Subject condition progressive_time diff_time CUM_time

    1   PRE                0             0         0
    1   PRE               10            10        10
    1   PRE               20            10        30
    1   POST              50            10        50
    1   POST              60            10       110
    2   PRE              100            10       100
    2   PRE              110            10       210
    2   POST             150            10       150
    2   POST             160            10       310

Number of cases read:  9    Number of cases listed:  9
=============================
APPENDIX: Test data, and code
=============================
DATA LIST LIST/
    Subject condition progressive_time diff_time
    (F2,    A6,          F4,            F4).
BEGIN DATA   
    1       PRE           0              0
    1       PRE           10             10
    1       PRE           20             10
    1       POST          50             10
    1       POST          60             10
    2       PRE           100            10
    2       PRE           110            10
    2       POST          150            10
    2       POST          160            10
END DATA.

LIST.

SPLIT FILE BY Subject condition.

CREATE CUM_time = CSUM(progressive_time).

SPLIT FILE OFF.

LIST.

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

Re: CSUM conditioned

Richard Ristow
At 09:36 AM 4/27/2009, Patrizio Tressoldi wrote,off-list:

To have CSUM work within groups of cases rather than the whole file, use SPLIT FILE to split the cases into groups. For this, you need a subject ID as well as PRE/POST, so every group of cases to be summed has a unique identifier (subject, and condition).

Very kind for this suggestions.
Do you know an automatic procedure to generate Subject's or Event's progressive number?

The following creates the "Subject" variable I used in the previous example, by incrementing a counter every time 'POST' changes to 'PRE'. "(Subject" is now at the end of the records instead of at the beginning.)

|-----------------------------|---------------------------|
|Output Created               |29-APR-2009 21:17:33       |
|-----------------------------|---------------------------|
condition progressive_time diff_time

PRE                0             0
PRE               10            10
PRE               20            10
POST              50            10
POST              60            10
PRE              100            10
PRE              110            10
POST             150            10
POST             160            10

Number of cases read:  9    Number of cases listed:  9

 
NUMERIC    Subject (F2).

DO IF   $CASENUM EQ 1.
.  COMPUTE Subject = 1.
ELSE IF     CONDITION  EQ 'PRE'
      & LAG(CONDITION) EQ 'POST'.
.  COMPUTE Subject = LAG(Subject) + 1.
ELSE.
.  COMPUTE Subject = LAG(Subject).
END IF.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |29-APR-2009 21:17:33       |
|-----------------------------|---------------------------|
condition progressive_time diff_time Subject

PRE                0             0       1
PRE               10            10       1
PRE               20            10       1
POST              50            10       1
POST              60            10       1
PRE              100            10       2
PRE              110            10       2
POST             150            10       2
POST             160            10       2

Number of cases read:  9    Number of cases listed:  9

=============================
APPENDIX: Test data, and code
=============================
DATA LIST LIST/
    condition progressive_time diff_time
     (A6,          F4,            F4).
BEGIN DATA   
       PRE           0              0
       PRE           10             10
       PRE           20             10
       POST          50             10
       POST          60             10
       PRE           100            10
       PRE           110            10
       POST          150            10
       POST          160            10
END DATA.

LIST.

NUMERIC    Subject (F2).

DO IF   $CASENUM EQ 1.
.  COMPUTE Subject = 1.
ELSE IF     CONDITION  EQ 'PRE'
      & LAG(CONDITION) EQ 'POST'.
.  COMPUTE Subject = LAG(Subject) + 1.
ELSE.
.  COMPUTE Subject = LAG(Subject).
END IF.

LIST.

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