Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stacking (and unstacking) data columns

634 views
Skip to first unread message

David Atkins

unread,
Nov 22, 1999, 3:00:00 AM11/22/99
to

Hello, I have a problem which I suspect others have had as well. Namely,
is it possible within SPSS to stack and unstack data columns? We do
marital research and sometimes we have husband and wife data in separate
columns:

ID HVAR WVAR
1 5 6
2 4 7
3 5 5
4 4 6
...

And, we'd like to stack the husband and wife column into a single column
and add a sex variable:

ID SEX VAR
1 1 5
1 2 6
2 1 4
2 2 7
3 1 5
3 2 5
4 1 4
4 2 6
...

Any ideas on how this can be done?

Thanks in advance,

Dave Atkins

Manuel Hernandez Martin

unread,
Nov 22, 1999, 3:00:00 AM11/22/99
to
One way it can be done is to create a sex variable and save the husband and
wife data into 2 separate files, them merge both into a a single file. When
merging you will have to rename the hvar and the wvar.
something like this should work:
compute sex = 'H' .
save outfile ='husband' /keep= id sex hvar.
compute sex = 'F' .
save outfile ='wife' /keep= id sex wvar.
add files /file = 'husband' /rename (hvar=var)
/file ='wife' /rename (wvar=var).
save outfile='unstacked file'.

hope that helps.
Manolo

Rich Ulrich

unread,
Nov 24, 1999, 3:00:00 AM11/24/99
to
On Mon, 22 Nov 1999 10:27:13 -0800, David Atkins
<dat...@u.washington.edu> wrote:

> Hello, I have a problem which I suspect others have had as well. Namely,
> is it possible within SPSS to stack and unstack data columns? We do
> marital research and sometimes we have husband and wife data in separate
> columns:

ID HUSBAND-score WIFE-score
becomes two records per family, with
ID Gender=1 Score
ID Gender=2 Score

after you use the "LOOP" instruction, and Xsave. You might also use
Vector Who(2).

Then, while LOOPing on Gender=1,2
you +compute Score=Who(Gender),
and write out, +Xsave ... ID, Gender, Score.

Look for a detailed example on the SPSS website.

--
Rich Ulrich
http://www.pitt.edu/~wpilib/index.html

Russ916

unread,
Nov 25, 1999, 3:00:00 AM11/25/99
to
David, I disagree with creating duplicate records as it tends to come back and
bite you later. But...

string family(a8).
compute family = hvar.
sort cases by id.
save outfile= his.sav
/keep id hvar family
/compressed.
compute family = ' '.
compute family = wvar.
sort cases by id.
save outfile= her.sav
/keep id wvar family
/compressed.

add files
file= his.sav
/file= her.sav.

sort cases by id.


0 new messages