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

Re: computing new variable using "IF" statement

by George Emerson D'Umbra :: Rate this Message:

Reply to Author | View in Thread

Hi Heather,
Try this:

vector p = partner1gender to partner3gender.
compute #same_sex=0.
compute #op_sex = 0.
loop #I = 1 to 3.
  if gender=p(#I) #same_sex =1.
  if gender~=p(#I) #op_sex=1.
end loop.
compute partnergender = sum(#same_sex, #op_sex*10).
recode partnergender (0=SYSMIS) (10 = 2) (11 = 0) .
execute.

Regards,
George
----- Original Message -----
From: "Heather" <hblunt@...>
To: <SPSSX-L@...>
Sent: Tuesday, July 07, 2009 4:23 PM
Subject: computing new variable using "IF" statement


> 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