SPSS Statistics

 View Only
  • 1.  Writing Syntax

    Posted Wed August 17, 2022 09:33 AM
    Hello!
    I am a complete newbie when it comes to SPSS...

    I am trying to add a variable to a data set based on a variable that is already listed - for example, I have geographical regions to that I want to assign a score.
    The syntax writer is probably the best option, but I cannot get the syntax to work, and I am not familiar with the commands at all.

    COMPUTE PoliticalPolarization.
    IF(REGION eq 1, PoliticalPolarization eq 4).
    IF(REGION eq 2, PoliticalPolarization eq 3.4167).
    IF(REGION eq 3, PoliticalPolarization eq 3.8235).
    IF(REGION eq 4, PoliticalPolarization eq 3.4615).
    EXECUTE.

    I know there is a problem with the comma (according to the error message), but I do not know what else to put there.
    Also, I believe that I needed to set up the variable in variable view (which I did, and I assigned scoring). Or do still need set up a data list before the compute command?

    Thank you very much for your advice!










    ------------------------------
    A MC
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Writing Syntax

    Posted Wed August 17, 2022 09:39 AM
    Hi. Try:

    NUMERIC PoliticalPolarization (F8.4).
    IF REGION=1 PoliticalPolarization=4.
    IF REGION=2 PoliticalPolarization=3.4167.
    IF REGION=3 PoliticalPolarization=3.8235.
    IF REGION=4 PoliticalPolarization=3.4615.
    EXECUTE.





  • 3.  RE: Writing Syntax

    Posted Wed August 17, 2022 04:52 PM
    Thank you very much! It did the trick.
    Would you mind telling me what  (F8.4) does?

    ------------------------------
    A MC
    ------------------------------



  • 4.  RE: Writing Syntax

    Posted Wed August 17, 2022 04:57 PM
    Glad it worked.

    Think of NUMERIC as SPSS's way of initializing a numeric variable, which includes giving it a format (width and number of decimals to display). There is a counterpart, STRING, for string variables: STRING MyStringVar (A12) - A="Alpha",  12=width (which ranges from 1 to 32767 or something like that).

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------