Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages

# Why user-written Programs

The following list of Stata programs can be used in finance and accounting research and other allied disciplines. In finance, usually we have very large datasets and some of the built-in data tools in Stata are very slow to process such data sets. Take the example of the xtile command that is used for creating quantile groups, or the rolling command for rolling window calculations. These commands are extremely slow. These limitations have always frustrated me and gave me enough motivation to write the following commands.

## 1. asm : A Stata program to create momentum portfolios

[available for nominal price]
I have written an easy to use Stata® program, asm.ado for creation and testing of momentum portfolio returns. The program offers a large number of options which have been used in the momentum literature. This program employs well-known momentum portfolio strategies as suggested in Jagadesh and Titman (1993) and many other options suggested in subsequent papers. This program is equally useful for academics and practitioners. The program offers the following features:…

## 2. asdoc: A Stata program to easily send Stata output to MS Word

asdoc sends Stata output to Word / RTF format. asdoc creates high-quality, publication-ready tables from various Stata commands such as summarize, correlate, pwcorr, tab1, tab2, tabulate1, tabulate2, tabstat, ttest, regress, table, amean, proportions, means, and many more. Using asdoc is pretty easy. We need to just add asdoc as a prefix to Stata commands. asdoc has several built-in routines for dedicated calculations and making nicely formatted tables.
..

## 3. asrol : A Stata program to generate rolling-window statistics and by-group statistics

asrol calculates descriptive statistics in a user’s defined rolling-window or over a grouping variable. The descriptive statistics include standard deviation, mean, median, geometric mean, products, count, minimum, maximum, number of missing values, first observation, last observation, and total.   asrol can efficiently handle all types of data structures such as data declared as time series or panel data, undeclared data, or data with duplicate values, missing values or data having time series gaps..

## 4. ascol : To convert returns and prices from daily to weekly, monthly… frequency.

It is pretty easy with ascol 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. data, undeclared data, or data with duplicate values, missing values or data having time series gaps..

## 5. asreg : A Stata program for rolling-window and by-group regressions

asreg fits a model of the dependent variable on independent variables using linear regression in a user’s defined rolling window or by a grouping variable. The estimation of rolling beta or cross-sectional regression is very common in finance. asreg is very efficient in both estimation of rolling-window regressions or cross-sectional regressions. asreg is an order of magnitude faster than estimating rolling window regressions through conventional methods such as Stata loops or using the Stata’s official rolling command. asreg has the same speed efficiency as asrol. All the rolling window calculations, estimation of regression parameters, and writing the results to Stata variables are done in the Mata language.

## 6. astile : A Stata program for creating quantile categories

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 portfolio 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.
.

## 7. asgen : A Stata program for generating weighted average mean

asgen creates a new variable from an existing variable or an expression. The new variable contains weighted average mean. The existing variable is supplied to asgen by the =exp. The weights are based on the values of an existing numeric variable, that is specified in the weight(varname) option. asgen accepts both the [if] [in] qualifiers for performing the required calculations on a subset of data. Further, the use of =exp can come handy in many situations where we want to make changes on the fly before we find the weighted average mean.

## 8. astx : Creates a table of descriptive statistics by a grouping variable.

astx finds descriptive statistics for a specific variable over a grouping variable. Further, it estimates t-statistics and sends the output file to MS Excel File.

## 9. searchfor : Searches for texts in selected or all string variables.

searchfor finds text in string variables and either lists the selected variables on screen or edits the variables in Data Editor. The search text is capitalization free.

#### Omar

March 24, 2019at 10:36 pm

Hi
First, many thanks for the incredible effort!
Just tried the astx command, the link to Excel file leads to a page in internet browser which does not load.
Regards
Omar

#### Attaullah Shah

March 24, 2019at 11:10 pm

Omar
astx is a light program. I would recommend using asdoc for more elegant tables. Still, if you are interested in astx, you can download it from SSC by typing the following in the Stata command window

`ssc install astx`

#### Mark

May 30, 2019at 11:40 pm

Dear Professor,
I was wondering how we can perform a conditional double sorting. For instance, firstly we sort stocks on X generating five quintiles and secondly whithin each quintile we sort stocks on Y generating in total 25 portfolios.
Kind Regards

#### Attaullah Shah

May 31, 2019at 2:54 pm

I think you or someone else posted the same question on Statalist here, if that is not answered there, I shall answer it here.

#### Mark

June 3, 2019at 1:56 am

Dear Professor,
I took a look at the discussion suggested by you but unfortunately I am still confused… Could you answer here?
Many thanks

#### Attaullah Shah

June 3, 2019at 3:18 am

Mark
Your question is not clear to me? What are you asking for?

#### Mark

June 3, 2019at 10:48 pm

Dear Professor,
my question is about how we can perform a conditional double sorting on stata.
Why for instance, in the bivariate independent-sort the breakpoints for each variable are calculated independetly from each other, in the bivariate dependent-sort the second sort, based on value of X2, is done separately for each of the portfolios created by the breakpoints for the first sort variable X1.
According to your codes, I think that the independent double sort could be performed in the following way:
astile X10 = X, nq(10)
astile Y10=Y, nq(10)
and then combine them..
But honestly, I do not know how we can run a dependent double sorting.