I am working in a extensive dataset - and I need to calculate new
variables based on the existing variables in the dataset.
Say if I have
Var1 Var2 Var3 Var4 Var5
And I need to calculate a new variable which is the sum of
var2+var3+var5
then I can choose transform->compute and compute the new variable
But if I want to check later whether that variable is correctly
calculated - spss have forgotten how it was calculated (or it is
overwritten because I have calculated several variables like this). So
how can I save such variable calculations? In Excel I would create a
formula which I can always turn back to and edit - but how is this
done in SPSS?
Thanks very much in advance for any help.
/MG
When you exit the menu for transform->compute, exit via the PASTE
button. This will generate syntax for your computation, which you can
save. For the computation to happen, you must then run the syntax.
See the RUN menu in the syntax window for various options (e.g., run
selected, run to end, run all).
For more info on why use of syntax is so essential, see:
http://www.spsstools.net/SampleSyntax.htm
http://www.spsstools.net/LearningSyntax.htm
http://www.spsstools.net/LearningSyntax.htm#KeyItems
Notice especially the 3rd link.
HTH.
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
1) In the compute dialog, the Type & Label subdialog includes the choice to use the compute formula as the variable label.
2) If you use programmability, there is a module named Transform that will automatically create a custom attribute containing the formula. The formula is saved with the data and can be reexecuted, also by programmability code. This supports COMPUTE, RECODE, and COUNT, including DO IF blocks. This feature is only intended for those using Python programmabity, however.
HTH,
Jon Peck
Again thanks a lot for your help. I kinda get it now and was writing
all my calculations in syntaxeditor (I am calculating subscales of a
Symptom Checklist 90 (SCL90) questionnaire). And it looks like it
works and my formulas are saved.
The next issue is that a part of the formula is to divide the result
with the amount of answered items
Say
Index1=item1+item2+item4+item8
and then it should be divided by 4 - that is as long as all 4 items
are answered. If only three of the items are answered then it should
be divided by 3.
Can I make a count like "count if" or how is this done in syntax
editor?
Again I don't think I can thank you enough and I might be pulling my
luck here, but it is pretty hard to get help regarding this elsewhere.
Thanks.
--- snip ---
>
> Again thanks a lot for your help. I kinda get it now and was writing
> all my calculations in syntaxeditor (I am calculating subscales of a
> Symptom Checklist 90 (SCL90) questionnaire). And it looks like it
> works and my formulas are saved.
>
> The next issue is that a part of the formula is to divide the result
> with the amount of answered items
> Say
> Index1=item1+item2+item4+item8
> and then it should be divided by 4 - that is as long as all 4 items
> are answered. If only three of the items are answered then it should
> be divided by 3.
>
> Can I make a count like "count if" or how is this done in syntax
> editor?
>
> Again I don't think I can thank you enough and I might be pulling my
> luck here, but it is pretty hard to get help regarding this elsewhere.
>
> Thanks.
Rather than compute a sum and divide by some N, just use one of the
MEAN functions. Here are a couple examples from the Help files.
COMPUTE MeanValue = MEAN(V1,V2,V3,V4).
COMPUTE NewMean = MEAN.3(V1,V2,V3,V4).
• MeanValue is the mean of the values for V1 to V4. Since the mean can
be computed for one, two, three, or four values, MeanValue is assigned
a valid value as long as any one of the four variables has a valid
value for that case.
• In the last example above, the .3 suffix specifies the minimum
number of valid arguments required. NewMean is the mean of variables
V1 to V4 only if at least three of these variables have valid values.
Otherwise, NewMean is system-missing for that case.
Note that if the variables are contiguous in the file, you could use
the key word TO rather than having to list all variables. I.e.,
COMPUTE MeanValue = MEAN(V1 to V4).
COMPUTE NewMean = MEAN.3(V1 to V4).
HTH.
--
Bruce Weaver
bwe...@lakeheadu.ca
Thank you for this. Interesting though that I didn't think about it as
means. Would there be away to count the number of filled out items
anyway? I guess there is but where can I find it (aaaand now it would
be embarrassing if you refer me to the help files again :-/).
Thanks anyway
Cheers,
It's not always easy knowing where to look in the Help files until
after you've figured something out. Here's what you want:
NMISS. NMISS(variable[,..]). Numeric. Returns a count of the arguments
that have system- and user-missing values. This function requires one
or more arguments, which should be variable names in the active
dataset.
NVALID. NVALID(variable[,..]). Numeric. Returns a count of the
arguments that have valid, nonmissing values. This function requires
one or more arguments, which should be variable names in the active
dataset.
If you hand the same list of variables to NMISS and NVALID, the sum of
those two counts gives the total number of variables in the list.
--
Bruce Weaver
bwe...@lakeheadu.ca