PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 20, 2022

[FIXED] How can I create a new variable in SPSS that contains the lowest number out of 6 variables?

 December 20, 2022     if-statement, spss, syntax     No comments   

Issue

I have 6 age variables (agek1..agek6) and need to create a new variable that contains the value of the lowest age of all those 6 variables. This new variable agejk should therefore only contain the age of the youngest child.

The age variables are not ordered by age, because sometimes the youngest age was written in agek1 and sometimes in one of the other age variables. The age variables agek2..agek6 also contain missings (999), because some people only had one child.

I have tried different solutions in the SPSS syntax, but none really worked sufficiently. Here is one of the solutions I tried for the case when the youngest age was written in agek1:

Do iF (AgeK1  LT AgeK2) AND (AgeK3= 999) OR (AgeK4= 999) OR (AgeK5= 999) OR (AgeK6= 999) .
     Recode Agejk (Else= copy) INTO AgeK1.
End if.

I've also tried the IF-function:

IF AgeK1  LT AgeK2 AND AgeK1 LT AgeK3 AND AgeK1 LT AgeK4 AND AgeK1 LT AgeK5 AND AgeK1 LT AgeK6
     Agejk EQ AgeK1.
IF AgeK2 LT AgeK1  AND AgeK2 LT AgeK3 AND AgeK2 LT AgeK4 AND AgeK2 LT AgeK5 AND AgeK2 LT AgeK6
     Agejk EQ AgeK2.
IF AgeK3 LT AgeK1  AND AgeK3 LT AgeK2  AND AgeK3 LT AgeK4 AND AgeK3 LT AgeK5 AND AgeK3 LT AgeK6
     Agejk EQ AgeK3.

Thanks a lot for your help!


Solution

What you need is the min function:

compute Agejk = min(agek1 to agek6).

Note that if the age variables are not consecutive in the dataset, you'll need to white it this way:

compute Agejk = min(agek1, agek2, agek3, agek4, agek5, agek6).


Answered By - eli-k
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing