Compute New Variable - Based on Responses to Other Variables

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

Compute New Variable - Based on Responses to Other Variables

Chao yawo-2
Hello Listservers,

I have variables:

X (use of anal-condom)
Y (use of oral condom)
Z (use of vaginal condom)

Each as is coded 1=Yes, 2=No, 0,8,9=Missing.

I want to create a new variable that is set to 1 (CONDUSE = 1), if the respondent uses condom for any type of sex, 2, if not

I tried the following command, however but it is giving me an error regarding the ELSE statement.
If i delete the ELSE statement, the command is not giving me the values for case 2 (those who do not use condom for at all.

COMPUTE CONDUSE=0.
IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
IF ELSE CONDUSE=2.
EXECUTE. 

I will appreciate some help from you all.

thanks - Cy
===================== 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: Compute New Variable - Based on Responses to Other Variables

peter link

IF ELSE is not supported syntax. See DO IF command.

 

peter

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Chao yawo
Sent: Tuesday, March 20, 2018 9:49 AM
To: [hidden email]
Subject: [SPSSX-L] Compute New Variable - Based on Responses to Other Variables

 

Hello Listservers,

 

I have variables:

 

X (use of anal-condom)

Y (use of oral condom)

Z (use of vaginal condom)

 

Each as is coded 1=Yes, 2=No, 0,8,9=Missing.

 

I want to create a new variable that is set to 1 (CONDUSE = 1), if the respondent uses condom for any type of sex, 2, if not

 

I tried the following command, however but it is giving me an error regarding the ELSE statement.

If i delete the ELSE statement, the command is not giving me the values for case 2 (those who do not use condom for at all.

 

COMPUTE CONDUSE=0.

IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.

IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.

IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.

IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.

IF ELSE CONDUSE=2.

EXECUTE. 

 

I will appreciate some help from you all.

 

thanks - Cy

===================== 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: Compute New Variable - Based on Responses to Other Variables

John F Hall

Try something like (untested)

 

COUNT concount = ANALCOND ORALCOND VAGCOND (1).  

IF concount gt 0 conduse = ANALCOND * 100 + ORALCOND*10 + VAGCOND.

FREQ conduse.

 

Values should range from 001 (vagcon only) to 111 (all three).

 

John F Hall  MA (Cantab) Dip Ed (Dunelm)

[Retired academic survey researcher]

 

Email:          [hidden email]

Website:     Journeys in Survey Research

Course:       Survey Analysis Workshop (SPSS)

Research:   Subjective Social Indicators (Quality of Life)

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Peter Link
Sent: 20 March 2018 18:05
To: [hidden email]
Subject: Re: Compute New Variable - Based on Responses to Other Variables

 

IF ELSE is not supported syntax. See DO IF command.

 

peter

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Chao yawo
Sent: Tuesday, March 20, 2018 9:49 AM
To:
[hidden email]
Subject: [SPSSX-L] Compute New Variable - Based on Responses to Other Variables

 

Hello Listservers,

 

I have variables:

 

X (use of anal-condom)

Y (use of oral condom)

Z (use of vaginal condom)

 

Each as is coded 1=Yes, 2=No, 0,8,9=Missing.

 

I want to create a new variable that is set to 1 (CONDUSE = 1), if the respondent uses condom for any type of sex, 2, if not

 

I tried the following command, however but it is giving me an error regarding the ELSE statement.

If i delete the ELSE statement, the command is not giving me the values for case 2 (those who do not use condom for at all.

 

COMPUTE CONDUSE=0.

IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.

IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.

IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.

IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.

IF ELSE CONDUSE=2.

EXECUTE. 

 

I will appreciate some help from you all.

 

thanks - Cy

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

Re: Compute New Variable - Based on Responses to Other Variables

Rich Ulrich
In reply to this post by Chao yawo-2

I think you have not clearly defined what to do for various combinations of MISSings. 

But John Hall's IF  imples the useful step,

    COMPUTE conduse = ANALCOND * 100 + ORALCOND*10 + VAGCOND.
That result shows you all your values, and you might RECODE to your heart's content.


To rely on IF statements to good effective for a hierarchy of preferred answers,

start by setting your lowest priority answer, and end with the one that over-rules all the others.


IF ANY(0, < three vars > )  conduse= 0.

IF ANY(9, < three vars > )  conduse= 9.

IF ANY(8, < three vars > )  conduse= 8.

IF ANY(2, < three vars > )  conduse= 2.

IF ANY(1, < three vars > )  conduse= 1.


Those could be placed in a DO REPEAT, with   testval= 0, 9, 8, 2, 1.

DO REPEAT testval= 0,9,8,2,1.

IF ANY( testval, ANALCOND, ORALCOND, VAGCOND ) conduse= testval.

END REPEAT.


--

Rich Ulrich



From: SPSSX(r) Discussion <[hidden email]> on behalf of Chao yawo <[hidden email]>
Sent: Tuesday, March 20, 2018 12:49:25 PM
To: [hidden email]
Subject: Compute New Variable - Based on Responses to Other Variables
 
Hello Listservers,

I have variables:

X (use of anal-condom)
Y (use of oral condom)
Z (use of vaginal condom)

Each as is coded 1=Yes, 2=No, 0,8,9=Missing.

I want to create a new variable that is set to 1 (CONDUSE = 1), if the respondent uses condom for any type of sex, 2, if not

I tried the following command, however but it is giving me an error regarding the ELSE statement.
If i delete the ELSE statement, the command is not giving me the values for case 2 (those who do not use condom for at all.

COMPUTE CONDUSE=0.
IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
IF ELSE CONDUSE=2.
EXECUTE. 

I will appreciate some help from you all.

thanks - Cy
===================== 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: Compute New Variable - Based on Responses to Other Variables

David Marso
Administrator
In reply to this post by Chao yawo-2
DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote

> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Compute New Variable - Based on Responses to Other Variables

Javier Figueroa
To use ELSE you have to use the DO IF command, not just with an IF,

I hope this serves you,

/* procedimiento recodificacion en nuevas variables con condiciones.

data list list
/ANALCOND ORALCOND VAGCOND.
begin data.
1 1 2
0 1 5 
2 0 1
1 1 5
2 0 1
0 8 2
8 1 1
5 2 1
1 0 2
2 1 5
1 8 0
2 1 2
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

IF any(1, ANALCOND, ORALCOND, VAGCOND)  CONDUSE = 1.
EXE.
RECODE CONDUSE (SYSMIS=2).
EXE.

Sincerely,


2018-03-20 15:51 GMT-06:00 David Marso <[hidden email]>:
DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote
> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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: Compute New Variable - Based on Responses to Other Variables

Jon Peck
Please don't use those EXECUTE commands.  They are forcing four data passes when one would do.

On Tue, Mar 20, 2018 at 4:15 PM Javier Figueroa <[hidden email]> wrote:
To use ELSE you have to use the DO IF command, not just with an IF,

I hope this serves you,

/* procedimiento recodificacion en nuevas variables con condiciones.

data list list
/ANALCOND ORALCOND VAGCOND.
begin data.
1 1 2
0 1 5 
2 0 1
1 1 5
2 0 1
0 8 2
8 1 1
5 2 1
1 0 2
2 1 5
1 8 0
2 1 2
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

IF any(1, ANALCOND, ORALCOND, VAGCOND)  CONDUSE = 1.
EXE.
RECODE CONDUSE (SYSMIS=2).
EXE.

Sincerely,


2018-03-20 15:51 GMT-06:00 David Marso <[hidden email]>:
DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote
> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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
--
Jon K Peck
[hidden email]

===================== 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: Compute New Variable - Based on Responses to Other Variables

Javier Figueroa

Ok, thanks for the recommendation. It is custom, but I will try not to use EXECUTE a lot, I will try to use them properly. I had already heard something about that issue of using many EXECUTE commands.

Sincerely,



2018-03-20 16:34 GMT-06:00 Jon Peck <[hidden email]>:
Please don't use those EXECUTE commands.  They are forcing four data passes when one would do.

On Tue, Mar 20, 2018 at 4:15 PM Javier Figueroa <[hidden email]> wrote:
To use ELSE you have to use the DO IF command, not just with an IF,

I hope this serves you,

/* procedimiento recodificacion en nuevas variables con condiciones.

data list list
/ANALCOND ORALCOND VAGCOND.
begin data.
1 1 2
0 1 5 
2 0 1
1 1 5
2 0 1
0 8 2
8 1 1
5 2 1
1 0 2
2 1 5
1 8 0
2 1 2
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

IF any(1, ANALCOND, ORALCOND, VAGCOND)  CONDUSE = 1.
EXE.
RECODE CONDUSE (SYSMIS=2).
EXE.

Sincerely,


2018-03-20 15:51 GMT-06:00 David Marso <[hidden email]>:
DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote
> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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



--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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
--
Jon K Peck
[hidden email]




--
Javier Figueroa
Procesamiento y Análisis de bases de datos
Cel: 5927-4748 / 4970-1940
Casa: 2289-0184

===================== 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: Compute New Variable - Based on Responses to Other Variables

John F Hall

In haste and tested using Javier's dummy data:

 

data list

/analcond 1 oralcond 3 vagcond 5.

begin data

1 1 2

0 1 5

2 0 1

1 1 5

2 0 1

0 8 2

8 1 1

5 2 1

1 0 2

2 1 5

1 8 0

2 1 2

end data.

 

count concount = analcond oralcond vagcond (1).

recode concount (2,1=1)(0=0) into conduse.

var lev concount (scale) conuse (Nominal).

var lab concount 'Number of methods used'

    /conduse 'Use any methods'.

val lab conduse 1 'Yes' 0 'No'.

 

freq concount conduse.

 

Number of methods used

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

0

1

8.3

8.3

8.3

1

8

66.7

66.7

75.0

2

3

25.0

25.0

100.0

Total

12

100.0

100.0

 

 

 

Use any methods

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

No

1

8.3

8.3

8.3

Yes

11

91.7

91.7

100.0

Total

12

100.0

100.0

 

 

 

mult resp groups = method 'Method(s) used'

    (analcond oralcond vagcond (1))

    /var concount (1,3) conduse (0,1)

    /freq method

    /tab concount conduse by method.

 

method Frequencies

 

Responses

Percent of Cases

N

Percent

Method(s) useda

ANALCOND

4

28.6%

36.4%

ORALCOND

6

42.9%

54.5%

VAGCOND

4

28.6%

36.4%

Total

14

100.0%

127.3%

a. Dichotomy group tabulated at value 1.

 

concount*method Crosstabulation

 

Method(s) useda

Total

ANALCOND

ORALCOND

VAGCOND

Number of methods used

1

Count

2

3

3

8

2

Count

2

3

1

3

Total

Count

4

6

4

11

Percentages and totals are based on respondents.

a. Dichotomy group tabulated at value 1.

 

conduse*method Crosstabulation

 

Method(s) useda

Total

ANALCOND

ORALCOND

VAGCOND

Use any methods

Yes

Count

4

6

4

11

Total

Count

4

6

4

11

Percentages and totals are based on respondents.

a. Dichotomy group tabulated at value 1.

Hope this is close to what you want.

 

John F Hall  MA (Cantab) Dip Ed (Dunelm)

[Retired academic survey researcher]

 

Email:          [hidden email]

Website:     Journeys in Survey Research

Course:       Survey Analysis Workshop (SPSS)

Research:   Subjective Social Indicators (Quality of Life)

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Javier Figueroa
Sent: 20 March 2018 23:48
To: [hidden email]
Subject: Re: Compute New Variable - Based on Responses to Other Variables

 

 

Ok, thanks for the recommendation. It is custom, but I will try not to use EXECUTE a lot, I will try to use them properly. I had already heard something about that issue of using many EXECUTE commands.

 

Sincerely,

 

 

 

2018-03-20 16:34 GMT-06:00 Jon Peck <[hidden email]>:

Please don't use those EXECUTE commands.  They are forcing four data passes when one would do.

 

On Tue, Mar 20, 2018 at 4:15 PM Javier Figueroa <[hidden email]> wrote:

To use ELSE you have to use the DO IF command, not just with an IF,

 

I hope this serves you,

 

/* procedimiento recodificacion en nuevas variables con condiciones.

 

data list list

/ANALCOND ORALCOND VAGCOND.

begin data.

1 1 2

0 1 5 

2 0 1

1 1 5

2 0 1

0 8 2

8 1 1

5 2 1

1 0 2

2 1 5

1 8 0

2 1 2

end data.

execute.

 

numeric id(f8.0).

compute id=$casenum.

execute.

variable level all (scale).

 

IF any(1, ANALCOND, ORALCOND, VAGCOND)  CONDUSE = 1.

EXE.

RECODE CONDUSE (SYSMIS=2).

EXE.

 

Sincerely,

 

 

2018-03-20 15:51 GMT-06:00 David Marso <[hidden email]>:

DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote


> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> 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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/


=====================
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



 

--

Javier Figueroa
Procesamiento y Análisis de bases de datos

Cel: 5927-4748 / 4970-1940

Casa: 2289-0184

===================== 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

--

Jon K Peck
[hidden email]



 

--

Javier Figueroa
Procesamiento y Análisis de bases de datos

Cel: 5927-4748 / 4970-1940

Casa: 2289-0184

===================== 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: Compute New Variable - Based on Responses to Other Variables

John F Hall
In reply to this post by Javier Figueroa

Left this one out:

mult resp groups = method 'Method(s) used'
    (ANALCOND ORALCOND VAGCOND (1))
    /tab method by method.

method*method Crosstabulation

 

Method(s) useda

Total

ANALCOND

ORALCOND

VAGCOND

Method(s) useda

ANALCOND

Count

4

2

0

4

ORALCOND

Count

2

6

1

6

VAGCOND

Count

0

1

4

4

Total

Count

4

6

4

11

Percentages and totals are based on respondents.

a. Dichotomy group tabulated at value 1.

 

You can also do it three ways!  Does DJT?

 

John F Hall  MA (Cantab) Dip Ed (Dunelm)

[Retired academic survey researcher]

 

Email:          [hidden email]

Website:     Journeys in Survey Research

Course:       Survey Analysis Workshop (SPSS)

Research:   Subjective Social Indicators (Quality of Life)

 

From: John F Hall <[hidden email]>
Sent: 21 March 2018 10:18
To: '[hidden email]' <[hidden email]>
Subject: RE: Compute New Variable - Based on Responses to Other Variables

 

In haste and tested using Javier's dummy data:

 

data list

/analcond 1 oralcond 3 vagcond 5.

begin data

1 1 2

0 1 5

2 0 1

1 1 5

2 0 1

0 8 2

8 1 1

5 2 1

1 0 2

2 1 5

1 8 0

2 1 2

end data.

 

count concount = analcond oralcond vagcond (1).

recode concount (2,1=1)(0=0) into conduse.

var lev concount (scale) conuse (Nominal).

var lab concount 'Number of methods used'

    /conduse 'Use any methods'.

val lab conduse 1 'Yes' 0 'No'.

 

freq concount conduse.

 

Number of methods used

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

0

1

8.3

8.3

8.3

1

8

66.7

66.7

75.0

2

3

25.0

25.0

100.0

Total

12

100.0

100.0

 

 

 

Use any methods

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

No

1

8.3

8.3

8.3

Yes

11

91.7

91.7

100.0

Total

12

100.0

100.0

 

 

 

mult resp groups = method 'Method(s) used'

    (analcond oralcond vagcond (1))

    /var concount (1,3) conduse (0,1)

    /freq method

    /tab concount conduse by method.

 

method Frequencies

 

Responses

Percent of Cases

N

Percent

Method(s) useda

ANALCOND

4

28.6%

36.4%

ORALCOND

6

42.9%

54.5%

VAGCOND

4

28.6%

36.4%

Total

14

100.0%

127.3%

a. Dichotomy group tabulated at value 1.

 

concount*method Crosstabulation

 

Method(s) useda

Total

ANALCOND

ORALCOND

VAGCOND

Number of methods used

1

Count

2

3

3

8

2

Count

2

3

1

3

Total

Count

4

6

4

11

Percentages and totals are based on respondents.

a. Dichotomy group tabulated at value 1.

 

conduse*method Crosstabulation

 

Method(s) useda

Total

ANALCOND

ORALCOND

VAGCOND

Use any methods

Yes

Count

4

6

4

11

Total

Count

4

6

4

11

Percentages and totals are based on respondents.

a. Dichotomy group tabulated at value 1.

Hope this is close to what you want.

 

John F Hall  MA (Cantab) Dip Ed (Dunelm)

[Retired academic survey researcher]

 

Email:          [hidden email]

Website:     Journeys in Survey Research

Course:       Survey Analysis Workshop (SPSS)

Research:   Subjective Social Indicators (Quality of Life)

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Javier Figueroa
Sent: 20 March 2018 23:48
To: [hidden email]
Subject: Re: Compute New Variable - Based on Responses to Other Variables

 

 

Ok, thanks for the recommendation. It is custom, but I will try not to use EXECUTE a lot, I will try to use them properly. I had already heard something about that issue of using many EXECUTE commands.

 

Sincerely,

 

 

 

2018-03-20 16:34 GMT-06:00 Jon Peck <[hidden email]>:

Please don't use those EXECUTE commands.  They are forcing four data passes when one would do.

 

On Tue, Mar 20, 2018 at 4:15 PM Javier Figueroa <[hidden email]> wrote:

To use ELSE you have to use the DO IF command, not just with an IF,

 

I hope this serves you,

 

/* procedimiento recodificacion en nuevas variables con condiciones.

 

data list list

/ANALCOND ORALCOND VAGCOND.

begin data.

1 1 2

0 1 5 

2 0 1

1 1 5

2 0 1

0 8 2

8 1 1

5 2 1

1 0 2

2 1 5

1 8 0

2 1 2

end data.

execute.

 

numeric id(f8.0).

compute id=$casenum.

execute.

variable level all (scale).

 

IF any(1, ANALCOND, ORALCOND, VAGCOND)  CONDUSE = 1.

EXE.

RECODE CONDUSE (SYSMIS=2).

EXE.

 

Sincerely,

 

 

2018-03-20 15:51 GMT-06:00 David Marso <[hidden email]>:

DO IF (condition).
blah blah blah.
ELSE IF  (condition).
........
....
ELSE
....
END IF.

But that does NOT address the utterly piss poor mapping of the 3D space to
your proposed values.

Does {0,8,9} REALLY map to a 2?
Look at a 5x5 cube.  That is your 3D space.  What goes into what?
Back to the drawing board.



Chao yawo-2 wrote


> Hello Listservers,
>
> I have variables:
>
> X (use of anal-condom)
> Y (use of oral condom)
> Z (use of vaginal condom)
>
> Each as is coded 1=Yes, 2=No, 0,8,9=Missing.
>
> I want to create a new variable that is set to 1 (CONDUSE = 1), if the
> respondent uses condom for any type of sex, 2, if not
>
> I tried the following command, however but it is giving me an error
> regarding the ELSE statement.
> If i delete the ELSE statement, the command is not giving me the values
> for
> case 2 (those who do not use condom for at all.
>
> COMPUTE CONDUSE=0.
> IF ((ANALCOND=1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.
> IF ((ANALCOND=0) AND (ORALCOND=0) AND (VAGCOND=0)) CONDUSE=0.
> IF ((ANALCOND=8) AND (ORALCOND=8) AND (VAGCOND=8)) CONDUSE=8.
> IF ((ANALCOND=9) AND (ORALCOND=9) AND (VAGCOND=9)) CONDUSE=9.
> IF ELSE CONDUSE=2.
> EXECUTE.
>
> I will appreciate some help from you all.
>
> thanks - Cy
>
> =====================
> 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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/


=====================
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



 

--

Javier Figueroa
Procesamiento y Análisis de bases de datos

Cel: 5927-4748 / 4970-1940

Casa: 2289-0184

===================== 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

--

Jon K Peck
[hidden email]



 

--

Javier Figueroa
Procesamiento y Análisis de bases de datos

Cel: 5927-4748 / 4970-1940

Casa: 2289-0184

===================== 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: Compute New Variable - Based on Responses to Other Variables

Art Kendall
In reply to this post by Chao yawo-2
Rich gave a good suggestion so that you find out what patterns of responses
actually occur in your data.
in <help> look at AUTORECODE. It is sometimes helpful in further use of the
new variable.

A few suggestions for your future work to increase readability and thereby
help yourself, QA reviewers, and possible helpers:

-- After creating a new variable be sure to add a variable label and value
labels.
-- use <autoindent> to clarify the structure of your syntax.
-- reserve "=" as an  assignment  operator and use "EQ" as the logical
operator.
      IF ((ANALCOND EQ 1) OR (ORALCOND=1) OR (VAGCOND=1)) CONDUSE=1.


at the end of your DO logic structure end with something like this (untested
PRINT command).
This will document to yourself and to others that you have provided for all
alternative combinations
ELSE.
        PRINT / 'oops should not be here'.
END IF.

In this instance, I would go with Rich's suggestion about concatenating
variables into a new  variable.

but there will be times when ANY will be useful.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Art Kendall
Social Research Consultants