version: 3.2.2
help astile April 17, 2018

Title

astile - Creates variable containing quantile categories

Syntax

astile
newvar = exp
[if] [in]
[, nquantiles(#)
qc(string)
by(varlist)]

Description

astile creates a new variable that categorizes exp by its quantiles. For example, we might be interested in making 10 firm size-based
portfolios. This will involve placing the smallest 10% firms in portfolio 1, next 10% in portolio 2, and so on. astile creates
a new variable as specified in the newvar option from the existing variable which is specified in the = exp. Values of the newvar
ranges from 1, 2, 3, ... up to n, where n is the maximum number of quantile groups
specified in the nq option. For example, if we want to make 10 portfolios, values of the newvar will range from 1 to 10.

astile is faster than Stata official xtile. It's speed efficiency matters more in larger data sets or when the quantile
categories are created multiple times, e.g, we might want to create portfolios in each year or each month. Unlike Stata's
official xtile, astile is byable. astile handles groupwise calculations super efficiently. For example, the difference in time when
used with bys and without bys is usually few seconds in a million observations and 1000 groups.

Options

astile has the following three optional options.

1. nquantiles : The nq(#) option specifies the number of quantiles. For example, nq(4) will create quratiles, making 4 equal groups of the data
based on the values of the selected variable. The default value of nq is 2, that is the median.

2. by : astile is byable. Hence, it can be run on groups as specified by option by(varlist).

3. qc(string) : qc is an abbreviation for qunatiles criterion. This option can be used if the qunatile breakpoints need to be based on a subset of the data, and then observations
in the entire data set (off course in the toused sample as created by the [if] [in] options) are assigned to these break points.

Example 1: Create 10 groups of firms based on thier market value

. webuse grunfeld

. astile size10=mvalue, nq(10)

Example 2: Create 5 groups of firms based on thier market value in each year

. webuse grunfeld

. astile size5=mvalue, nq(5) by(year)

OR

. bys year: astile size5=mvalue, nq(5)

Example 3: Use option qc: breakpoints ared based on prices of foreign

Let use use the auto data set and make 10-qunatile breakpoints based on values of the variable price where the made is foreign, and then
assign observations in the entire data set to these breakpoints.

. sysuse auto

. astile P10 = price, nq(10) qc(foreign == 1)

Example 4: Use option qc with string variables

qc accepts both numeric and string variables or other general Stata expressions. For example, if foreign was coded as a string variable in the
previous example, we could have typed:

. decode foreign , gen(foreign2)

. astile Ps102 = price, nq(10) qc(foreign2=="Foreign")

Author

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: *
* *
* Dr. Attaullah Shah *
* Institute of Management Sciences, Peshawar, Pakistan *
* Email: attaullah.shah@imsciences.edu.pk *
* www.OpenDoors.Pk *
* www.StataProfessor.com *

*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*

Also see

fastxtile,
egenmore,
xtile,
asreg,
asrol,
searchfor