Home › Forums › ASROL : Rolling Window and by-Group Descriptive Statistics › Converting daily returns to weekly returns in Stata
Nath KackGuestDecember 25, 2020 at 7:48 amPost count: 116
I’m a student and looking for help about converting daily returns to weekly returns in Stata. In fact, I read some of your posts and tried to use ascol without success.
the code for raw_return is :
g raw_return = log(price[_n]/price[_n-1])
Could you please tell me which code I need to use?
Thank you very much in advance for your help,
Have a wonderful day,
NathanAttaullah ShahKeymasterDecember 25, 2020 at 8:07 amPost count: 68
To convert daily returns to weekly, you can either use asrol or ascol. Both of them employ similar methods, though ascol is specifically designed for this task. The help file of ascol provides several examples in this regard. You might also find this blog entry helpful. In the following paragraph, I show one additional example using data from my site.
* Install ascol from SSC
ssc install ascol
* Generate log returns bys symbol : gen daily_return = ln(close / close[_n-1]) * Create weekly date gen week_date = wofd(date) format week_date %tw * Convert the daily returns to weekly ascol daily_return , returns(log) keep(all) toweek gen(weekly_return) timevar(date) panelvar(symbol)
returns(log) : Tells ascol that the returns were initially generated using log method. This is important because ascol then applies the simple summation method to convert the returns from daily to weekly frequency.
keep(all): When we convert data from daily to a lower-frequency such as weekly, monthly, etc., we end up with repeated values of the converted variable. We often just need one value of the variable per cross-sectional unit and time-period. Therefore, the repeated observations are not needed and should be dropped. This is what the Stata’s collapse command does. The default in ascol is to collapse the data to a lower frequency and delete all other variables except the newly created one. However, there might be circumstances when we want to retain all the observations without collapsing the data set. Towards this end, we can use the option keep(all) or keep(vars). keep(all) will keep the data set as it was before running the command, while keep(vars) will collapse the data to a lower frequency and keep all the variables of the data set. Here is the summary:
keep(all) conversion happens without collapsing the data and without deleting other variables
keep(vars) conversion happens without deleting other variables; data collapses to a lower frequency
timevar(date) panelvar(symbol) : If the data is already declared as panel with the tsset, these two options are not required. If the data is declared as panel data, then timevar() is used to declare the time variable and panelvar() is used to declare the panel variable, here it is the company symbol.
- You must be logged in to reply to this topic.