Create new case as mean of two cases

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Create new case as mean of two cases

Postby ana.tourino » Sat Feb 22, 2014 12:35 pm

Hi all,

I need to create (in the same dataset) a new case wich is the mean of other two cases (for each variable) using syntax.
For example,

I have this:
ID V1 V2
1 2.5 5
2 3.5 6.5

I want to obtain:
ID V1 V2
1 2.5 5
2 4.5 6.5
3 3.5 5.75

Suggestions?

Thanks a lot!
statman
Administrator
Posts: 2735
Joined: Tue Jun 12, 2007 12:08 pm
Location: Florida, USA

Re: Create new case as mean of two cases

Postby statman » Sun Feb 23, 2014 1:41 pm

Truly unclear why one would want to do this but .... the only way I can think of is via a micro or the OMS facility

Please see the Note below
See the note below

NOTE: Please read the Posting Guidelines and always tell us your OS, the SPSS version and information about your study and data!

Statman
Statistical Services
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Create new case as mean of two cases

Postby GerineL » Mon Feb 24, 2014 9:24 am

ana.tourino wrote:Hi all,

I need to create (in the same dataset) a new case wich is the mean of other two cases (for each variable) using syntax.
For example,

I have this:
ID V1 V2
1 2.5 5
2 3.5 6.5

I want to obtain:
ID V1 V2
1 2.5 5
2 4.5 6.5
3 3.5 5.75

Suggestions?

Thanks a lot!
Is it always 2 cases? or is it lots of cases (i.e., is there also case 3 and 4, that have to become case 5)?
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create new case as mean of two cases

Postby ana.tourino » Mon Feb 24, 2014 10:40 am

Ok,
Its seems I´ve been very unclear. Sorry, I tried to be brief but didn´t work. Thanks anyway!.
Here it is the extended version of the problem:

-I have along database about parties in Europe which merge diferents surveys. Each case is a combination of party*survey*year. As a result, I have several rows for each party. I have information about this cases in diferent scales or variables (50 aprox) with a lot of missings (because the scale make reference to one survey but not to otthers).

-Now I need to link parties not only by the identificators but also creating new cases which "merge" these parties (sometimes 2 parties, sometimes 3) in two different ways:
1. Substituting the real value for the mean of the two parties when They appear in the same survey (challenge: "create a new case as a mean of two cases")
2. Creating new cases with a common name to link it sequentially (challenge: "copy cases", not asked here but suggestions are welcome to make it with syntax).

Yes, It sounds rare but I have these instructions. And, as you note, "merge" means duplicate cases maintaining the originals and the new ones in the same database.

Example First challenge:
I have this:
party survey year V1 V2 V3
SF 1 1984 2 - -
SF 2 1988 - 5 -
DKP 1 1984 3 - 2
DKP 2 1988 - 6 -
DKP 3 1996 - - 8

[- means missings]

I want this:
party survey year V1 V2 V3
SF 1 1984 2 - -
SF 2 1988 - 5 -
DKP 1 1984 3 - 2
DKP 2 1988 - 6 -
DKP 3 1996 - - 8
SF_DKP 1 1984 2.5 - -
SF_DKP 2 1988 - 5.5 -
SF_DKP 3 1996 - - 8

I don´t know if now the question is more clear or not?
Thank you very much for your help.
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create new case as mean of two cases

Postby ana.tourino » Mon Feb 24, 2014 10:46 am

Gutnre wrote:
ana.tourino wrote:Hi all,

I need to create (in the same dataset) a new case wich is the mean of other two cases (for each variable) using syntax.
For example,

I have this:
ID V1 V2
1 2.5 5
2 3.5 6.5

I want to obtain:
ID V1 V2
1 2.5 5
2 4.5 6.5
3 3.5 5.75

Suggestions?

Thanks a lot!
Is it always 2 cases? or is it lots of cases (i.e., is there also case 3 and 4, that have to become case 5)?
Ok,
Its seems I´ve been very unclear. Sorry, I tried to be brief but didn´t work. Thanks anyway!.
Here it is the extended version of the problem:

-I have along database about parties in Europe which merge diferents surveys. Each case is a combination of party*survey*year. As a result, I have several rows for each party. I have information about this cases in diferent scales or variables (50 aprox) with a lot of missings (because the scale make reference to one survey but not to otthers).

-Now I need to link parties not only by the identificators but also creating new cases which "merge" these parties (sometimes 2 parties, sometimes 3) in two different ways:
1. Substituting the real value for the mean of the two parties when They appear in the same survey (challenge: "create a new case as a mean of two cases")
2. Creating new cases with a common name to link it sequentially (challenge: "copy cases", not asked here but suggestions are welcome to make it with syntax).

Yes, It sounds rare but I have these instructions. And, as you note, "merge" means duplicate cases maintaining the originals and the new ones in the same database.

Example First challenge:
I have this:
party survey year V1 V2 V3
SF 1 1984 2 - -
SF 2 1988 - 5 -
DKP 1 1984 3 - 2
DKP 2 1988 - 6 -
DKP 3 1996 - - 8

[- means missings]

I want this:
party survey year V1 V2 V3
SF 1 1984 2 - -
SF 2 1988 - 5 -
DKP 1 1984 3 - 2
DKP 2 1988 - 6 -
DKP 3 1996 - - 8
SF_DKP 1 1984 2.5 - -
SF_DKP 2 1988 - 5.5 -
SF_DKP 3 1996 - - 8

I don´t know if now the question is more clear or not?
Thank you very much for your help.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Create new case as mean of two cases

Postby GerineL » Mon Feb 24, 2014 3:15 pm

does it need to be a new case, or can it be a new variable behind the old ones?
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create new case as mean of two cases

Postby ana.tourino » Mon Feb 24, 2014 6:01 pm

Gutnre wrote:does it need to be a new case, or can it be a new variable behind the old ones?
It must be a new case Gutnre.
I´ve thought a solution with this steps:

1. Create a new dataset only with the cases which I want to merge.
2. Generate an id to identificate which cases will be merged together.
3. Use the Aggregate function with the id as "break" variable.
4. Merge this dataset with the original database.

I didn't find a more direct solution. What do you think?

Thank you very much for your help!
This forum is great! (Sometimes it works in clearing up yourself!)
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Create new case as mean of two cases

Postby GerineL » Tue Feb 25, 2014 8:57 am

Maybe a macro is a solution as was suggested, but unfortunately I don't know anything about that.

Your solution makes sense to me. That's how I would go about it, as I don't know anything about macros.

After step 3, I would delete the original cases (if it is a copy file there sould be no problem there), then replace the variable names.
e.g. rename variables (V1_mean = V1), so you can just use the add cases function in merge.
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create new case as mean of two cases

Postby ana.tourino » Tue Feb 25, 2014 9:00 am

Gutnre wrote:Maybe a macro is a solution as was suggested, but unfortunately I don't know anything about that.

Your solution makes sense to me. That's how I would go about it, as I don't know anything about macros.

After step 3, I would delete the original cases (if it is a copy file there sould be no problem there), then replace the variable names.
e.g. rename variables (V1_mean = V1), so you can just use the add cases function in merge.
Buff macros! I'll study about that someday...
All your suggestions will be followed!
Thanks!

Who is online

Users browsing this forum: No registered users and 1 guest

cron