Having issues with recoding

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

Having issues with recoding

suzycat
Hi! I was hoping someone could help me, as I am new to SPSS and this is my first time recoding...

I have 6 variables I want to recode into one variable

d101b
d101c
d101d
d101e
d101f
d101g

with the values of

0=No
1=Yes
8=DK

I want to recode all six into one Variable (Control). I wrote the following syntax (complete guess :)

RECODE d101b d101c d101d d101e d101f d101g (0,8=1) (1=0) INTO CONTROL.
VALUE LABELS CONTROL 1'No Abuse' 0'Controlling Behavior'.
VARIABLE LABELS CONTROL 'No Abuse vs. Controlling Behavior'.
FREQUENCIES CONTROL.

Do I write each variable separately? I keep getting the error message ">On the RECODE command, an attempt has been made to assign a numeric value to a string variable which is named after the keyword INTO.
>Execution of this command stops.
VALUE LABELS CONTROL 1'No Abuse' 0'Controlling Behavior'.
VARIABLE LABELS CONTROL 'No Abuse vs. Controlling Behavior'.
FREQUENCIES CONTROL.

What am I doing wrong? Thank you for any help you can give me!

=====================
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: Having issues with recoding

Richard Ristow
At 04:25 PM 8/20/2014, susan wrote:

>I have 6 variables (d101b, d101c, d101d, d101e, d101f and d101g)
>with the values of
>0=No
>1=Yes
>8=DK
>
>I want to [combine these] into one variable.

What you want to do, can't be done with RECODE; RECODE strictly maps
each input variable to a single output variable. (The output variable
may be the same as the input.)

>I wrote the following syntax:
>
>RECODE d101b d101c d101d d101e d101f d101g (0,8=1) (1=0) INTO CONTROL.
>VALUE LABELS CONTROL 1'No Abuse' 0'Controlling Behavior'.
>VARIABLE LABELS CONTROL 'No Abuse vs. Controlling Behavior'.

It's not clear to me what you're trying to do -- can you describe it
in words? Do you want CONTROL=0 if any of the input variables has
value 1, or what?

And you have a second problem:

>I keep getting the error message
>>On the RECODE command, an attempt has been made to assign a numeric
>>value to a string variable which is named after the keyword INTO.
>>Execution of this command stops.

 From your VALUE LABELS statement, you want CONTROL to be a numeric
variable. It looks like you already have a variable named CONTROL,
and it's a string. The easiest course is to choose some other name
than CONTROL for the variable you want to create.

=====================
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: Having issues with recoding

Albert-Jan Roskam-2
In reply to this post by suzycat
Hello,

Untested:

RECODE d101b  d101c  d101d  d101e  d101f  d101g (CONVERT) ('0'=1)('8'=1) ('1'=0) 
    INTO bin_d101b  bin_d101c  bin_d101d  bin_d101e  bin_d101f  bin_d101g.
 
Regards,

Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



From: susan <[hidden email]>
To: [hidden email]
Sent: Wednesday, August 20, 2014 10:25 PM
Subject: [SPSSX-L] Having issues with recoding

Hi! I was hoping someone could help me, as I am new to SPSS and this is my first time recoding...

I have 6 variables I want to recode into one variable

d101b
d101c
d101d
d101e
d101f
d101g

with the values of

0=No
1=Yes
8=DK

I want to recode all six into one Variable (Control). I wrote the following syntax (complete guess :)

RECODE d101b d101c d101d d101e d101f d101g (0,8=1) (1=0) INTO CONTROL.
VALUE LABELS CONTROL 1'No Abuse' 0'Controlling Behavior'.
VARIABLE LABELS CONTROL 'No Abuse vs. Controlling Behavior'.
FREQUENCIES CONTROL.

Do I write each variable separately? I keep getting the error message ">On the RECODE command, an attempt has been made to assign a numeric value to a string variable which is named after the keyword INTO.
>Execution of this command stops.
VALUE LABELS CONTROL 1'No Abuse' 0'Controlling Behavior'.
VARIABLE LABELS CONTROL 'No Abuse vs. Controlling Behavior'.
FREQUENCIES CONTROL.

What am I doing wrong? Thank you for any help you can give me!

=====================
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: Having issues with recoding

Richard Ristow
In reply to this post by Richard Ristow
At 05:23 PM 8/20/2014, Susan Cataldo asked, off-list:

>Yes I would like a new variable named CONTROL (or i can name it
>something else) where CONTROL=0 if any of the input variables has value of 1.

Try this (untested):

NUMERIC         CONTROLLING (F2).
COMPUTE         CONTROLLING = NOT ANY(0,d101b TO d101g).
VALUE LABELS    CONTROLLING  1 'No Abuse' 0 'Controlling Behavior'.
VARIABLE LABELS CONTROLLING 'No Abuse vs. Controlling Behavior'.

Notes:
- The NUMERIC statement is not required. I use it to ensure the
variable exists and has the right type and format, before the computation code.
- In the ANY function, the form "d101b TO d101g" works if the
variables are contiguous in your file. If they're not, you'll have to write
"d101b, d101c, d101d, d101e, d101f, d101g"
instead.
- Stylistically, when you have a variable distinguishing between the
presence and absence of something, it's more common to have 1 denote
presence and 0 denote absence, rather than the reverse. What you're
doing will work, but it may slightly confuse others who work with your file.

And I'm replying on-list for the usual reasons: first, to make the
reply available to anyone on the list to whom the information is
useful; and second, to invite corrections or comments by other list members.

=====================
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: Having issues with recoding

suzycat
IT WORKED!! YOU ARE AWESOME! Thank you so much!


On Wed, Aug 20, 2014 at 6:13 PM, Richard Ristow <[hidden email]> wrote:
At 05:23 PM 8/20/2014, Susan Cataldo asked, off-list:


Yes I would like a new variable named CONTROL (or i can name it something else) where CONTROL=0 if any of the input variables has value of 1.

Try this (untested):

NUMERIC         CONTROLLING (F2).
COMPUTE         CONTROLLING = NOT ANY(0,d101b TO d101g).
VALUE LABELS    CONTROLLING  1 'No Abuse' 0 'Controlling Behavior'.
VARIABLE LABELS CONTROLLING 'No Abuse vs. Controlling Behavior'.

Notes:
- The NUMERIC statement is not required. I use it to ensure the variable exists and has the right type and format, before the computation code.
- In the ANY function, the form "d101b TO d101g" works if the variables are contiguous in your file. If they're not, you'll have to write
"d101b, d101c, d101d, d101e, d101f, d101g"
instead.
- Stylistically, when you have a variable distinguishing between the presence and absence of something, it's more common to have 1 denote presence and 0 denote absence, rather than the reverse. What you're doing will work, but it may slightly confuse others who work with your file.

And I'm replying on-list for the usual reasons: first, to make the reply available to anyone on the list to whom the information is useful; and second, to invite corrections or comments by other list members.




--
*Susan Cataldo*

===================== 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: Having issues with recoding

Richard Ristow
In reply to this post by Richard Ristow
Susan Cataldo had asked,

>>Yes I would like a new variable named CONTROL (or i can name it
>>something else) where CONTROL=0 if any of the input variables has value of 1.

At 06:13 PM 8/20/2014, I suggested:

>NUMERIC         CONTROLLING (F2).
>COMPUTE         CONTROLLING = NOT ANY(0,d101b TO d101g).
>VALUE LABELS    CONTROLLING  1 'No Abuse' 0 'Controlling Behavior'.
>VARIABLE LABELS CONTROLLING 'No Abuse vs. Controlling Behavior'.

I'm afraid there's a bug here. In the second line, the first argument
to "ANY" should be 1, not 0.

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