I am trying to count the number of times an event occurred before a particular age. I have data that shows the age at each event over a lifetime (age_at_event1-age_at_event3), as well as the age at which I am no longer interested in counting such events (stop_age). I would like to create a variable (sum_event) which counts the number of times the event of interest occurred prior to the stop age. An example:
ID age_event1 age_event2 age_event3 stop_age sum_event
1 10 17 45 34 2
2 23 31 32 54 3
3 25 55 . 32 1
4 21 . . 22 1
How do I create the appropriate sum_event variable?