DESC var (zvar) /SAVE.
You do not need to worry about changing means or standard deviations of a variable, everytime the syntax is run, SPSS automatically recalculates those for you.
SPSS syntax however does not offer an easy way to perform further calculations with the result of a previous calculation (unlike other packages, e.g., R!). So, if you want to merely center (and not standardize) variables, you usually have to first calculate the mean of a variable:
DESC var.
,
read the mean off the output and then insert it into your syntax:
COMPU centered_var = XXX.
where "XXX" is the hard coded mean.
Additionally, if you want to standard deviate variables, for example for simple slopes or simple means analyses, you need the standard deviation of a variable. Again, you need to extract the standard deviation number from the output and then hard code it into your syntax:
COMPU shifted_var_1standarddeviation = var - YYY.
where "YYY" is the specific standard deviation number.
This practice is inconvenient (to say the least) for three reasons:
- In getting the mean from the output, rounding errors as well as other mistakes in copying the number may occur.
- If you happen to prepare analyses for a data file that is not complete yet (i.e., data collection is in process, but you already prepare the analysis script with a portion of data already available to have it ready once all data are in), you will have to revise the mean (or several means for that matter) every time and what is worse: you have to remember to do it. Very error-prone.
- You may want to rerun analyses later with filtered subsets of data. Again: Unnoticed, seemingly inconspicuous but potentially disastrous errors loom large.
COMPUTE temp = 1.
EXECUTE.
AGGREGATE /BREAK temp /var_mean= MEAN(var).
AGGREGATE /BREAK temp /var_sd= SD(var).
COMPUTE centered_var = var - var_mean.
COMPUTE centered_sd_deviated_var = centered_var - var_sd.
EXECUTE.
DELETE VARIABLES temp.
or in short form:
COMPU temp = 1.
EXE.
AGG /BREAK temp /var_mean= MEAN(var).
AGG /BREAK temp /var_sd= SD(var).
COMPU centered_var = var - var_mean.
COMPU centered_sd_deviated_var = centered_var - var_sd.
EXE.
DEL VAR temp.
In this syntax example, var is the name of the variable for which you want to obtain the current mean and standard deviation, and the mean deviated (i.e., centered) variable will be saved in centered_var, and the standard deviated variable (the centered variable minus 1 SD) will be saved in centered_sd_deviated_var (adjust and modify variable names at your own discretion).
Don't forget the EXECUTE.s in the course of this syntax, they are important because SPSS like you to tell it that it is supposed to compute a variable, because this is not at all obvious if you use a statistical software package...
No comments:
Post a Comment