Create dummy variables

There is no specific command in SPSS to create dummy variables in the , but various transformation commands help you to create such variables, namely the various forms of the Recode command, as well as conditional transformations.

Below you will find some examples using these facilities to produce dummy variables.

important

A dummy variable is a variable that can take two values, 1 (presence of an attribute) 0 (absence). You should however be aware of the fact that in SPSS this is not necessarily true, as there is also the possibility that a value is actually missing; this is not a problem when you are using dummy variables in your analysis as missing values are by default automatically excluded, but when you create dummies using transformations you need to be careful and know what you want, i.e. a missing value in the original variable should it simply get a value of 0 (not having the attribute) or should it missing.

Example 1: Dummies from categorical variables

Assume that you want to create dummy variables for the continent variable, i.e. a variable coded as shown. As an example we create a dummy variable AsianCountry, where a value of 1 is identifies an Asian country, and 0 all other countries.

Using , select the variable and give the new variable to be created a label as shown.

All Asian countries will - for the new variable - keep a value of 1, all other countries will get a value of 0.

Using command language you would have to write:

   RECODE Continent (1=1) (else=0) into AsianCountry.

Note that if one or several countries had a missing value on the Continent variable, its value on AsianCountry will be 0, i.e. a non-asian country. If this is not what you want, you need to add further specifications dealing specifically with the missing cases.

You might also use to: first create a new variable AsianCountry with all values 0, then assign 1 to it, but only for Asian countries. This is quite cumbersome using menus, especially if you need to create more than one dummy variable; command language is much easier here:

COMPUTE AsianCountry=0.
IF (Continent=1) AsianCountry=1.

Important: Make sure to understand that if you omit the first command, i.e. you only execute (assuming that AsianCountry does not yet exist in the active dataset):

IF (Continent=1) AsianCountry=1.
SPSS will create a new variable, where Asian countries have a value of 1, but all other countries will be missing, i.e. SYSMIS!

Example 2: Dummies from a continuous variable

Assume that you would like to create a dummy variable AgriCountry, where 0 is a country where agriculture is less important (based on the criterion that AgriGDP (% of GDP produced in agriculture is below the mean of all countries (22.9), and 1 a country where agriculture is important (AgriGDP above the mean.

Declare the new variable to be created.

Fill in the specifications as shown.

Using command language you can achieve the same by executing:

RECODE AgriGDP (LOWEST THRU 22.9=1) (ELSE=0) INTO AgriCountry.

Using the IF command you can do the same with:

COMPUTE AgriCountry=0
IF (AgriGDP < 22.9) AgriCountry=1.

The same can be achieved with this command

Using the IF command you can do the same with:

COMPUTE AgriCountry=AgriGDP < 22.9.

This creates a variable with value of 1 if the condition is true and 0 if the condition is false. (In SPSS logical values are represented by 0/1 (false/true).