For testing the validity of parallel trend assumption I need to know how many observations I have ( state-year level) in each lag of my event study. The idea is that parallel trend tests can be underpowered, and I need to make sure that I have enough observations in the pre-time to be able to correctly reject the null hypothesis.

I've so far figured out how I can address the issue. The problem is - still quite didnt wrap my head around how I can code it :

1. I need to Create a relative year measure first

2. Then , I need to Use bysort or a loop and "tab statefip" for relative year values (if statement)

Any suggestion how I should code it up for these two steps ?