Group Likert scale responses in SPSS - spss

I have a likert scale, (1-7), I want to group responses 2 to 7 together and leave out response 1. I'm using SPSS and getting a little confused.

I'll assume you wanted to convert a variable. Lets call a variable "var1", and it needs to be converted to a dummy variable (0 and 1). In this case, your original variable can be transformed to "var1r" by using the following code.
RECODE var1 (1=0) (2=1) (3=1) (4=1) (5=1) (6=1) (7=1) into var1r .
The previous codes, creates a new variable, in which higher responses (2-7) are denoted by 1, and lower numbers (1) are denoted by 0. If you cross this variables in a cross tab, by using the next syntax:
cross var1 by var1r .
It would show your different values correspondingly. The latter is a way to verify you have recode your variables correctly. You can use the similar syntax and change variables at will.
Good luck!

I think the best way is to clone the original variable and then RECODE it into the same variable. The advantages are that you'll keep your variables in the same order and you already have the variable label and value labels. So if the variable name is v1, clone it and run
RECODE v1 (7=2).
Now adjust the value labels with
ADD VALUE LABELS v1 2 "this value means ... or ...".
Here you give the meaning of values 2 and 7. For "leaving out" value 1, specify it as a missing value like so
MISSING VALUES v1 (1).
This presumes 1 is the only missing value. Now check all this by running
CROSSTABS v1 by copy_v1.
presuming your clone is called copy_v1. Following these steps is a short and safe road to a perfect result.
UPDATE
I think this syntax -although valid- may not be what the OP meant. Also, see comments below.

For recoding 1 into 0 and all other values into 1, an alternative is
compute v1 = v1 gt 1.
This looks like invalid syntax but it's explained in this tutorial. You can use this trick for a lot of other stuff too.
For staying on the safe side, first clone the original variable so you can cross it with the recoded version to ensure that the result is correct.

Related

Sum multiple variables, while leaving out variables that have a particular value

I'm using SPSS and hoping to create a new variable that houses the sum of a group of previous variables. The catch is: if any of the variables are recorded as "9" then I need to leave them out.
Is there a command that makes this relatively easy? I had thought of doing DO IF, but it seems like that would get extremely tedious with 6 variables as I'd have to code each possible instance unless I'm mistaken. If there is an easier way that I just haven't been able to find, I would be forever grateful!
This is what I'm thinking would need to be done, but could absolutely be wrong:
DO IF (var1<=4 AND var2<=4 AND var3<=4 AND var4<=4 AND var5<=4 AND var6<=4).
COMPUTE newvar=SUM(var1,var2,var3,var4,var5,var6).
ELSE IF (var1<=4 AND var2<=4 AND var3<=4 AND var4<=4 AND var5<=4 AND var6=9).
COMPUTE newvar=SUM(var1,var2,var3,var4,var5).
/* And so on and so forth for each possible variation of the sum.
It's not that this didn't work, I'm just checking to see if there's an easier way before committing the time to it.
Here are some ways to make it shorter:
missing values var1 to var6(9).
compute newvar=sum(var1 to var6).
Now if you don't want to just mark value 9 as missing, but to get rid of it all together:
recode var1 to var6(9=sysmis).
compute newvar=sum(var1 to var6).
If you don't want to change anything in the data, you can go:
missing values var1 to var6(9).
compute newvar=sum(var1 to var6).
missing values var1 to var6().
If all those sulutions are problematic for you, here's the classicle loop solution:
compute newvar=0.
do repeat vr=var1 to var6.
if vr<>9 newvar=newvar+vr.
end repeat.
exe.
Here's another solution just for fun:
count nines=var1 to var6(9).
compute newvar=sum(var1 to var6) - nines*9.

How to merge zero values (vector(0) with metric values in PromQL

I'm using flexlm_exporter to export my license usage to Prometheus and from Prometheus to custom service (Not Graphana).
As you know Prometheus hides missing values.
However, I need those missing values in my metric values, therefore I added to my prom query or vector(0)
For example:
flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} or vector(0)
This query adds a empty metric with zero values.
My question is if there's a way to merge the zero vector with each metric values?
Edit:
I need grouping, at least for a user and name labels, so vector(0) is probably not the best option here?
I tried multiple solutions in different StackOverflow threads, however, nothing works.
Please assist.
It would help if you used Absent with labels to convert the value from 1 to zero, use clamp_max
( Metrics{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0))
+
( Metrics2{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0)
Vector(0) has no label.
clamp_max(Absent(notExists{label=“a”},0) is 0 with label.
If you do sum(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} or vector(0)) you should get what you're looking for, but you'll lose possibility to do group by, since vector(0) doesn't have any labels.
I needed a similar thing, and ended up flattening the options. What worked for me was something like:
(sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp1"} + sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp2"}) or
sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp1"} or
sum by xyz(flexlm_feature_used_users{app="vendor_lic-server01",name="Temp2"}
There is no an easy generic way to fill gaps in returned time series with zeroes in Prometheus. But this can be easily done via default operator in VictoriaMetrics:
flexlm_feature_used_users{app="vendor_lic-server01",name="Temp"} default 0
The q default N fills gaps with the given default value N per each time series returned from q. See more details in MetricsQL docs.

Delete variables based on the number of observations

I have an SPSS file that contains about 1000 variables and I have to delete the ones having 0 valid values. I can think of a loop with an if statement but I can't find how to write it.
The simplest way would be to use the spssaux2.FindEmptyVars Python function like this:
begin program.
import spssaux2
spssaux2.FindEmptyVars(delete=True)
end program.
If you don't already have the spssaux2 module installed, you would need to get it from the SPSS Community website or the IBM Predictive Analytics site and save it in the python\lib\site-packages directory under your Statistics installation.
Otherwise, the VALIDATEDATA command, if you have it, will identify the variables violating such rules as maximum percentage of missing values, but you would have to turn that output into a DELETE VARIABLES command. You could also look for variables with zero missing values using, say, DESCRIPTIVES and select out the ones with N=0.
If you've never worked with python in SPSS, here's a way to get the job done without it (not as elegant, but should do the job):
This will count the valid cases in each variable, and select only those that have 0 valid cases. Then you'll manually copy the names of these variables into a syntax command that will delete them.
DATASET NAME Orig.
DATASET DECLARE VARLIST.
AGGREGATE /OUTFILE='VARLIST'/BREAK=
/**list_all_the_variable_names_here = NU(*FirstVarName to *LastVarName).
DATASET ACTIVATE VARLIST.
VARSTOCASES /MAKE NumValid FROM *FirstVarName to *LastVarName/INDEX=VarName(NumValid).
SELECT IF NumValid=0.
EXECUTE.
Pause here to copy the remaining names in the list and complete the syntax, then continue:
DATASET ACTIVATE Orig.
DELETE VARIABLES *paste_here_all_the_remaining_variable_names_from_varlist .
Notes:
* I put stars where you have to replace my text with your variable names.
** If the variables are neatly named like Q1, Q2, Q3 .... Q1000, you can use the "FirstVarName to LastVarName" form (Q1 to Q1000) instead of listing all the variable names.
BTW it is of course possible to do this completely automatically without manually copying those names (using only syntax, no Python), but the added complexity is not worth bothering with for a single use...

How do you include categories with 0 responses in SPSS frequency output?

Is there a way to display response options that have 0 responses in SPSS frequency output? The default is for SPSS to omit in the frequency table output any response option that is not selected by at least a single respondent. I looked for a syntax-driven option to no avail. Thank you in advance for any assistance!
It doesn't show because there is no one single case in the data is with that attribute. So, by forcing a row of zero you'll need to realize we're asking SPSS to do something incorrect.
Having said that, you can introduce a fake case with the missing category. E.g. if you have Orange, Apple, and Pear, but no one answered they like Pear, the add one fake case that says Pear.
Now, make a new weight variable that consists of only 1. But for the Pear case, make it very very small like 0.00001. Then, go to Data > Weight Cases > Weight cases by and put that new weight variable over. Click OK to apply. Now what happens is that SPSS will treat the "1" with a weight of 1 and the fake case with a weight that is 1/10000 of a normal case. If you rerun the frequency you should see the one with zero count shows up.
If you have purchased the Custom Table module you can also do that directly as well, as far as I can tell from their technical document. That module costs 637 to 3630 depending on license type, so probably only worth a try if your institute has it.
So, I'm a noob with SPSS, I (shame on me) have a cracked version of SPSS 22 and if I understood your question correctly, this is my solution:
double click the Frequency table in Output
right click table, select Table Properties
go to General and then uncheck the Hide empty rows and columns option
Hope this helps someone!
If your SPSS version has no Custom Tables installed and you haven't collected money for that module yet then use the following (run this syntax):
*Note: please use variable names up to 8 characters long.
set mxloops 1000. /*in case your list of values is longer than 40
matrix.
get vars /vari= V1 V2 /names= names /miss= omit. /*V1 V2 here is your categorical variable(s)
comp vals= {1,2,3,4,5,99}. /*let this be the list of possible values shared by the variables
comp freq= make(ncol(vals),ncol(vars),0).
loop i= 1 to ncol(vals).
comp freq(i,:)= csum(vars=vals(i)).
end loop.
comp names= {'vals',names}.
print {t(vals),freq} /cnames= names /title 'Frequency'. /*here you are - the frequencies
print {t(vals),freq/nrow(vars)*100} /cnames= names /format f8.2 /title 'Percent'. /*and percents
end matrix.
*If variables have missing values, they are deleted listwise. To include missings, use
get vars /vari= V1 V2 /names= names /miss= -999. /*or other value
*To exclude missings individually from each variable, analyze by separate variables.

Please help on using SPSS to add scales of Likert-type

Since the last post is closed due to unclear expression, here is a edited one.
There are in total 20 items from 5 Likert-type scale questions from a questionnaire. I need to add the 20 items from 5 separate questions to create a total scale. I already got the data.
The question is just like the picture above. How can I run the command to add the 20 items from 5 separate questions? What is the command?
Is it something like Transform > Compute variable. Enter a variable name, specify which items to add up, and hey presto (e.g. "V1+V2+V3" etc)?
You can do exactly as you suggested, using the Transform -> Compute variable... function. Simply type in the name of your new scale in the Target variable box and the addition you want in the Numeric variable box.
You will see that the following SPSS syntax command is run:
COMPUTE total=v1 + v2 + v3 + v4.
EXECUTE.
If any of the variables has a missing value, the simply adding them will result in a missing value as well. If you don't want to impute for missing values, using the MEAN command in syntax works well. Also, if the variables are contiguous in the data file, you can make the syntax much more readable by using the TO modifier.
COMPUTE myscore=MEAN(variable1 TO variable5)*5.
The resulting value provides an efficient expected value.
However, it seems like the problem in this case is that the data entry process has dummy coded all of the items, producing 20 separate variables instead of 5, where each block of 4 variables has a value of 0 or 1 but represents the values 1 to 4. In this case, you can use the following syntax:
COMPUTE mycounter=1.
COMPUTE myscore=0.
EXECUTE.
DO REPEAT a=variable1 TO variable20.
COMPUTE myscore=myscore+mycounter*a.
COMPUTE mycounter=mycounter+1.
IF (mycounter=5) mycounter=1.
END REPEAT.
EXECUTE.
Note that the variables from variable1 to variable20 must have each set of dummy codes from the original items clustered together in ascending order.

Resources