Hi,

attached you find a .dta file with the three columns ticker, date and an index value (gsv_scaled). I now want to create a 4th coloumn which on a firm level gives me the median of all index observations within the previous 180 days.
Using the formular
rangestat (count) gsv_count=gsv_scaled (median) gsv_median_180days=gsv_scaled, int(date_daily -180 -1) by(ticker)
gives me the median for each firm of the previous 180 observations. The problem now is that not for every day there is observation data. Going back in the date using the previous 180 observations will therefore also include observations which are more than 180 days in the past. However, I only want to go back by the specific number of observations which are not more than 180 days older than the date the value is calculated for. How can I adjust the formular above to accomodate for this problem?

Thanks a lot in advance and regads

Marian