problems recoding string to numeric data: results in missing data

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

problems recoding string to numeric data: results in missing data

ruth
This post was updated on .
I have received a data file that I have uploaded from excel (version 2010) into SPSS (version 20) only to find most variables have been entered in a text format (strings of letter characters rather than numerals e.g. "yes" and "no"). I need to convert them into numeric values (e.g. "1" and "0"). I have looked at several sources on-line tutorials and it would appear that I should be able to use the simple approach of using the "recode" function either from the pull down menu or through the below syntax

RECODE PatQBelief1 ('-9'=SYSMIS) ('no'=0) ('yes'=1) ('not sure'=2) INTO nPatQBelief1.
VARIABLE LABELS  nPatQBelief1 'numeric version of string'.
EXECUTE.

However when I run this I get the new numeric variable named "nPatQBelief1" but the rows are empty of converted data. So I am wondering what I have done wrong?

Any advice gratefully received.
Best wishes,
Ruth
Reply | Threaded
Open this post in threaded view
|

Re: recode string to numeric results in no missing data

Maguin, Eugene
Here is kind of clever idea.

Recode v1 to v10('no'='0')('yes'='1')('-9'=' ').
Execute. /* may not be needed.
Alter type v1 to v10(f1.0).

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of ruth
Sent: Wednesday, August 05, 2015 9:21 AM
To: [hidden email]
Subject: recode string to numeric results in no missing data

I have received a data file that I have uploaded from excel (version 2010) into SPSS (version 20) only to find most variables have been entered in a text format (strings of letter characters rather than numerals e.g. "yes"
and "no"). I need to convert them into numeric values (e.g. "1" and "0"). I have looked at several sources on-line tutorials and it would appear that I should be able to use the simple approach of using the "recode" function either from the pull down menu or through the below syntax

RECODE PatQBelief1 ('-9'=SYSMIS) ('no'=0) ('yes'=1) ('not sure'=2) INTO nPatQBelief1.
VARIABLE LABELS  nPatQBelief1 'numeric version of string'.
EXECUTE.

However when I run this I get the new numeric variable named "nPatQBelief1"
but the rows are empty of converted data. So I am wondering what I have done wrong?

Any advice gratefully received.
Best wishes,
Ruth



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/recode-string-to-numeric-results-in-no-missing-data-tp5730371.html
Sent from the SPSSX Discussion mailing list archive at 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

=====================
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: recode string to numeric results in no missing data

ruth
Many thanks Gene. My (limited) understanding of "Alter type" was that it was great option if I was converting numerals that were tagged as text into numerals tagged as numerals and that if I tried to convert letter strings into numerals using this I would ended up with missing data. When I had a go using alter type this appears to be what has happened but I may be missing something here!
Reply | Threaded
Open this post in threaded view
|

Re: recode string to numeric results in no missing data

Maguin, Eugene
With respect, your reply is uninformative. Step by step: 1) When you did/do a frequencies on (some of) the recoded variables after the variables have been recoded, do you get 0, 1, and ' '? If not, what do you get?
Step 2) what do the frequencies look like after the alter type?

Gene Maguin



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of ruth
Sent: Wednesday, August 05, 2015 10:01 AM
To: [hidden email]
Subject: Re: recode string to numeric results in no missing data

Many thanks Gene. My (limited) understanding of "Alter type" was that it was great option if I was converting numerals that were tagged as text into numerals tagged as numerals and that if I tried to convert letter strings into numerals using this I would ended up with missing data. When I had a go using alter type this appears to be what has happened but I may be missing something here!




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/problems-recoding-string-to-numeric-data-results-in-missing-data-tp5730371p5730373.html
Sent from the SPSSX Discussion mailing list archive at 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

=====================
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: recode string to numeric results in no missing data

ruth
Thanks Gene,
So I am just trying to convert one variable over from string to numeric at the moment to test out the process. There are just 24 rows of data in this instance and four types of responses to code from string to numeric: "yes", "no" "maybe" and "missing" labelled as "-9", converted to "1","0","2" as well as "99" for missing data. If I run a frequency count on the original string variable I get values for yes, no and maybe, and for the newly created numeric variable I get 24 counts of system missing! Any additional advise would be helpful!
Reply | Threaded
Open this post in threaded view
|

Re: recode string to numeric results in no missing data

ruth
For anyone with a similar problem....now have the solution (thank you Mark A), it was simply that within the recode syntax listed (in the original post) there needs to be a complete match in how the variable response options are written i.e. capital first letter for "Yes" if that is how it is written in the data base... because SPSS is case sensitive. This small oversight meant I got missing data and once corrected the syntax works!

Reply | Threaded
Open this post in threaded view
|

Re: recode string to numeric results in no missing data

David Marso
Administrator
My first thought was case sensitivity and was going to request a FREQ of the original variable.
For anyone listening.  Such info is crucial to proper advisement.
---
ruth wrote
For anyone with a similar problem....now have the solution (thank you Mark A), it was simply that within the recode syntax listed (in the original post) there needs to be a complete match in how the variable response options are written i.e. capital first letter for "Yes" if that is how it is written in the data base... because SPSS is case sensitive. This small oversight meant I got missing data and once corrected the syntax works!
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: recode string to numeric results in no missing data

John F Hall
In reply to this post by ruth
Ruth

Tell whoever supplied the data that using text for responses instead of
numeric codes requires far too many key depressions (and is open to typing
errors): safer, and quicker, to stick to numeric except for things like
addresses.  Mixed case labels are easier to read and are more aesthetic.  

Varnames should be kept short: v22 is quicker to type than nPatQBelief1 !

SPSS is only case sensitive for text in labels, not for commands.  

You could have used AUTORECODE to get 1 = Maybe, 2 = Missing, 3 = No 4 = Yes
etc.  Strings starting with a lower case letter or all in UPPER CASE will
get different numeric codes (missing, Missing and MISSING are not the same
thing.  You could then use RECODE to re-order and group the numeric values.


John F Hall (Mr)
[Retired academic survey researcher]

Email:   [hidden email]  
Website: www.surveyresearch.weebly.com
SPSS start page:  www.surveyresearch.weebly.com/1-survey-analysis-workshop






 
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
ruth
Sent: 05 August 2015 17:58
To: [hidden email]
Subject: Re: recode string to numeric results in no missing data

For anyone with a similar problem....now have the solution (thank you Mark
A), it was simply that within the recode syntax listed (in the original
post) there needs to be a complete match in how the variable response
options are written i.e. capital first letter for "Yes" if that is how it is
written in the data base... because SPSS is case sensitive. This small
oversight meant I got missing data and once corrected the syntax works!





--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/problems-recoding-string-to-nu
meric-data-results-in-missing-data-tp5730371p5730378.html
Sent from the SPSSX Discussion mailing list archive at 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

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