Hello!

I'm certain there is a simple answer to this, so please feel free to direct me to the resource. I am hoping to count the number of events after a specific event occurred. My data are currently in wide format.

As an example of the data, I have created the below table. I am hoping to create a totals column that would count the number of events after "Event 2" occurred. I have looked at egen commands, but haven't been able to identify the right one, so wasn't sure if there was another option or if I should continue searching egen commands.
Person id Visit1 Visit2 Visit3 Visit4 Totals
01 Event 1 Event 2 Event3 Event4 2
02 Event2 Event3 Event4 Event1 3
03 Event3 Event1 Event2 Event5 1
04 Event2 Event1 Event4 Event3 3
Appreciate the help!