version: 2.0
help ascol Dec 28, 2017

Title

ascol - Converts asset returns and prices from daily to a weekly, monthly, quarterly, and yearly frequency

Syntax

ascol
varname,
returns([simple | log])
prices
keep([all | vars])
frequency_options
timevar(varname)
panelvar(varname)
generate(newvar)

Description

ascol converts daily data of asset prices or returns to weekly,
monthly, quarterly, or yearly frequencies. When converting asset prices to a lower frequency, ascol selects the last price in the given period.
For converting asset returns, ascol offers two possibilities - either to sum the daily returns or find products of the daily returns.
The first choice is used with daily log returns while the second is used with daily simple returns (Detailed discussion is given below). ascol requires that the existing data has a time variable that
tracks daily dates. If the data is already tsset or xtset, ascol will automatically
pick the time and panel variables from the previous tsset or xtset declarations. In case the data is not already set for time or panel dimensions, then
the time variable has to be set by using the option timevar(varname).

Options

1. returns(simple | log): If varname has daily returns data, we need to use the returns() option. This option
can be used with two variations : simple returns and log returns. For detailed discussion,
examples, and comparisons of simple and log returns, please visit my web page here.
See the following details of when to use which of the two sub-options:

1.1 returns(simple) : If daily returns have already been calculated with the following
formula;

simple ri = ( Price[i] – Price[i-1] ) / Price[i-1] ... (Eq. 1)

Then the appropriate method to convert the returns to n-period cumulative returns would be;

Cumulative n-period simple returns = (1+simple_r1) * (1+simple_r2) *(1+simple_r3) … (1+simple_rn) – 1 ... (Eq. 2)

By invoking option returns(simple), ascol applies Eq. 2 to find n-period cumulative
returns.

1.2 returns(log) : If daily returns have already been calculated with the following
formula;

log_ri = ln(Price[i] / Price[i-1]) ... (Eq. 3)

Then the appropriate method to convert the returns to n-period cumulative returns would be to just sum the daily returns

By invoking option returns(log), ascol sums the daily returns to find n-period cumulative returns.

Therefore, users must exercise care in selecting the appropriate option in converting daily returns to n-period cumulative returns.

2. prices : If the data in memory are asset prices, we shall use the option prices. Please note that option return and prices
cannot be combined together. To collapse prices to the desired frequency, the program finds the last traded prices of the period.

3. Frequency Options

ascol has the following options for data conversion:

toweek converts from daily to weekly frequency

tomonth converts from daily to monthly frequency

toquarter converts from daily to quarterly frequency

toyear converts from daily to yearly frequency

4. timevar(varname) and panelvar(varname)

ascol needs a variable that tracks daily dates. If the data is already tsset, asocl
will automatically pick the time variable. Therefore, there will be no need to use the option timevar().
Similarly, if the data is already xtset, ascol will pick both the time and panel variables from
the previous xtset declarations. Again, there will be no need to use the otpions timevar()
or panelvar(). However, if the data has duplicates or has other reasons that do not allow the tsset
or xtset declarations, then we shall have to inform ascol about the time and/or panel variables of the
data set through options timevar(varname) and panelvar(varname).

5. keep(all) or keep(vars)

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 newely 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

6. generate(newvar)

This is an optional option to specify the name of the new variable. If left blank, ascol will automatically
name the new variable as varname_frequency.

Example Data Set

copy the following and run from Stata do editor

clear
set obs 1000
gen date=date("1/1/2012" , "DMY")+_n
format %td date
tsset date
gen pr=10
replace pr=pr[_n-1]+uniform() if _n>1
gen simpleRi=(pr/l.pr)-1
gen logRi = ln(pr/l.pr)
save stocks,replace

Example 1: From Daily to weekly - simple returns

Suppose we have already generated daily simple returns using Equation 1,
we shall convert them to weekly returns with:

. use stocks, clear

. ascol simpleRi, toweek returns(simple)

ascol is the program name, simpleRi is the stock return variable in our data set,
toweek is the program option that tells Stata to convert daily
data to weekly frequency, and the returns(simple) option tells Stata that our simpleRi variable
has simple stock returns and therefore ascol will apply Equation 2 above to find cumulative weekly returns.
Please note that we did not use the option timevar(varname) and panelvar(varname)
as our data is already tsset.

Example 2: From Daily to weekly - log returns

Suppose we have already generated log returns using Equation 2,
we shall convert them to weekly returns with:

. use stocks, clear

. ascol logRi, toweek returns(log)

ascol is the program name, logRi is the stock return variable in our data set,
toweek is the program option that tells Stata to convert daily
data to weekly frequency, and the returns(log) option tells Stata that our logRi variable
has log stock returns.Therefore ascol will just sum the returns within each week to find cumulative weekly returns. Please note that we did not use the option timevar(varname) and panelvar(varname)
as our data is already tsset.

Example 3: From Daily to monthly - prices

. use stocks, clear

. ascol pr, tomonth price

pr is the variable name that has stock prices data, tomonth option specifies
conversion from daily to a monhtly frequency, and the price specifies that the conversion is
needed for stock prices data.

Converting Data to Other Frequencies

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

. ascol pr, toq price

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

. ascol pr, toy price

Example 4: Conversion without collapse - keep all observations and variables

We shall use the option keep(all) to retain all variables and observations in the data set.
After conversion, you can see that there are duplicate values of the newely created variable week_simpleRi.

. use stocks, clear

. ascol simpleRi , toweek returns(simple) keep(all)

Example 5: Collapsing by time variables only - keep variables

We shall use the option keep(vars) to retain all variables while collapsing the data to a lower frequency.
After conversion, you can see that there are no duplicate values of the newely created variable. week_simpleRi.

. use stocks, clear

. ascol simpleRi , toweek returns(simple) keep(vars)

Author

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: *
* *
* Dr. Attaullah Shah *
* Institute of Management Sciences, Peshawar, Pakistan *
* Email: attaullah.shah@imsciences.edu.pk *
* See my webpage for more programs and help at: *
* http://www.OpenDoors.Pk *
* https://FinTechProfessor.com *
*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*

Also see

asm : for momentum portfolios

astile : for creating fastest quantile groups

asgen : for weighted average mean

asrol : for rolling-window statistics

asreg : for rolling-window, by-group, and Fama and MacBeth regressions

searchfor : for searching text in data sets