Author Archives: Attaullah Shah

  • 0

Fama – MacBeth (1973) procedure: What, how and where | asreg in Stata

Category:Uncategorized

Fama and MacBeth (1973) procedure can be used in testing asset pricing models and other areas. In this post, my primary focus is on its use in testing asset pricing models.


FMB in asset pricing models

It is actually a three-step process. We would divide the time period into three parts.

1. The first step is to find the assets/portfolios betas in the first period. Some researchers would use these betas to classify assets into portfolios.

2. The second step is to find betas of these portfolios in the second period.

3. The third step is to find the portfolio returns in the third period and test whether the betas from the second period can explain these returns? This step involves:
(i) cross-sectional regressions of the portfolio returns on the portfolio betas in each period.
(ii) averaging coefficients from the cross-sectional regressions across time. The standard errors are adjusted for cross-sectional dependence.


What does asreg do in the above process


asreg with fmb option performs step 3(i) and 3(ii). 

asreg can also help in step (1) where individual betas need to be calculated for each stock. The command might look like
Code:

bys company: asreg returns market_returns if period == 1

This means that for typical asset pricing tests, the researcher has to do step (1) and (2) and arrange the data in a panel format, listing portfolio returns and betas as variables in columns. And then use asreg with fmb option, e.g.

keep if period == 3
xtset company month
asreg returns betas, fmb


Where else FMB regression can be used?

Fama and MacBeth (1973) procedure (i.e step 3(i) and (ii)) is also used in areas other than testing the asset pricing models. You can see one example in my paper, Table 3, column 8, page 264

Shah, Attaullah & Shah, Hamid Ali & Smith, Jason M. & Labianca, Giuseppe (Joe), 2017. “Judicial efficiency and capital structure: An international study,” Journal of Corporate Finance, Elsevier, vol. 44(C), pages 255-274.




  • 2

Export correlation table to Word with stars and significance level using asdoc

Category:Uncategorized

The updated version of asdoc can now create a table of correlation with significance levels starred at different levels. The new version can be installed by typing the following line in Stata.


Installation of the new version

net install asdoc, from(http://fintechprofessor.com) replace


An Example

sysuse auto, clear
asdoc pwcorr price mpg rep78 headroom trunk weight length turn , star(all) replace nonum


Explanation

Just like with any other Stata command, we would write asdoc as a prefix to the Stata command. In this case, the Stata command is pwcorr which is followed by the variable names. After the comma, we added option nonum, star(all) and replace. These are explained bellow:

star(all) = This option is used to report stars to signfy significance at different levels. These are: ***

  1. *** to show significance at 1% or bellow
  2. ** to show significance at 5% or bellow
  3. * to show significance at 10% or bellow

nonum = Without using this option, asdoc will report numeric numbers as column headers

replace = This option replaces any existing file

You would be interested in this blog entry where I show several useful options of asdoc that can be used with correlation tables.




  • 0

asdoc abbreviates / truncates my variable names and labels | Word to Stata

Category:asdoc

Stephen Okiya has asked the following question

I notice that the variable names are truncated in spite of using the option abb(100). Do you know why this is the case?


Answer:

asdoc uses the abbrev() function of Mata. For some reasons, the abbrev() function splits the following sentence in half, no matter which value we set for the abbreviation.

loc vari " Child's age when she/he was first fed something other than breast milk"

. dis abbrev("`vari'", 32)
 Child's age when she/he was firs

 . dis abbrev("`vari'", 100)
 Child's age when she/he was firs

However, we set the second argument of abbrev() function to missing, then the full sentence is show

. dis abbrev("`vari'", .)

Child's age when she/he was first fed something other than breast milk

Therefore, if we prefer not to abbreviate any name or label, just provide missing value for the abb() option of asdoc. So the following will show all the text

asdoc sum Q85, label abb(.)




  • 10

Fama and MacBeth regression over 25 Portfolios using asreg in Stata

Category:Uncategorized

Antonio has asked the following question

Dear Sir,
I was wondering how to run a Fama and MacBeth regression over 25 Portfolios. In accordance with your code, the first variable needs to be the dependent variable while the following variables are considered as independent variables. Basically, I would like to calculate the risk premium of a factor over the 25 value and size-sorted portfolios. Therefore in my case, I would have more dependent variables and just one dependent variable.
Thanks for your availability


Answer

To answer your question, I have preareed a dummy dataset, which you can download by typing the following in Stata command window.

use http://fintechprofessor.com/ff.dta, clear

So before running the Fama and MacBeth regressions, this is how the data needs to be structured.

The data is in a long format where the portfolios are tracked by a variable, called the panelvar. The portfolio returns are written in a separate variable, in our case, it is named as returns. The panelvar has values from 1, up to 25. The first 10 observations of the portfolios 1 and 2 look like:

. list in 1/10, noob
   +---------------------------------------------+
   |    mofd   P   returns       size        MTB |
   |---------------------------------------------|
   |  1993m6   1      .038    64.0125   5.224508 |
   |  1993m7   1     .0539   71.86839   4.505145 |
   |  1993m8   1    -.0639   27.82528   1.888283 |
   |  1993m9   1    -.0328   20.08383   7.730755 |
   | 1993m10   1     .0249   59.34985   8.961844 |
   |---------------------------------------------|
   | 1993m11   1     .0657   47.42625   3.766557 |
   | 1993m12   1     .0408   81.47429   5.148165 |
   |  1994m1   1     .0185   42.39914   5.375627 |
   |  1994m2   1     .0323   62.36839   4.882884 |
   |  1994m3   1   -.00598   64.79323   1.281697 |
   +---------------------------------------------+
 . list in 101/110, noob
   +---------------------------------------------+
   |    mofd   P   returns       size        MTB |
   |---------------------------------------------|
   |  1993m6   2     .0114   41.16883   4.549813 |
   |  1993m7   2    -.0158   10.09915   2.136258 |
   |  1993m8   2    .00616   73.43023   2.924793 |
   |  1993m9   2    -.0141   58.28651   7.608449 |
   | 1993m10   2     .0129    63.4972   1.137969 |
   |---------------------------------------------|
   | 1993m11   2    -.0223    16.1786   1.368057 |
   | 1993m12   2     .0322   64.10929   6.226629 |
   |  1994m1   2    -.0144   54.48264   7.883276 |
   |  1994m2   2     .0388   74.99379   1.362888 |
   |  1994m3   2     .0345   68.66164   7.102628 |
   +---------------------------------------------+



How to run the Fama and MacBeth regression

My asreg command is available on SSC, to download it, type:

ssc install asreg, replace

asreg can estimate three types of regressions: (1) cross-sectional regressions (2) rolling window regressions and (3) Fama and MacBeth regressions. You can read more details here.

Since our main focus here is on the Fama and MacBeth procedure, the discussion this point onwards will use option fmb of the asreg program. The syntax is:

asreg depvar indepvars, fmb

The data must be first declared as panel data with the xtset command. In our dataset, we have P as the panel variable and mofd as the time variable, therefore, to declare the data as panel data, the xtset command would be:

xtset P mofd

In our dataset, we have the variable returns as the dependent variable and size and MTB as the two independent variables. The command for the Fama and MacBeth regression would be:

. asreg returns  size MTB , fmb


Explanation

retunrs = The dependent variable

size and MTB = independent variables


  • 1

asdoc Unicode issue | Stata to MS Word

Category:Uncategorized

For those who are not yet familiar with asdoc, asdoc can be downloaded from SSC and can be used with almost all Stata commands. Here is a short blog post that shows how asdoc can be used with any Stata command. You can also watch several YouTube videos that show the use of asdoc


asdoc installation

 ssc install asdoc


The problem

Since asdoc uses RTF file format, any Unicode character passed from Stata to the RTF file will be incorrectly shown in the output file. For example, a variable has the following value label which is correctly shown on Stata screen, but when written with asdoc, it is distorted.

Stata view: Don’t know
asdoc view: 

The solution

If you have Stata 14 or higher, then the good news is that you can use unicode command to change the file encoding. Specifically, the subcommand convertfile of unicode command can be extremely useful here. In the following example, I shall download an example dataset, called unicode.dta from my site, and then tabulate the variable M25 with asdoc, write the results to Myfile.doc and convert the coding and write the results to a new file, Myfile_new.doc

use http://fintechprofessor.com/unicode.dta, clear
asdoc tab M25, replace

The file generated by asdoc looks like this, the last line of the file highlights the given issue.

Now lets try the unicode solution.

unicode convertfile  Myfile.doc  Myfile_new.doc, dstencoding(Windows-1252) replace

  • 0

asdoc – custom table title | MS Word | Stata

Category:Uncategorized

For those who are not yet familiar with asdoc, asdoc can be downloaded from SSC and can be used with almost all Stata commands. Here is a short blog post that shows how asdoc can be used with any Stata command. You can also watch several YouTube videos that show the use of asdoc

asdoc installation

 ssc install asdoc


Customizing the table title

The focus of this blog entry to highlight some of the tips that can be used to customize table titles. asdoc produces some generic table titles with many Stata commands. However, the default table titles can be replaced by using the option title. In the following text, I discuss this and seveal other features of asdoc to modify the table titles:


1. Custom titles

If custom titles are needed, just use option title( title text). See the following example.

sysuse auto
asdoc tab rep78 , title(My cutom table title) replace


2. Title not required

We can use an empty title if the table title is not required. In the following example, I am using the backslash (\) inside the title option. This will produce empty title in the document.

asdoc tab rep78 , title(\) replace


3. Title is needed in italics

We can use many RTF directives inside the title option. So to get the title in italics font, the code would be:

asdoc tab rep78 , title(\i My custom table title) replace


4. Title with bigger font size

The default in asdoc is to report table titles in boldface and font size of 10pt. If bigger or smaller font size is needed, again we can pass the RTF directive \fs# to the document. So to produce a title with 14 pt, we shall type:

asdoc tab rep78 , title(\fs28 My custom table title) replace



  • 0

The Error option matrow() not allowed” when using asdoc with tabulate command

Category:Uncategorized

Ronald asked the following question: I am getting the error when using asdoc with tabulate command.
option matrow() not allowed
r(198);

I asked Ronald to send his dataset for a closer look. Upon inspection, it turned out that Ronald was trying to tabulate values of a string variable, and asdoc had problem with that. As a temporary solution, I suggested the following two steps.

Step 1: Convert the string variable to numeric variable with value labels. The good news is that we can do that in one line of code using the encode command. So assume that the string variable name is country, we shall encode it:

encode country, gen(country_new)

where country_new is a new is a new variable with value labels.

Step 2: Now we can use it with asdoc, so to tabulate it and send the output to MS Word, we type:

asdoc tab country_new, replace


  • 0

Reporting odd ratios and Chi2 with asdoc

Category:asdoc,Blog

Richard Makurumidze has asked:It seems asdoc does not work with the chi (chi -square) and or (odds ratio) in logistic regression. Is this correct or am making some error?

Richard is referring to the nest option of asdoc that creates the nested regression tables. Without the nest option, asdoc produces detailed regression tables and exports odds ratio as a default option. However, with nest option, users must explicitly declare that they are interested in the odd ratios. This declaration is done using the eform option. In the following examples, I show how to get odd ratios with both the detailed and the nested regressions.


Reporting the odd ratios

We shall use the example data that is available on the Stata web server. The data can be downloaded by typing the following in the Stata command window.

 
webuse lbw, clear


Getting odd ratios in the detailed regression tables

 asdoc logistic low age lwt i.race smoke ptl ht ui, replace 



Getting odd ratios in the nested regression tables

 asdoc logistic low age lwt i.race smoke ptl ht ui, replace nest eform

This is how the output looks like.


Reporting the Chi2

Richard’s second querry is related to reporting the Chi2 test value. Since asdoc tries to find the r-squared values in regression commands, it is possible that this value is not available in some commands such as in the case of the logisitc regression. Users can add additional statistics to the regression table by using the option add(). There is a detailed discussion on this option in the asdoc help file, which we can access by typing:

help asdoc

Below, I show how we can use this option for reporting the Chi2 test value. Please note that Stata regression commands leaves behind several statistics in the e() macro which we can report with asdoc.

 asdoc logistic low age lwt i.race smoke  ui, replace nest add(Chi2, `e(chi2)')

* Add another regression

asdoc logistic low age lwt i.race smoke ptl ht ui, nest add(Chi2, `e(chi2)')

Explanation

Option add() has two elements – the text Chi2 and the macro `e(chi2)’. These two elements are separated by the comma. This is how option add works. The inputs of option add() should be added in pairs of two, each one separated by a comma.


  • 0

Reshape data in Stata – An easy to understand tutorial

Category:Blog,Uncategorized Tags : 

From wide to long format

Suppose we have the data in the following format

 +-------------------------------------------------------+
 | id   sex   inc80   inc81   inc82   ue80   ue81   ue82 |
 |-------------------------------------------------------|
 |  1     0    5000    5500    6000      0      1      0 |
 |  2     1    2000    2200    3300      1      0      0 |
 |  3     0    3000    2000    1000      0      0      1 |
 +-------------------------------------------------------+

The above structure is known as the wide format. If we wish to convert it to a long format, such as the one given below,

 +-----------------------------+  
| id year sex inc ue |
|-----------------------------|
| 1 80 0 5000 0 |
| 1 81 0 5500 1 |
| 1 82 0 6000 0 |
| 2 80 1 2000 1 |
| 2 81 1 2200 0 |
|-----------------------------|
| 2 82 1 3300 0 |
| 3 80 0 3000 0 |
| 3 81 0 2000 0 |
| 3 82 0 1000 1 |
+-----------------------------+

We shall just type

reshape long inc ue, i(id) j(year)

Explanation

Since we need to convert the data from a wide format to a long format, this is why the command that we wrote was reshape long. After that, we have to specify the names of the variables which are in the wide format. In our dataset, there are 2 variables which are INC and UE. Both of these variables have a numeric part. That numeric part is what we call the variable J. We specify this J variable in the option j(new variable). In our dataset, there is no variable with the name year, however, we wrote the option j(year) so that a new variable is created for the numeric values of 80, 81, and 82. We also specified option i(id), where option i needs an existing variable that is a unique panel identifier.

To practice the above yourself, here is the source data and code.

use http://www.stata-press.com/data/r15/reshape1
list
reshape long inc ue, i(id) j(year)
list


Reshape long to wide

Continuing from the previous example, we can reshape the data back to wide format by

reshape wide inc ue, i(id) j(year)

email-subscribers-form id=”{form-id}”


  • 0

asdoc version 2.3.3 : New Features

Category:asdoc,Stata Programs Tags : 

Version 2.3.3.2, dated Feb 23, 2019, of asdoc bring significant improvements to existing routines and introduces few new features. Details are given below. If you have not used asdoc previously, I would encourage you to read this half page quick start to asdoc.


New Features


1.Font style

2. Formatting the header row and header column

3. Revamped the tabulation commands

4. Revamped the table command

5. Extending the detailed regression tables [ Read further details here]

  • 5.1 Added confidence intervals to the detailed regression tables
  • 5.2 Added an option for customizing the significance starts
  • 5.3 Added an option for suppressing significance stars
  • 5.4 Added an option for suppressing confidence intervals

6. Adding support for macOS

6. Improving the output from proportion command

7. Support added for logistic family of regressions

8. Improving table outputs of non-standard outputs i.e. multilevel models

9. eform() option added to nested tables

Detailed discussion and examples are provided in the help file accompanying the new version of asdoc. However, I would like to discuss the first two features in some details below.


1. Setting font style

The default font style is Garamond in the latest version of asdoc. Option font(font_name) can be used to change the font face to any desired font style. In the brackets, we have to write the full name of the font, which is currently installed in the operating system. For example, to set the font face to Arial, we shall type: 

font(Arial)

To produce summary statistics in Times New Roman font, let us use the auto dataset from the system directory

sysuse auto, clear
asdoc sum, font(Times New Roman) replace

Please note that the font() option can be used only at the start of the document. Therefore, it cannot change from table to table when using option append of asdoc.


2. Formatting table headers

In this new version of asdoc, we can easily pass RTF formatting control words to the header row and header columns of the ouput tables. For this purpose, option fhr() is used to format the row headers, i.e. the data given in the first column of each row. Similarly, option fhc() is used to format the column headers, i.e., the data given in the top cells of each column. Both the fhr() and fhc() will pass RTF control words to the final document. See the
following examples.

------------------------------------------------------------
Objective                                    Code to use
------------------------------------------------------------
Format column headers as bold               fhc(\b)
Format column headers as italic             fhc(\i)
Format column headers as bold and italic    fhc(\b \i)
Format row headers as bold                  fhr(\b)
Format row headers as italic                fhr(\b)
Format row headers as bold and italic       fhr(\b \i)
------------------------------------------------------------

So to make a table of descriptive statistics with column headers in bold and row headers in italic font, the code would be:

sysuse auto, clear
asdoc sum, fhr(\i) fhc(\b) replace