Combining cases

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

Combining cases

Anu Kotay
I have a data file with stress and pain ratings completed multiple times during the day: stress1, stress2, stress3, stress4 (see example below) .  I would like to collapse the data into one line for each day.  Any ideas on how to do this (without copying and pasting the data =)?


Sample of data currently:

DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3    PAIN4
4.00    20.00    .            .            .      20.00      .                .            .
4.00    .            25.00     .            .        .        45.00            .            .
4.00    .                .    10.00        .        .           .            35.00         .
4.00    .                .        .        20.00    .           .                .         70.00
5.00    5.00           .        .           .    10.00        .                .            .
5.00    .            20.00     .           .        .        15.00            .            .
5.00    .                .    40.00        .        .             .            15.00        .


How I would like it look  :
DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3    PAIN4
4.00    20.00    25.00    10.00    20.00    20.00    45.00    35.00    70.00
5.00    5.00     20.00     40.00    9.00    10.00    15.00    15.00    15.00

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.
Reply | Threaded
Open this post in threaded view
|

Re: Combining cases

Marta Garcia-Granero
Hi Anu,

Try this syntax:

RECODE STR1 TO PAIN4  (SYSMIS=0)  .
AGGREGATE
 /OUTFILE=*
 /BREAK=DAY
 /STR1_sum = SUM(STR1)
 /STR2_sum = SUM(STR2)
 /STR3_sum = SUM(STR3)
 /STR4_sum = SUM(STR4)
 /PAIN1_sum = SUM(PAIN1)
 /PAIN2_sum = SUM(PAIN2)
 /PAIN3_sum = SUM(PAIN3)
 /PAIN4_sum = SUM(PAIN4).

AK> I have a data file with stress and pain ratings completed
AK> multiple times during the day: stress1, stress2, stress3, stress4
AK> (see example below) .  I would like to collapse the data into one
AK> line for each day.  Any ideas on how to do this (without copying
AK> and pasting the data =)?


AK> Sample of data currently:

AK> DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3 PAIN4
AK> 4.00    20.00    .            .            .      20.00
AK> .                .            .
AK> 4.00    .            25.00     .            .        .
AK> 45.00            .            .
AK> 4.00    .                .    10.00        .        .         .            35.00         .
AK> 4.00    .                .        .        20.00    .
AK> .                .         70.00
AK> 5.00    5.00           .        .           .    10.00
AK> .                .            .
AK> 5.00    .            20.00     .           .        .
AK> 15.00            .            .
AK> 5.00    .                .    40.00        .        .         .            15.00        .


AK> How I would like it look  :
AK> DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3 PAIN4
AK> 4.00    20.00    25.00    10.00    20.00    20.00    45.00    35.00    70.00
AK> 5.00    5.00     20.00     40.00    9.00    10.00    15.00    15.00    15.00


--
Best regards,
 Marta Garcia-Granero                mailto:[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Combining cases

Marta Garcia-Granero
Hi Anu

Please, provide a more complete sample dataset, because the code gave
the result you wanted with the data you provided:

PRESERVE.
SET ERRORS=NONE.
DATA LIST LIST/DAY STR1 STR2 STR3 STR4 PAIN1 PAIN2 PAIN3 PAIN4.
BEGIN DATA
4.00 20.00 .     .     .     20.00   .     .     .
4.00 .     25.00 .     .     .       45.00 .     .
4.00 .     .     10.00 .     .       .     35.00 .
4.00 .     .     .     20.00 .       .     .     70.00
5.00 5.00  .     .     .     10.00   .     .      .
5.00 .     20.00 .     .     .       15.00 .      .
5.00 .     .     40.00 .     .       .     15.00  .
5.00 .     .     .     9.00  .       .     .      15.00
END DATA.
RESTORE.
LIST.

RECODE STR1 TO PAIN4 (SYSMIS=0) .
AGGREGATE
/OUTFILE=*
/BREAK=DAY
/STR1 = SUM(STR1)
/STR2 = SUM(STR2)
/STR3 = SUM(STR3)
/STR4 = SUM(STR4)
/PAIN1 = SUM(PAIN1)
/PAIN2 = SUM(PAIN2)
/PAIN3 = SUM(PAIN3)
/PAIN4 = SUM(PAIN4).
LIST.

Con fecha sábado, 30 de junio de 2007, 22:39:14, escribió:

AK> Thank you for the suggestion, but I didn't quite get the
AK> effect that I am looking for.  I would like to get the raw scores
AK> displayed in one row for each day rather than a composite of the
AK> scores in a row (i.e. sum).

AK> How I would like it look  :
AK> DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3    PAIN4
AK> 4.00    20.00    25.00    10.00    20.00    20.00    45.00    35.00    70.00
AK> 5.00    5.00     20.00     40.00    9.00    10.00    15.00    15.00    15.00

AK> How it turned out with sum syntax:
AK> DAY   STR1_S   STR2_S  STR3_S STR4_S  PAIN1_S   PAIN2_S  PAIN3_S  PAIN4_S
AK> 4.00  475.00    458.00    328.00    249.00    398.00    304.00    432.00    468.00
AK> 5.00  539.00    481.00    264.00    213.00    333.00    383.00    377.00    256.00

--
Regards,
 Marta                            mailto:[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Combining cases

Simon Phillip Freidin
In reply to this post by Anu Kotay
casestovars/id=day.

On 01/07/2007, at 2:08 AM, Anu Kotay wrote:

> I have a data file with stress and pain ratings completed multiple
> times during the day: stress1, stress2, stress3, stress4 (see
> example below) .  I would like to collapse the data into one line
> for each day.  Any ideas on how to do this (without copying and
> pasting the data =)?
>
>
> Sample of data currently:
>
> DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3    PAIN4
> 4.00    20.00    .            .            .
> 20.00      .                .            .
> 4.00    .            25.00     .            .        .
> 45.00            .            .
> 4.00    .                .
> 10.00        .        .           .            35.00         .
> 4.00    .                .        .
> 20.00    .           .                .         70.00
> 5.00    5.00           .        .           .
> 10.00        .                .            .
> 5.00    .            20.00     .           .        .
> 15.00            .            .
> 5.00    .                .
> 40.00        .        .             .            15.00        .
>
>
> How I would like it look  :
> DAY   STR1    STR2    STR3   STR4    PAIN1    PAIN2     PAIN3    PAIN4
> 4.00    20.00    25.00    10.00    20.00    20.00    45.00
> 35.00    70.00
> 5.00    5.00     20.00     40.00    9.00    10.00    15.00
> 15.00    15.00
>
> ---------------------------------
> Need a vacation? Get great deals to amazing places on Yahoo! Travel.