SPSS Statistics

 View Only
  • 1.  Compute variable: Use numeric label of a variable instead of string value

    Posted Fri July 23, 2021 04:30 AM
    Dear community,

    I am new to SPSS and would like to determine the average of 5 questionnaire items as follows: 

    However, this throws the following error message:
    By reducing the formula, I identified that the issue is that the variables are not recognised as integers but as strings. I have added the following labels so that they look like this:

    This is the data when not using the label but the original view:


    ​Is there any possibility to use the labels (1-7) rather than the values (String like "Agree"...) to perform the calculations?

    Thank you very much in advance for your help!

    ------------------------------
    Alexander Farr
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Compute variable: Use numeric label of a variable instead of string value

    IBM Champion
    Posted Fri July 23, 2021 08:49 AM
    First, if you want to sum a bunch of variables within a case, look at the sum function, which can also use TO.  For example
    compute z = sum(var1 to var5)
    To use TO, the variables need to be contiguous in the file.

    Second, the variables need to be numeric.  If they are strings but the strings represent numbers, you can change the variable types in the Data Editor Variable View or use the ALTER TYPE command to make them numbers.

    You would never use variable labels in a computation.  A label is the same for all cases, so this would never make sense.

    Finally, these variable names are extremely long and rather difficult to work with.  I suggest that you rename to have shorter names and use the question text as the variable label.

    ------------------------------
    Jon Peck
    ------------------------------



  • 3.  RE: Compute variable: Use numeric label of a variable instead of string value

    Posted Fri July 23, 2021 10:04 AM
    @Jon Peck, thank you very much for your answer and notes. This is very helpful.

    1. Regarding changing the variable type, I assume that I cannot do it. The data was originally entered as "Agree", "Strongly agree​", etc. In the variable view ->values column, I assigned the according number as labels. How could I use these labels instead for the calculation? Would I need to recode the variable?

    2. Regarding the long names: The question texts were the original column headers. It was imported as you see it with the question texts shown as "Label" in the variable view. How can I show these question labels in the data view?

    Thank you very much in advance for your further help.

    ------------------------------
    Alexander Farr
    ------------------------------



  • 4.  RE: Compute variable: Use numeric label of a variable instead of string value

    IBM Champion
    Posted Fri July 23, 2021 12:17 PM
    Since the values are actually the strings, you would  need to recode the variables.  You could use the RECODE command (Transform > Recode into Different Variables) or use AUTORECODE (Transform > Automatic Recode).  It could be done for all the variables with a single command.

    AUTORECODE would automatically create value labels.  With RECODE you would need to generate those, but if you install the SPSSINC RECODEEX extension command via Extensions > Extension Hub, it  will automatically generate the value labels for you.

    Regarding the second question, you can't have the labels automatically appear in Data View, but if you hover over a column header, the label and other information will appear in a popup.  With such long labels, it would be impractical to have them appear as column headers, but the long names will appear wrapped to the column width.  You can toggle value label display using the toolbar button that has a 1 and A in its image.

    --