Syntax coding for new variables using string variables

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

MeganD
Posts: 6
Joined: Thu Jul 23, 2015 6:03 pm

Syntax coding for new variables using string variables

Postby MeganD » Mon Sep 28, 2015 6:44 pm

I have a categorical variable (GeoSet- categorical variable) with the following categories:
0- other
1- urban
2- suburban
3- both urban/suburban
4- not applicable
5- not sure

various responses have selected "other" and left comments (variable GeoSetOther- string variable) noting "rural" or "rural and suburban" I would like to add the additional categories to my variable:
6- rural
7- both rural/suburban

and ideally re-code the variable with the following options:
0- other
1- urban
2- suburban
3- rural
4-both urban/suburban
5- both rural/suburban
6- not applicable
7- not sure

I am working with two variables GeoSet- the categorical variable and GeoSetOther- the variable containing comments that needs to be made into categories. Is there a way to do this using SPSS syntax? (I would like to conserve the code for future use). Either adding on the additional two categories or adding the categories/ reordering would work.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Syntax coding for new variables using string variables

Postby GerineL » Mon Nov 09, 2015 10:50 am

I am not entirely sure what your question is.

You can use recode to create your new variable, is that what you need? If not please clarify what the question is exactly.
Erikyo
Posts: 28
Joined: Mon Mar 30, 2009 8:20 pm

Re: Syntax coding for new variables using string variables

Postby Erikyo » Thu Nov 12, 2015 9:22 pm

Hi,

First, you are right, you should not transform your GeoSet variable, it is your original variable and contains the original datas. You should leave it as is.

You should built a new variable ! GeoSet2 for example.

Second, your original codes 0, 4 and 5. These should be considered 'special codes' and should be treated as such. Otherwise, they will always end up being in your way.

The good thing is, you can create a new variable, recode GeoSetOther and treat the special codes easily !

Try the following :

COMPUTE GeoSet2 = GeoSet.
EXECUTE.

DO IF (GeoSet2 = 0) .
RECODE GeoSet2 (0=90) .
END IF .
DO IF (GeoSet2 = 4) .
RECODE GeoSet2 (4=97) .
END IF .
DO IF (GeoSet2 = 5) .
RECODE GeoSet2 (5=99) .
END IF .
DO IF (GeoSet2 = 3) .
RECODE GeoSet2 (3=4) .
END IF .
EXECUTE.

DO IF (GeoSetOther = "rural") .
RECODE GeoSet2 (90=3) .
END IF .
EXECUTE.

DO IF (GeoSetOther = "rural and suburban") .
RECODE GeoSet2 (90=5) .
END IF .
EXECUTE.

VALUE LABELS GeoSet2
1 "urban"
2 "suburban"
3 "rural"
4 "both urban/suburban"
5 "both rural/suburban"
90 "other"
97 "not applicable"
99 "not sure".
EXECUTE.

Who is online

Users browsing this forum: No registered users and 1 guest

cron