Hello,

I have daily panel data over several years and for several stocks. For each day and for each stock I have the number of stockholders. I have sorted the data by stock.
I now need to calculate a new variable for each row the median stockholders over the previous 30 days. How can I implement this in Stata?
I do not know how to ensure that the median stockholders for each row is computed by the stockholders of the previous 30 days and how to ensure that when it comes to the next stock Stata does not include for this stock some of the previous observations referring to the previous stock.

Would really appreciate your help! Thank you!

Best regards,
Eva