SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Help needed with a Syntax compute variable

    Posted Mon December 28, 2020 01:39 PM

    Hello everyone,

    I need help with the analysis of the data for my thesis. I have imported all the data from an Excel file, but the data were classified as string variables. To run the syntax compute variable, I had to change the variables to numeric variables. So I did that with Automatic Recode and it worked, but when I run the syntax now, it calculates all the labels instead of the actual values.

    This is the formula

    COMPUTE trajlength = ABS(X_2 - X_1) + ABS(X_3 - X_2) + ABS(X_4 - X_3) + ABS(X_5 - X_4) + ABS(X_6 - X_5) +

    ABS(X_7 - X_6) + ABS(X_8 - X_7) + ABS(X_9 - X_8) + ABS(X_10 - X_9) + ABS(X_11 - X_10) +

    ABS(X_12 - X_11) + ABS(X_13 - X_12) + ABS(X_14 - X_13) + ABS(X_15 - X_14) + ABS(X_16 - X_15) +

    ABS(X_17 - X_16) + ABS(X_18 - X_17) + ABS(X_19 - X_18) + ABS(X_20 - X_19) + ABS(X_21 - X_20) +

    ABS(X_22 - X_21) + ABS(X_23 - X_22) + ABS(X_24 - X_23) + ABS(X_25 - X_24) + ABS(X_26 - X_25) +

    ABS(X_27 - X_26) + ABS(X_28 - X_27) + ABS(X_29 - X_28) + ABS(X_30 - X_29) + ABS(X_31 - X_30) +

    ABS(X_32 - X_31) + ABS(X_33 - X_32) + ABS(X_34 - X_33) + ABS(X_35 - X_34) + ABS(X_36 - X_35) +

    ABS(X_37 - X_36) + ABS(X_38 - X_37) + ABS(X_39 - X_38) + ABS(X_40 - X_39) + ABS(X_41 - X_40) +

    ABS(X_42 - X_41) + ABS(X_43 - X_42) + ABS(X_44 - X_43) + ABS(X_45 - X_44) + ABS(X_46 - X_45) +

    ABS(X_47 - X_46) + ABS(X_48 - X_47) + ABS(X_49 - X_48) + ABS(X_50 - X_49) + ABS(X_51 - X_50) +

    ABS(X_52 - X_51) + ABS(X_53 - X_52) + ABS(X_54 - X_53) + ABS(X_55 - X_54) + ABS(X_56 - X_55) +

    ABS(X_57 - X_56) + ABS(X_58 - X_57) + ABS(X_59 - X_58) + ABS(X_60 - X_59) + ABS(X_61 - X_60) +

    ABS(X_62 - X_61) + ABS(X_63 - X_62) + ABS(X_64 - X_63) + ABS(X_65 - X_64) + ABS(X_66 - X_65) +

    ABS(X_67 - X_66) + ABS(X_68 - X_67) + ABS(X_69 - X_68) + ABS(X_70 - X_69) + ABS(X_71 - X_70) +

    ABS(X_72 - X_71) + ABS(X_73 - X_72) + ABS(X_74 - X_73) + ABS(X_75 - X_74) + ABS(X_76 - X_75) +

    ABS(X_77 - X_76) + ABS(X_78 - X_77) + ABS(X_79 - X_78) + ABS(X_80 - X_79) + ABS(X_81 - X_80) +

    ABS(X_82 - X_81) + ABS(X_83 - X_82) + ABS(X_84 - X_83) + ABS(X_85 - X_84) + ABS(X_86 - X_85) +

    ABS(X_87 - X_86) + ABS(X_88 - X_87) + ABS(X_89 - X_88) + ABS(X_90 - X_89) + ABS(X_91 - X_90) +

    ABS(X_92 - X_91) + ABS(X_93 - X_92) + ABS(X_94 - X_93) + ABS(X_95 - X_94) + ABS(X_96 - X_95) +

    ABS(X_97 - X_96) + ABS(X_98 - X_97) + ABS(X_99 - X_98) + ABS(X_100 - X_99) + ABS(X_101 - X_100).

    So for example, the actual data is -0.002 and -0.004 but because of the labels these are numbered 12 and 14. That means that the outcomes under the new variable are not the actual values and these are actually way higher than should be.

    Is there any way that I can remove these labels or do something else so that the formula calculates the right values?






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: Help needed with a Syntax compute variable

    Posted Mon December 28, 2020 02:37 PM

    Instead of using AUTORECODE, which does convert strings to numerics but assigns new values, use ALTER TYPE. For example,

    ALTER TYPE StringDate1 to StringDate4 (F8.2).

    would convert the values in those variables to numeric as long as they are actually numbers.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: Help needed with a Syntax compute variable

    Posted Mon December 28, 2020 02:51 PM

    Hi Jon thank you so much for your response! Should I copy paste this formula into Syntax or can I do this with another option in the dataset as well?






    #SPSSStatistics
    #Support
    #SupportMigration


  • 4.  RE: Help needed with a Syntax compute variable

    Posted Mon December 28, 2020 02:54 PM

    p.s. Rather than writing out that long formula, which is tedious and error prone, you could use the following code if the variables are contiguous in the dataset. This requires the SPSSINC TRANS extension command, which you can install from the Extensions > Extension Hub menu in Statistics if you don't already have it. Change the variable specification to fit your data. It is important to match the indentations below in the Python code.

    data list list/x1 to x5(5f8.0).

    begin data

    1 2 3 4 5

    5 4 3 2 1

    end data

    dataset name data.

    list.

    begin program python3.

    def deltasum(*args):

    deltas = sum([abs(args[i] - args[i-1]) for i in range(1, len(args))])

    return deltas

    end program.

    spssinc trans result = absdeltas

    /variables x1 to x5

    /formula "deltasum(<>)".






    #SPSSStatistics
    #Support
    #SupportMigration


  • 5.  RE: Help needed with a Syntax compute variable

    Posted Mon December 28, 2020 11:12 PM

    Just run the syntax. (sorry for the delay. I couldn't log in to this site all day.)






    #SPSSStatistics
    #Support
    #SupportMigration