Appending cases

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

Appending cases

Greg Chulsky
I currently have a bunch of SPSS files where the cases are arranged in
the following manner:

MEAN    M1    M2    M3    ...    M43
STDERR    S1    S2    S3    ...    S43
MEAN    M1    M2    M3    ...    M43
STDERR    S1    S2    S3    ...    S43
...,

where M1, S1, M2, S2, etc. are numbers.

As you can see, every two "cases" are actually one case.  For some
purposes, this format suits me fine.  For others, it does not.  I've
been trying to write a simple piece of code that would go through,
append all the even cases to the ends of the odd cases preceding them,
and then remove the resulting empty even cases.  This turned out to be
harder than I had expected.  Does anybody know how this could be done?

-Greg

=====================
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: Appending cases

Maguin, Eugene
Greg,

I think you will find the casestovars command to be what you need. You will
need to create a case number variable for the command to work. I'd think
first of the following scheme.

Compute id=$casenum.
If (mod(id,2) eq 0) id=lag(id).


This should have the effect of creating pairs of records with ids=1, 3, 5,
7, ... . I think that will work fine with casestovars. Pay attention to how
the variables are named coming out of the command because if you want
resulting variables to be named something like M1 to M43; SE1 to SE43, I'm
almost certain you'll need to do a rename command following the casestovars.
This much will get you started. There are others on the list who are really
skillful with casestovars (and varstocases). Perhaps they can jump in give
you better advice than I have.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Greg Chulsky
Sent: Tuesday, September 09, 2008 2:22 PM
To: [hidden email]
Subject: Appending cases


I currently have a bunch of SPSS files where the cases are arranged in
the following manner:

MEAN    M1    M2    M3    ...    M43
STDERR    S1    S2    S3    ...    S43
MEAN    M1    M2    M3    ...    M43
STDERR    S1    S2    S3    ...    S43
...,

where M1, S1, M2, S2, etc. are numbers.

As you can see, every two "cases" are actually one case.  For some
purposes, this format suits me fine.  For others, it does not.  I've
been trying to write a simple piece of code that would go through,
append all the even cases to the ends of the odd cases preceding them,
and then remove the resulting empty even cases.  This turned out to be
harder than I had expected.  Does anybody know how this could be done?

-Greg

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

Re: Appending cases

Greg Chulsky
Gene,

Thank you!  I looked up CASESTOVARS and what you suggested was exactly
what I needed to do here.  My variable names were STATS (which took on
the value MEAN or STDERR) and then B120, 140, B160, B180 and so on to
B960, which took on numerical values.  I wrote the code as follows:

COMPUTE ID=$CASENUM.
IF (MOD(ID,2) EQ 0) ID=LAG(ID).
CASESTOVARS
   /ID=ID
   /INDEX=STATS
   /GROUPBY=VARIABLE.
DELETE VARIABLES ID.

My new variables were named B120.MEAN, B120.STDERR, B140.MEAN,
B140.STDERR,...B960.MEAN, B960.STDERR.

-Greg

Gene Maguin wrote:

> Greg,
>
> I think you will find the casestovars command to be what you need. You will
> need to create a case number variable for the command to work. I'd think
> first of the following scheme.
>
> Compute id=$casenum.
> If (mod(id,2) eq 0) id=lag(id).
>
>
> This should have the effect of creating pairs of records with ids=1, 3, 5,
> 7, ... . I think that will work fine with casestovars. Pay attention to how
> the variables are named coming out of the command because if you want
> resulting variables to be named something like M1 to M43; SE1 to SE43, I'm
> almost certain you'll need to do a rename command following the casestovars.
> This much will get you started. There are others on the list who are really
> skillful with casestovars (and varstocases). Perhaps they can jump in give
> you better advice than I have.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Greg Chulsky
> Sent: Tuesday, September 09, 2008 2:22 PM
> To: [hidden email]
> Subject: Appending cases
>
>
> I currently have a bunch of SPSS files where the cases are arranged in
> the following manner:
>
> MEAN    M1    M2    M3    ...    M43
> STDERR    S1    S2    S3    ...    S43
> MEAN    M1    M2    M3    ...    M43
> STDERR    S1    S2    S3    ...    S43
> ..,
>
> where M1, S1, M2, S2, etc. are numbers.
>
> As you can see, every two "cases" are actually one case.  For some
> purposes, this format suits me fine.  For others, it does not.  I've
> been trying to write a simple piece of code that would go through,
> append all the even cases to the ends of the odd cases preceding them,
> and then remove the resulting empty even cases.  This turned out to be
> harder than I had expected.  Does anybody know how this could be done?
>
> -Greg
>
> =====================
> 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
>
> =====================
> 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