how to loop something / make it run multiple times / make it run for multiple seconds

What I'm trying to do is, if i have a certain tag and am in a 5 block radius of any entity, it removes a certain effect from them. What i want to do is: If I get close to them, it detects it like usual but instead of removing it once, it runs it multiple times or if possible for 3 seconds
Continue to help post