Converting Returns and Prices Data from Daily to Weekly, Monthly, Quarterly, and Yearly Frequencies.

Converting Returns and Prices from Daily to Weekly, Monthly, Quarterly, and Yearly Frequencies.

It is pretty easy to convert your data from daily frequency to weekly, monthly, quarterly, or yearly frequency. We can use the Stata built-in collapse function after creating period identifiers. Alternatively, we can use the ascol program that I have written.  ascol makes it pretty simple to convert stock returns or prices data from daily to weekly, monthly, quarterly, or yearly frequency.  Since returns and prices need different treatments for conversion (returns need to be summed for their conversion from daily to say weekly frequency, while in case of prices, the conversion will just results in producing end of the week prices.), the program  gives us both the option of converting returns and prices data. 

This program requires data to be a panel data or time series series data. This program can be downloaded from SSC by typing: 

ssc install ascol

For Stata 13, the program can downloaded using net command:

net from "https://sites.google.com/site/imspeshawar"

The program requires the data to be declared as panel data

Syntax

    ascol varlist , return price [frequency options]

options

    return

      This option tells the program that the data is stock returns data.  Since stock returns are already expressed in percentage change form, the collapse treatement would be to sum these returns within the  specified time interval.

    price 

    Alternatively, users can specify that the data in memory is  share prices data using option price. The return and price cannot be combined together. To collapse prices to desired frequency,  the program finds the last traded prices of the period which the users       specify.

Let us use some examples to understand how the program works

Examples   

  In all of the following examples, I assume that we have data or returns (named as ri) and prices (named as pr)

Let us first generate some examples data for practice. 

-----------------------------------------------------+

set obs 1000                           |

gen date=date("1/1/2012" , "DMY")+_n   |

format %td date                        |

gen pr=10                              |

replace pr=pr[_n-1]+uniform() if _n>1  |

gen ri=(pr/l.pr)-1                     |

save stocks,replace                    |

---------------------------------------+     

From Daily to Weekly

From Daily to weekly –returns

----------------------------------+

use stocks, clear                 |

ascol returns, toweek returns     |

                                  |

OR                                |

ascol ri, tow r                   |

--------------------------------------------- +                                   

ascol is the program name, ri is the variable name in our data set, toweek is the program option that tells Stata that we want to convert the daily data to weakly frequency, and the return option tells Stata that our ri variable is return (i.e. already converted from prices into periodic returns)

From Daily to weekly – Prices

----------------------------------+

use stocks, clear                 |

ascol returns, toweek prices      |

                                  |

OR                                |

ascol ri, tow p                   |

--------------------------------------------- +       

Other Options

ascol can also be used similarly as in the above examples to convert from daily to monthly, quarterly, and yearly frequency. The options to be used in each case are given below;

From daily to monthly, option tomonth or tom is to be used

From daily to quarterly, option toquarter or toq is to be used

From daily to yearly, option toyear or toy is to be used

For more detailed examples, see this PDF file 

  **********************