Page 1 of 1

Filter based on multiple conditions

Posted: Fri Apr 10, 2020 1:21 am
by tcford
Hi all,
I am trying to filter out rows where two conditions are met (e.g., sex and age over 40). I can create a filter that removes all cases that are males and all cases that are over 40 years (sex != "M" and age < 40), but what if I only want to filter out males who are over 40? So all males under the age of 40 remain active?
My apologies if this question has been answered already. I have tried a number of variations but cant seem to work it out.
Thanks,
Talitha

Re: Filter based on multiple conditions

Posted: Fri Apr 10, 2020 10:09 am
by MAgojam
Hi Talitha,
The filter has the purpose of selecting only the data that supports it and excluding the others for the statistics that you are going to use, but also updating those you have already done.
In your case, if you want to run statistics that only include cases where the Sex variable is "M" to select only males and the Age variable must only have values greater than 40 years, you can filter:
Sex == 'M' and Age> 40
You can see the attached screenshot.
screenshot_filter.png
screenshot_filter.png (63.82 KiB) Viewed 9896 times
Greetings and Happy Easter.
Maurizio

Re: Filter based on multiple conditions

Posted: Fri Apr 10, 2020 11:04 am
by jonathon
maurizio is spot-on,

but another thing you can do is use the '+' button to the top left of the filters. this way you can create separate filters:

the first one: `Sex == 'M'`, and `Age > 40` for the second one. the nice thing about doing them separately, is you can see at a glance why a row was excluded. but both ways work.

cheers

jonathon

Re: Filter based on multiple conditions

Posted: Tue Mar 02, 2021 1:37 pm
by enricocmendoza
jonathon wrote:maurizio is spot-on,

but another thing you can do is use the '+' button to the top left of the filters. this way you can create separate filters:

the first one: `Sex == 'M'`, and `Age > 40` for the second one. the nice thing about doing them separately, is you can see at a glance why a row was excluded. but both ways work.

cheers

jonathon
Hi Jonathon,

Good day. Can i ask you for the command if i want to filter the following: I only want to include ages between 25 and 34, and countries only like Sweden, Norway, Finland, Denmark in my analysis. I am using GEM data set. Hope you can help me on this. Thank you very much.

Warm regards,

Enrico Mendoza

Re: Filter based on multiple conditions

Posted: Tue Mar 02, 2021 9:52 pm
by jonathon
i'd create two filters

25 < age < 34

country == 'Sweden' or country == 'Norway' or country == 'Finland' or country == 'Denmark'

jonathon

Re: Filter based on multiple conditions

Posted: Tue Dec 19, 2023 9:28 am
by tcford
Hello, I'm back again. What if I want to filter out rows where 2 conditions are met. For example have a column of participant IDs (1,2,3, etc) and a column of treatments (A,B). Each participant has 4 rows (4 time points [T1-T4]), where they have treatment A for 2 time-points and treatment B for the other 2.
How would I exclude the rows for participant 1 AND ONLY condition B, leaving participant 1 and condition A as active in the data?
Thanks for your help!

Re: Filter based on multiple conditions

Posted: Mon Jan 01, 2024 10:43 pm
by jonathon
> leaving participant 1 and condition A as active in the data?

participant == 1 and condition == 'A'