Reputation: 21
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?
Upvotes: 2
Views: 394
Reputation: 11310
If you edit your post to add your syntax for importing the data from excel it may be possible to correct it there.
If it can't be changed, autorecode
is not the right way to turn the data from string into numbers. Try this instead:
alter type X_1 to x_101 (f12.4).
while you're at it heres some shorter code to do what you were doing with the numbers:
compute trajlength=0.
do repeat s1=X_1 to x_100 /s2=X_2 to x_101.
compute trajlength=sum(trajlength, abs(s2-s1)).
end repeat.
NOTES:
(f12.4)
for the new number format - you should change that according to the actual data.X_1 to x_100
will only work if these variables are consecutive in the file. If they are not you'll have to name them individually.Upvotes: 1