Hi there,
My dataset is organised in three columns.
First column (date): weekday dates (excluding public holidays) from 2002 to 2014
Second column (index): S&P500 index level
Third column (return_1d): daily returns (computed from the second column)
I would like to generate 1-day return "terciles" (or tertiles) using 1-year rolling windows. In other words, I would like to generate 2 new columns: the first one should contain for each day, the value of the 33rd percentile of 1-day return for the previous 1-year, and in the second column, the value of the 66th percentile of 1-day returns.
I have tried mvsumm without much success (to be precise, to the best of my knowledge mvsumm would not give me terciles anyways, but I would have been happy at this stage to generate quartiles too). I get an entire column with missing observations. The code I am using is:
"mvsumm return_1d, stat(p25) win(365) gen(bottom_quartile) end"
"mvsumm return_1d, stat(p75) win(365) gen(top_quartile) end"
I think one of the reason why the code is returning me missing values, is because mvsumm requires me to "tsfill" the date column (i.e., mvsummdoes not allow gaps in the timeseries, and I do not have observations for weekends and public holidays), and all the filled dates have missing values for return_1d.
I am aware of the command "rolling" but I cannot figure out how to generate tertiles out of it.
Any help would be much appreciated.
Best,
Carlo
My dataset is organised in three columns.
First column (date): weekday dates (excluding public holidays) from 2002 to 2014
Second column (index): S&P500 index level
Third column (return_1d): daily returns (computed from the second column)
I would like to generate 1-day return "terciles" (or tertiles) using 1-year rolling windows. In other words, I would like to generate 2 new columns: the first one should contain for each day, the value of the 33rd percentile of 1-day return for the previous 1-year, and in the second column, the value of the 66th percentile of 1-day returns.
I have tried mvsumm without much success (to be precise, to the best of my knowledge mvsumm would not give me terciles anyways, but I would have been happy at this stage to generate quartiles too). I get an entire column with missing observations. The code I am using is:
"mvsumm return_1d, stat(p25) win(365) gen(bottom_quartile) end"
"mvsumm return_1d, stat(p75) win(365) gen(top_quartile) end"
I think one of the reason why the code is returning me missing values, is because mvsumm requires me to "tsfill" the date column (i.e., mvsummdoes not allow gaps in the timeseries, and I do not have observations for weekends and public holidays), and all the filled dates have missing values for return_1d.
I am aware of the command "rolling" but I cannot figure out how to generate tertiles out of it.
Any help would be much appreciated.
Best,
Carlo
Comment