« Return to Thread: computing new variable using "IF" statement

Re: computing new variable using "IF" statement

by Hillel Vardi :: Rate this Message:

Reply to Author | View in Thread

Shalom

Another simple way to do what you want is the fallowing syntax.

IF (gender EQ 1) AND MEAN(partner1gender TO partner3gender) eq  1
samesex=1 .
IF (gender EQ 2) AND MEAN(partner1gender TO partner3gender) eq  2
samesex=2 .
if sysmis(samesex) samesex=3.
value labels   1   all meal 2 all female  3 mix .
execute .

This syntax will work for any number of partner .

Hillel vardi
BGU



Heather wrote:

> Hello,
>
> I have a dataset in which each participant/respondent has information on
> up to 3 partners.
> I'm trying to compute a new variable that will indicate whether each
> participant had only same sex partners, only opposite sex partners, or
> both. I have separate variables indicating the sex of partner 1,2,and 3,
> and I have a variable for the gender of the respondent.
>
> This is the syntax I have tried, but it is not working:
>
> COMPUTE partnergender.
> IF gender=1 AND partner1gender=1 AND partner2gender=1 AND partner3gender=1
> partnergender=1 (same sex).
> IF gender=2 AND partner1gender=2 AND partner2gender=2 AND partner3gender=2
> partnergender=1 (same sex).
> IF gender=1 AND partner1gender=2 AND partner2gender=2 AND partner3gender=2
> partnergender=2 (opposite sex).
> IF gender=2 AND partner1gender=1 AND partner2gender=1 AND partner3gender=1
> partnergender=2 (opposite sex).
> IF else partnergender=0 (both sexes).
> EXECUTE.
>
>
> Also, not all participants have 3 partners. Some only have 1 or 2. How do
> I account for this also? I'm afraid if I request partnergender="same sex"
> if all 3 partners have same sex as respondent, then if someone only has 2
> partners it won't be computed since not all 3 are same sex (i.e., one is
> missing).
>
> Can someone share with me what might be wrong with the syntax I'm using,
> and how to account for respondents who only have 1 or 2 partners?
>
> Thanks so much in advance,
> Heather
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@... (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
LISTSERV@... (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

 « Return to Thread: computing new variable using "IF" statement