Computing New Variables

Using a wide variety of mathematical functions, you can compute new variables based on highly complex equations. In this example, however, we will simply compute a new variable that is the difference between the values of two existing variables.

The data file demo.sav contains a variable for the respondent's current age and a variable for the number of years at current job. It does not, however, contain a variable for the respondent's age at the time he or she started that job. We can create a new variable that is the computed difference between current age and number of years at current job, which should be the approximate age at which the respondent started that job.

  1. From the menus in the Data Editor window choose:

    Transform > Compute Variable...

  2. For Target Variable, enter jobstart.
  3. Select Age in years [age] in the source variable list and click the arrow button to copy it to the Numeric Expression text box.
  4. Click the minus (–) button on the calculator pad in the dialog box (or press the minus key on the keyboard).
  5. Select Years with current employer [employ] and click the arrow button to copy it to the expression.
    Figure 1. Compute Variable dialog box
    Compute Variable dialog box

    Note: Be careful to select the correct employment variable. There is also a recoded categorical version of the variable, which is not what you want. The numeric expression should be age–employ, not age–empcat.

  6. Click OK to compute the new variable.

The new variable is displayed in the Data Editor. Since the variable is added to the end of the file, it is displayed in the far right column in Data View and in the last row in Variable View.

Next