Hello everybody, Sergiy i need a help for this question.
I would like to write a code to control the age difference between the head of the household and his son is at least 10 years.
For example:
“Age of household head - Age of Son/Daughter >= 10”
I have the variable “relationship to head of household” which is in the table “roster_household” with modalities:
Head of Household
Son/Daughter
Nephew…
1 Like
See validation 3 for this question for some ideas on implementation. This comes from a public questionnaire in /Full questionnaires/Living Standards Survey/Enquête harmonisée sur les conditions de vie des ménages dans la zone UEMOA
.
The code comments are in French, but Google Translate can hopefully help.
Here is the same validation that has been updated/refactored (in a private questionnaire):
/* ============================================================================
ÉCART D'ÂGE ENTRE CM ET ENFANT DOIT ÊTRE 14+ ANS
- POUR CM mâle 14+ ANS
- POUR CM femelle 12+ ANS
============================================================================ */
/* CM == mâle */
s01q02==1 && s01q01==1 ? !membres.Any(x=>x.s01q02==3 && (AgeAnnee-x.AgeAnnee)<14) : // si CM mâle
s01q02==3 ? !membres.Any(x=>x.s01q02==1 && x.s01q01==1 && (x.AgeAnnee-AgeAnnee)<14) : // si enfant du CM mâle
/* CM == mâle */
s01q02==1 && s01q01==2 ? !membres.Any(x=>x.s01q02==3 && (AgeAnnee-x.AgeAnnee)<12) : // si CM femelle
s01q02==3 ? !membres.Any(x=>x.s01q02==1 && x.s01q01==2 && (x.AgeAnnee-AgeAnnee)<12) : // si enfant du CM femelle
true
There may be other ways to do the same, but these leads can likely provide some inspiration.
2 Likes
Than you so much for this!