I have monthly return data and I wanted to calculate a rolling 3 year SD using monthly data I have. However, I want to skip the first year. For example; 3 years monthly SD for Company A in the year 2000 is the SD of the monthly return for the years 2001-2003. For the year 2001, it is going to be the SD of the month returns between 2002-2004 and so on.
So I wrote this:
Code:
gen Year = year(date) /* To extract the year from a monthly date variable*/ rangestat (sd) return, by(gvkey) interval(Year 3 1) /* to calculate sd skipping the first year. that is from t+1 to t+3. gvkey is my Company ID*/
Any Idea?
0 Response to calculating sd using rolling window
Post a Comment