Category Archives: Blog

  • 5

asdoc: Exporting customized descriptive statistics from Stata to MS Word / RTF


Osama Mahmood has asked : 

If I want to report 25th and 75th percentiles for variables through asdoc, then how would I do that? And what if I do not want to report the Min and Max?

Answer: In this YouTube video, I have shown various methods in which descriptive statistics can be reported using asdoc. What Osama has asked for is possible with the customized descriptive statistics using the stat() option of asdoc. Using option stat(), we can choose from the following statistics. Each of the bold words in the following list represents the control word that can be used to report the required statistic.

N Number of observations
mean Arithmetic mean
sd Standard deviation
semean Stanard error of the mean
sum Sum / total
range Range
min The smallest value
max The largest value
count Counts the number of non-missing observations
var Variance
cv Coefficient of variation
skewness Skewness
kurtosis Kurtosis
iqr Interquartile range
p1 1st percentile
p5 5th percentile
p10 10th percentile
p25 25th percentile
p50 Median or the 50 percentile
p75 75th percentile
p99 99th percentile
tstat t-statistics that the given variable == 0


Example 1: Mean, sd, 25th percentile, median, and 75th percentiles

 sysuse auto
asdoc sum, stat(mean sd p25 p50 p75) replace


Example 2: Mean, sd, 25th percentile, median, and 75th percentiles, range, t-statistics

 asdoc sum, stat(mean sd p25 p50 p75 range tstat) replace

  • 2

asdoc: Export matrix to MS Word | the case of xttab command in Stata


asdoc provides a variety of ways in which results from various Stata commands can be exported to MS Word or an RTF file. In this blog post,  I show how to export a Stata matrix to MS word. Usually, Stata commands leave results in r() or e() macros and sometimes in a Stata matrix. Consider the example of xttab command.  xttab is a generalization of tabulate oneway. It performs one-way tabulations and decomposes counts into between and within components in panel data. The command returns results in the r(results) matrix which we can then send to MS word.


The syntax

asdoc follows the following syntax for exporting matrix to a word document.

asdoc wmat, matrix(matrix_name) [rnames(row names) cnames(row names) replace append other_options]



wmat is the command name – an abbreviation for writing matrix. Option matrix() is a required option to get the name of an existing matrix. Option rnames() and cnames() are optional options to specify row names and column names of the matrix. If these options are left blank, existing row and column names of the matrix are used. Other options of asdoc can also be used with wmat. For example, replace will replace an existing output file, while append will append to the existing file. fs() sets the font size, while option title() can be used to specify the title of the matrix in the output file.

An example: The case of xttab command

The dataset that we shall use is from the help file of xttab.

webuse nlswork
xtset id year
xttab race
mat T = r(results)
asdoc wmat, mat(T) replace



1. The first line downloads the example data

2. The second line declares the data as panel data

3. The third line tabulates the race variable

4. The fourth line creates a matrix with the name T from the xttab command

5. The fifth line writes the T matrix to a Word file. wmat is a sub-command in asdoc for writing matrix data to the output file. The two words after command are options of asdoc. The first option tells asdoc about the name of the matrix that has to be exported. The second option tells asdoc to replace any existing output file.

asdoc produces the following Table.

Results Table
































Over a grouping variable?

If we wished to do the above for each category of the grouping variable msp, that has two categories i.e., 0 and 1, we can use the if qualifier and append the results to the same file. So

xttab race if msp == 1
mat T = r(results)
asdoc wmat, mat(T) replace title(When msp == 1)
xttab race if msp == 0
mat T = r(results)
asdoc wmat, mat(T) title(When msp == 0)


When msp == 1





































When msp == 0





































  • 2

asdoc: using option row for creating customized tables row by row in Stata | MS Word

Category:asdoc,Blog Tags : 


Option row is a new feature in version 2.0 of asdoc. This feature allows building tables in pieces. That is good news for those who want to make highly customized tables from Stata output.

This feature can be considered an advanced topic and might not be good for Stata beginners. With many other Stata commands, using asdoc is exceptionally easy. You can read this concise blog post for some basic examples of using asdoc. However, if you are already familiar with Stata macros and results returned in r() and e() macros, then you should continue reading this post.


How does option row work?

Option row allows building a table row by row from text and statistics. In each run of asdoc with option row, a row is added to the output table. The syntax for using this option is given below:

asdoc, row(data1, data2, data3, ...)

As shown above, we shall type nothing after the word asdoc. Therefore, all other arguments of the command come after the comma. The first required option is row(data1, data2, …). Here data1, data2, … can be either a numeric value, string, or both. Within the brackets after option row, each piece of data should be separated by the character comma and hence it will be written to a separate cell in the output table. If a cell is empty, then each comma should be accompanied by a backslash that is  “,\”


We can use the following options when using option row. dec(): for specifying the number of decimal points. If not used, the default is to use three decimal points. An example of using this option could be dec(2) for using two decimal points. title() : This will add a title to the table. This option works only when the row option is used for the first time in the creation of a table. For example, title(Descriptive Statistics). replace: this option will replace any existing file. Without option replace, the default is to append results.

save(): This will save file with the specified name. For example, save(Table 1) will save the file with the name Table 1. 

A simple example

To understand how does the option row work, let us write first the table column title and then some data. Let us create a table that has four columns. The columns are named as KP, Sindh, Baluchistan, and Punjab. We shall write the table title as Provincial GDP of Pakistan.  So the first row is the header row

 asdoc, row(Years, KP, Sindh, Baluchistan, Punjab) title(Provincial GDP of Pakistan over years) replace

The above line of code generates the table title and the header row. Please note that also included the Years in the table columns because we shall report the provincial GDP over years, so we need one additional column for displaying the year labels in the first column. Now let us continue writing to this table. Make sure that you close the Word file before writing additional rows to it.

asdoc, row(1999, 2500.55, 4000.35, 1000.21,  5500.74) dec(2)

In the second line of code, we did not write replace as we wanted to append the results to the same file “MyFile.doc” and we also skipped the title option. We used option dec(2) to use two decimal points with numeric values. We can continue writing additional rows to this table.

asdoc, row(200, 2600.25, 4500.35, 1100, 5700.87) dec(2)


Collecting stats with option accum

we can create a table from text and statistics that are collected from different Stata commands. There is one challenge to developing flexible tables with option row – that a given row has to be written in one go. So once a row is written, no further cells can be appended to the same row. This means that we need to first collect all the required bits of information before writing a row. Collecting and holding these bits of information can be tricky or too time-consuming. To facilitate this process, asdoc offers option accum(data1, data2,…). The word accum is an abbreviation that I use for accumulate. The syntax of this option is given below:

asdoc, accum(data1, data2, data3, data4, data5, ...) [ dec(#) show ]

Actually, the above command can be run as long as the limit of global macro to hold data is not reached. The above command will accumulate text and statistics from different runs of asdoc and hold them in the global macro ${accum}. Once we have accumulated all the needed bits of information in the global macro, then its contents can be written to the Word table with option row. Option show can be used to show the contents of the global macro ${accum}. Assume that we want to build an odd table that presents the number of observations, mean, and standard deviation for two variables in two different time periods. The researcher wants to follow the following format:

webuse grunfeld, clear

asdoc, row( \i, \i, invest, \i, \i, kstock,\i) replace

asdoc, row( Periods, N, Mean, SD, N, Mean, SD)

sum invest if inrange(year , 1935, 1945)

asdoc, accum(`r(N)', `r(mean)', `r(sd)')

sum kstock if inrange(year , 1935, 1945)

asdoc, accum(`r(N)', `r(mean)', `r(sd)')

asdoc, row( 1935-1945, $accum)



1. The second row of our required table reveals that a total of 7 cells are needed, this is why we created 7 cells in the first line of code. The text ” \i,” is a way of entering an empty cell. We entered empty cells so that the variables names invest and kstocks are written in the middle of the table. 2. The second line of code writes the table header row. 3. The third line finds summary statistics. We shall collect our required statistics from the macros that are left behind in r() by the sum command. 4. The fourth line accumulates the required statistics for our first variable invest 5. We are not yet writing the accumulated statistics to the Word file. So we find statistics for our second variable kstocks in the fifth line. 6. We again accumulate the needed statistics for our second variable in the sixth line. 7. Since our row of required statistics is now complete, we write the accumulated statistics and the first-row label, i.e, 1935-1945 to our Word file. Let us write one more row to the table. This time, the statistics are based on years 1946-1954

sum invest if inrange(year , 1946, 1954)

asdoc, accum(`r(N)', `r(mean)', `r(sd)')

sum kstock if inrange(year , 1946, 1954)

asdoc, accum(`r(N)', `r(mean)', `r(sd)')

asdoc, row( 1946-1954, $accum)

  • 11

Research Topics in Finance: Asset Pricing

Category:Blog Tags : 


Investor sentiment: Does it augment the performance of asset pricing models?

Mispricing and the five-factor model

Size, value, profitability, and investment: Evidence from emerging markets

4 Noisy prices and the Fama–French five-factor asset pricing model

5 Cross-sectional tests of the CAPM and Fama–French three-factor model

6 Decomposing the size, value and momentum premia of the Fama–French–Carhart four-factor model

7 Monday effect in Fama–French’s RMW factor

8 Digesting anomalies in emerging markets: A comparison of factor pricing models

9 Q-theory, mispricing, and profitability premium

10 Limits of arbitrage and idiosyncratic volatility

11 Is size dead? A review of the size effect in equity returns

12 Market states and the risk-based explanation of the size premium

13 Market volatility and momentum

14 A risk-return explanation of the momentum-reversal “anomaly”

15  Time-varying risk, mispricing attributes, and the accrual premium

16 Bayesian tests of global factor models

17 Model comparison tests of linear factor models in stock returns

18 Multi-factor asset pricing models: Factor construction choices and the revisit of pricing factors

19 Idiosyncratic volatility in the Asian equity market

20 What global economic factors drive emerging Asian stock market returns?

  • 2

asdoc : Easily create Summary Stats in Stata and send it to MS Word: A video example

Category:Blog Tags : 

In this video post, I show the use of asdoc for the different type of summary statistics in Stata and sending them to MS word. Examples given in this video include:

  1. Default summary statistics that include the number of observations, mean, standard deviation, minimum, and maximum
  2. Detailed summary statistics that include no. of observations, mean, standard deviation, 1st percentile, median, 99th percentile, skewness, and kurtosis
  3. Customized summary statistics
  4. Controlling the number of decimal points
  5. Creating new files
  6. appending to existing files

I would really appreciate if you comment on this video on Youtube and subscribe to my channel if you have not already done that.

  • 2

Dropping i.dummies from regression | asdoc | Word | Stata

Category:asdoc,Blog,Stata Programs Tags : 

Questions: I have time and location dummies which I want to include in the regression, but do not want to report them in the regression nested tables created with asdoc. How can I do that?

If you have not already installed asdoc, you can install it from SSC by typing the following in the Stata command window:

ssc install asdoc

Let’s use an example data set.

use, clear

This dataset has four main independent variables, named as x1, x2, x3, x4 and a set of possible dummy variables that will be constructed from the variable year (from 2001-2005) and location (from 1-3).  Let us estimated the following regression:

asdoc reg y x1 x2 x3 i.year i.location, nest drop(i.year i.location) replace

asdoc reg y x1 x2 x4 i.year i.location, nest drop(i.year i.location)


In the above two lines, we have estimated two regressions and sent their output to a Word file.  In the first line, we estimated a regression with the three main independent variables x1, x2, and x3 and included the year and location dummies on the fly. The option nest will create a nested regression table. The option drop(i.year i.location) drops these dummy variables from the regression table, however, they are included in the main regression. The two lines produce the following regression table in MS Word. 

[mc4wp_form id=”1409″]

  • 0

Exporting tabs and cross-tabs to MS Word from Stata with asdoc

Category:Blog Tags : 

For installation and other uses of asdoc, please see this short blog post.

Tabulation and Cross-tabs with asdoc

Exporting tables created by Stata commands such as tab, tabulate1, tabulate12, table, tabsum, tab1, tab2, and others to MS word is super easy with asdoc.  As with other commands, we need to just add asdoc as a prefix to the tabulation commands that includes tabulate, tabulate1 tabulate2, tab1, tab2, etc. Since frequency tables in Stata can assume different structures, asdoc writes these tables from log files.


One-way table

Example: One-way table

sysuse auto, clear 
asdoc tabulate rep78, replace


Please note that replace is asdoc option to replace the existing file. If we were to write to the existing file, we would then use option append, instead of replace.


Two-way table of frequencies


webuse citytemp2, clear

asdoc tabulate region agecat, replace


Example: Include row percentages


asdoc tabulate region agecat , nokey row replace

Note nokey suppresses the display of a key above two-way tables.


Example: Include column percentages

asdoc tabulate region agecat , nokey column replace

Example: Include row percentages, suppress frequency counts

asdoc tabulate region agecat, nokey row nofreq replace


One- and two-way tables of summary statistics

Example: One-way tabulation with summary statistics


sysuse auto, clear
asdoc tabulate rep78, summarize(mpg) replace


Example: Two variables tabulation with summary statistics

generate wgtcat = autocode(weight, 4, 1760, 4840)

asdoc tabulate wgtcat foreign, summarize(mpg) replace


Example: Suppress frequencies

asdoc tabulate wgtcat foreign, summarize(mpg) nofreq replace


Multiple-way tabulation (tab1)

tab1 produces a one-way tabulation for each variable specified in varlist.

Example: Multiple-way tabulation

sysuse nlsw88, clear
asdoc tab1 race married grade, replace


Two-way for all possible combinations (tab2)

Example: Two variables tabulation with summary statistics

asdoc tab2 race south, replace

  • 10

Research topics | Corporate Governance and Disclosure

Category:Blog Tags : 

In this blog post, I would like to present a list of research topics related to corporate governance and disclosure choices. 


 The relevance of good corporate governance practices in family controlled and concentrated ownership environment?

 Corporate governance practices, firms performance, and risk? Are these related?

Market risk disclosures and corporate governance structure

4  How and why an independent audit matters?

5   What determines CSR quantity and quality?

6   Usefulness of annual reports to individual investors.

7  Can board diversity play a role in the disclosure process?

8   How mandatory derivative disclosure policy affect CEO compensation and earning smoothing?

9  Earning management and IRFS adoption

10 The impact of Islamic Financial Services Board Standard No. 3 on corporate governance

11 The perception of financial analysts on risk, risk management, and internal control disclosure

12 The role of ethnic directors in corporate social responsibility: Does culture matter?

13 Corporate governance and intellectual capital reporting in a period of financial crisis

14  Extent and determinants of voluntary disclosure for regulatory purposes

15 The impact of company size and multiple directorships on corporate governance effectiveness

16  The capital structure and investment decisions of the small owner-managed firm

17 Governance indicators as determinants of operational risk

18 Corporate governance, size, and disclosure of related party transactions

19  Social media: New challenges and opportunities for corporate governance

20 The Corporate Gini Index (CGI) determinants and advantages

21  Industry concentration and corporate disclosure policy

22  The Impact of Audit Committee Characteristics on Corporate Voluntary Disclosure

23  Equity home bias and corporate disclosure

24  The impact of news articles and corporate disclosure on credit risk valuation

25  Internet-based corporate disclosure and market value

  • 0

Find annual | monthly cumulative (product) of returns

Category:Blog Tags : 

The problem

Let’s say that we have daily stock returns. We want to convert those returns to cumulative returns for a weekly, monthly or yearly frequency.

Where cumulative returns = (1+Ri1) * (1+Ri2) * (1+R3) * … (1+R4) – 1



First create the weekly, monthly or year identifier, and then use asrol program.

Let us use this data set [Click here to download], also shown below and find returns for different frequencies.

input id str20 D returns
 1 30jun1993 .7437958 
 1 02jul1993 .0674011 
 1 06jul1993 .2668857 
 1 14jul1993 .0454151 
 1 19jul1993 .1340756 
 1 29jul1993 .8053644 
 1 13aug1993 .5861199 
 1 24sep1993 .3200437 
 1 19oct1993 .0098762 
 1 19oct1993 .005197 
g date = date(D, "DMY")
drop D


Find weekly cumulative returns

Let us first install asrol from ssc

ssc install asrol

Now create weekly date

gen week = wofd(date)

Now find the returns using asrol

bys id week :  asrol returns, stat(product) add(1)

Note : add(1) adds 1 with each returns before multiplication and then subtracts 1 at the end.

Find monthly cumulative returns

gen month = mofd(date)
bys id month:  asrol returns, stat(product) add(1)

Find yearly cumulative returns

 gen year= year(date)
bys id year:  asrol returns, stat(product) add(1)

  • 2

Research Topics in Finance | Financing / Capital Structure Choices

Category:Blog Tags : 

In this blog post, I would like to present a list of research topics related to financing or capital structure decisions.

 Top managers experiences and firms’ capital structure choices

 Do macroeconomic factors affect the choice of debt /equity financing? How are small firms affected?

 Supply of capital and debt-equity choices

 Persistence in capital structure decisions?

4  Can earning timing affect capital structure decisions?

5   Can stock return shocks affect capital structure decisions?

6   Effects of Capital Structure on Cost of Capital

7  judicial efficiency and capital structure: is there a relation?

8   Cultural and religious effects on capital structure choices

9  Credit market imperfections and capital structure changes

10  How corporate governance affect capital structure decisions

11  How financial crisis plays a role in altering capital structures

12  Country tax system and capital structure choices

13  Information asymmetries and capital structure decisions around the world

14  Product market competition and capital structure decisions

15  Capital structure adjustments: Do macroeconomic and business risks matter?

16  The capital structure and investment decisions of the small owner-managed firm

17  Competing theories of capital structure: pecking order theory vs trade-off theory

18  Can hedging increase the debt capacity of a firm?

19  Can credit ratings determine firm’s capital structure

20  Diversification and capital structure