Hi everyone,

I have two questions for you.
I have a panel in which I have date, ID, company and outcome.
I would generate a dummy if in 30 days id and company are repeated.

I did something like this but is not really working to capture all events.
Code:
 bys company (date): g repetition=(date[_n]-date[_n-1]<30 & company[_n]==company[_n-1] & ID[_n]==ID[_n-1])
Moreover, I want to drop some rows, but before that I would replace the value of outcome as the mean of outcome between the same company and same ID in 30 days.

For instance, I want drop line 2 and substitute outcome in line 1 with the mean between 10 and 20.
DATE ID COMPANY OUTCOME
01/01/2020 1 Y 10
02/01/2020 1 Y 20
03/04/2021 1 Z 45
04/05/2022 2 X 50
Can you help me?

Thanks