SPSS Calculate variable based on values of other variables BUT not necessarily all variables need to meet conditions - spss

I'd like to create a new variable based on values of other variables (which is absolutely simple) BUT I encounter the problem when I need to find what function I should use when it gets to make specific condition.
The problem is I need an output 0-1 (1 when the condition is met & 0 when it's not) but not all the variables need to met this condition but at least 6 from all of 9.
In following example the condition is that the output will be 1 when all variables met condition and I need to specify that at least 6 from them need to do so:
Q25=3 & Q39=2 & Q38=1 & Q37=3 & Q36=2 &
Q35=1 & Q34=1 & Q33=3 & Q32=2
I tried to find solutions in group of functions but didn't find the specific one. Hope I wrote it clear enough to understand my problem.

Instead of using a logical condition, you can turn this into a mathematical condition. SPSS treats each logical value as a mathematical 0-1 value too, so:
compute YourNewVar=sum(Q25=3, Q39=2, Q38=1, Q37=3, Q36=2,
Q35=1, Q34=1, Q33=3, Q32=2)>=6.

Related

How to test if an equation is in its simplest (most compact) form

I'm building a learning tool where students are required to solve/enter mathematical equations. I'm using maxima to compare the answer of the student with the solution entered by the teacher to determine whether or not the student has solved it correctly. I would like to allow equivalent answers but only if they are in their simplest form. So if the answer is a+(b+1)/2, then a+(1+b)/2, (b+1)/2+a and (1+b)/2+a are also correct, but a+(2b+2)/4 is not.
Is there a way to do this in maxima?
I tried using ratsimp to simplify the expression and then check if it has remained the same, if so it would mean it was already in its simplest form. Unfortunately, if I use this on a+b for instance, it changes the order of the variables to b+a. Is there some way to check if two expressions are identical except for the order of the operations?
For future reference, I found that you can use the following:
args(expression), simp: false
This will return an array of all the arguments, without simplifying, which we then can use to check if this array is the same for two expressions except for the order.

How to recode first two digits SPSS

I have two variables, A and B, that both use a 5-digit code starting with 50. So variable A might be 50123 to designate orange and B might be 50123 to designate apple. The codes were originally constructed to be concatenated together to create a single hierarchy code. I now need to consider them independently and must be able to distinguish between a code for variable A and variable B.
Bottom line is I want to recode variable A items from 50123 to 60123 and variable B items from 50123 to 70123. What's the best way to do this in SPSS without having to manually enter items either in syntax or the recode dialog box?
Thanks
If variables A and B are numbers, you could try
compute A=A+10000.
compute B=B+20000.
If they are strings, this should work:
compute A=concat("6", char.substr(A,2,5)).
compute B=concat("7", char.substr(B,2,5)).

Check values existence using spss syntax

I should check existence of values based on some conditions.
i.e. i have 3 variables, varA, varB and varC. varC should not be empty only if varA>varB (condition).
i normally use some syntax to check any of the variables and run a frequency of any of them to see if there are errors:
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
exe.
fre ck_varC.
exe.
I had some errors when the condition became complex and when in the condition there are missing() or other functions but i could have made a mistake.
do you think there is an easier way of doing this checks?
thanks in advance
EDIT: here an example of what i mean, think at a questionnaire with some routing, you ask age to anyone, if they are between 17 and 44 ask them if they work, if they work ask them how many hours.
i have an excel tool where i put down all variables with all conditions, then it will generate the syntax in the example, all with the same structure for all variables, considering both situations, we have a value that shouldn't be there or we don't have a value that should be there.
is there an easier way of doing that? is this structure always valid no matter what is the condition?
In SPSS, missing values are not numbers. You need to explicitly program those scenarios as well. you got varC covered (partially), but no scenario where varA or varB have missing data is covered.
(As good practice, maybe you should initialize your check variable as sysmis or 0, using syntax):
numeric ck_varC (f1.0).
compute ck_varC=0.
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
***additional conditional scenarios go here:.
if missing(varA) or missing(varB) ck_varC=3.
...
fre ck_varC.
By the way - you do not need any of the exe. commands if you are going to run your syntax as a whole.
Later Edit, after the poster updated the question:
Your syntax would be something like this. Note the use of the range function, which is not mandatory, but might be useful for you in the future.
I am also assuming that work is a string variable, so its values need to be referenced using quotation signs.
if missing(age) ck_age=1.
if missing(work) and range(age,17,44) ck_work=1.
if missing(hours) and work="yes" ck_hours=1.
if not (missing (age)) and not(1>0) ck_age=2. /*this will never happen because of the not(1>0).
if not(missing(work)) and (not range(age,17,44)) ck_work=2. /*note that if age is missing, this ck_work won't be set here.
if not(missing(hours)) and (not(work="yes")) ck_hours=2.
EXECUTE.
String variables are case sensitive
There is no missing equivalent in strings; an empty blank string ("") is still a string. not(work="yes") is True when work is blank ("").

Create custom formula from Mathematical numbers and operators

I need to create a customized formula generated from Numbers (1-100) & Operators (+,-,*,/). The precedence of operation has to be dynamic. User can choose the numbers/operators one-by-one. But how to arrange the precedence for where to put the Brackets and all to make it a valid expression. For Example :
(21*430)-17+((45/5)+135)+243-16
((97+74)+242-(169+13)*4)/76-21+(36*4012)
We need to take numbers/operators as inputs but the order/type can be dynamic & random. The only limitation is in an expression the total numbers used is fixed (here in 1. 8 numbers & 2. 10 numbers).
Please suggest a feasible solution to this.

How do I run multiple sets of regressions in SPSS without having to retype the command each time?

How do I run multiple sets of regressions in SPSS without having to retype the command each time or without having to change the dependent variable every single time manually?
I need to run a lot of regressions with the same independent variables but I need to change the dependent variable. Is there a possibility to make this process easier?
Thank you very much for your help.
Note also that if you have to repeat this process for each country, you can use SPLIT FILES with the country id, and statistical procedures, including REGRESSION, will automatically iterate over each country.
Let's say you have 50 dependent variables, each of which needs to be regressed on the same predictors using the same regression options. Paste your list of dependent variables into Excel as a vertical list (cells b1:b50). Into cells a1:a:50 paste that part of your regression syntax that comes before the name of the dependent variable, right up to and including "/dependent ". Into cells c1:c50 paste the part of your syntax that follows the name of the dependent variable. Then in cell d1 type "=concatenate(a1,b1,c1)". Paste that formula down through cells d2:d50 and you'll have your 50 commands to paste into a syntax window. It may show gridlines; SPSS will not have any problem with these.
btw, What sort of research context is it that requires these identically-configured regressions for a large number of outcomes?

Resources