## 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**)*.

## How to Install it

ascol can be installed from SSC by typing the following line of code in the Stata command window

ssc install ascol

## Options

ascol has the following options.

## 1. returns

This option can be entered as returns(simple) or returns(log). If we wish to convert daily returns to a lower frequency we shall use this 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 this page . See the following details that explain 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*s cumulative returns would be to just sum the daily returns. By invoking option *returns(log)*, ascol sums the daily returns to find *n-period*s 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,* ascol will automatically pick the time variable. Therefore, there will be no need to use the opt*ion timeva*r(). Similarly, if the data is alr*eady x*tset, ascol will pick both the time and panel variables from the previous xtset

declarations. Again, there will be no need to use the options 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

Let us generate a dummy data set for our example. 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,

**is the program option that tells Stata to convert daily data to**

*toweek*weekly frequency, and

*the returns(sim*ple) option tells Stata that

**our s**imp

**l**eRi 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,

**is the program option that tells Stata to convert daily data to weekly frequency, and the returns(log) option tells Stata that our**

*toweek**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*

**logRi**

**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 monthly 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)

## Questions on ascol:

My ascol command returns the error “Invalid subscript” | Answer is here on the Statalist |

IshaqDecember 9, 2018 at 5:55 pmGreat work sir……….

SalehSeptember 26, 2019 at 8:29 amActually, I used it several times and I double checked the monthly prices, but I found wrong prices.

Attaullah ShahSeptember 26, 2019 at 9:10 pmSaleh

ascol keeps the last price in a given period. In the case of monthly prices, ascol would keep the last price of that month. When you say that you get wrong prices, what exactly is not correct. What command did you use and in what way the output had an error? Please reply with relevant details.

ShiwaniApril 13, 2021 at 2:50 amDear Dr Shah,

I am trying to compute firm-specific weekly returns for my panel data. I came across your website after reading your post on Statalist on changing returns frequency. Do you think the following code makes sense for calculating weekly returns on my panel data?

bys firm_id (date): gen dreturns = ln(pr[_n]/pr[_n-1])

ascol dreturns, toweek returns(log)

thank you!