This collection of programs was put together by
Nader Hafzalla for the benefit of all.

Please remember him
with the love and good humor
that he shared with all of us.


Accounting/Finance Research SAS Programs


Note:  This site was originally created and hosted on Nader's personal website here at the University of Michigan. However, as time elapsed, that account expired, and the contents of this site were taken offline. I am rehosting these contents, in their original form (with the exception of this note), as they appeared on Nader's website, as a service to those who find these contents useful. If anyone finds this objectionable, please let me know , and I will be happy to remove this site. 

Disclaimer:  The users and owners of this site provide no assurance as to the accuracy of these programs.  This site is merely a tool to share various codes that replicate accounting and finance research studies. 

Please take the time to understand each program before running it to verify that it is performing the tasks you desire as well as it is error-free.

 

Programs that replicate Accounting/Finance studies:

1) Skinner and Sloan (2001) I/B/E/S - Compustat merging (doesn't include CRSP program) - ibes.comp.sas

Description:

This file pulls I/B/E/S summary forecasts and calculates errors as in Skinner and Sloan (2001).  It then merges them to Compustat by permnos.  See the I/B/E/S manual for the dataset name if you would like to use the unadjusted I/B/E/S databases.

 

2) Fama and French (1997) Industry classification code - ff_industry.sas

Description: 

This file takes Compustat 4-digit sic and defines the industries according to Fama and French (1997). See also the word document attachment that you could use as the appendix in your paper.  The program uses PROC FORMAT so that the numeric nature of the SIC code is retained, while produces both short and long formats of industry description and classification.  Thanks to Xuesong Hu.

 

3) I/B/E/S - Compustat - CRSP merging program - ibes.comp.crsp.sas

Description:

This file merges I/B/E/S, Compustat and CRSP data.  Thanks to Steve Stubben.

 

4) Import an Excel File into SAS - excel.sas

Description:

This file uses proc import to read an excel file into SAS.  It then codes the quarters into t = -2 to t = 6 while giving them labels.  See for example Erickson and Wang (1999) for the quarter coding.  This is especially useful when hand collecting data in excel.

 

5) White Standard Errors and Breusch-Pagan test - white.sas

Description:

This file contains two ways to do the white standard errors and Breusch-Pagan test (Scroll all the way to the bottom of the program to see the easy way).  The file replicates Verbeek's A guide to Modern Econometrics table 4.5.  As per page 104 in Verbeek, if wj is zero we end up with just the White covariance matrix.  Thus, setting the kernel to zero lags accomplishes this.   See the SAS manual before running this to make sure you understand the kernel command.  Thanks to Peter Demerjian.

 

6) Regression tables - reg.sas

Description:

This file contains a program that will automatically put your regression results in an excel file.  BE VERY CAREFUL.  DON'T JUST RUN THIS AND PUT IT IN YOUR PAPER.  MAKE SURE YOU KNOW WHAT THE PROGRAM IS SPITTING OUT.  This can also easily be made into a macro.

 

7) Returns Program coming soon.

8) Industry regression - firmreg.sas

Description:

This program estimates regression coefficients for all firms in an industry group except firm i, and then applies the coefficients to firm i to obtain a predicted value. industry groups are 1 to 599 and called groupnum. Within each industry group there are nobservations which are defined as dumb1. The program first goes within each industry group (1-599) and then iterates the regression dumb1 times. The first part of the program is the macro, lower down is where the data is fed in and where the data is spit out... feeding file is currently called feedall.sas7bdat and spit out file is currently called uerefpred.sas7bdat.  Thanks to Sarah McVay.

9) Fama-MacBeth estimation of Coefficients and Standard Errors - fmJ.ado and fmwJ.ado (2 STATA programs)

Description:

Stata programs to perform Fama-MacBeth (F-M) style regressions.  fmJ.ado is a generic computation of F-M coefficients and fmwJ.ado weights years by the # of observation/year.  Thanks to Mitchell Petersen and Judson Caskey.

10) Mishkin (1983) - mishkin.sas 

Description:

This program employs the framework developed by Mishkin (1983) to test rational expectations hypotheses as applied by Sloan (1996).  Thanks to Weili Ge.

11) Shumway and Altman Scores - bankrupt.sas

Description:

This program calculates the Shumway (2001), Altman Z-score (1968) and the Ohlson (1980) bankruptcy scores.  The Shumway coefficients are the same as in his paper.  The Altman Z-score's coefficients are based on Hillegeist, Keating, Cram and Lundstedt (2004) hazard model estimations.  Note that the original Altman score was not a hazard model score (so a high Z-score was a good thing).  All scores here are hazard model predictions as in Shumway (2001) so the higher the score, the higher the firm is distressed (probability of bankruptcy).  Thanks to Judson Caskey and Peter Demerjian.

Helpful Macros:

1) Permanently use your macros without rewriting them - macro.sas

Description: 

This file will allow you to run the macros from this website without having to download the code nor place it in the main body of your SAS program codes.  Thanks to Ryan Ball.

 

2) Trim or Winsorize macro.sas - Windsorize_Macro.sas

Description: 

This file contains a macro that will winsorize or truncate any dataset and variables you specify. Thanks to Bill Mayew for the submission.  Another submission by the original author of the macor - thanks Steve Stubben here.

 

3) Correlation table Macro - Correlation_Table_Generation_Macro.sas

Description: 

This file contains a macro that will generate Pearson and Spearman correlation tables to any dataset and variables you specify. Thanks to Bill Mayew.  Another submission by the original author of the macor - thanks Steve Stubben here.

 

4) Industry Generating Macro - Industries_macro.sas

Description: 

This file contains a macro that will divide SIC codes into 22 industries with label.  Note that this can be combined with Fama and French above. Thanks to Steve Stubben and Bill Mayew.

 

5) Fama-MacBeth Macro - Fama_MacBeth_Macro.sas

Description: 

This file contains a macro that performs Fama-MacBeth style coefficients from OLS regressions. It summarizes regression results over a number of groups, provides mean estimate, #positive, mean t-stat, #sig., mean n and adjusted R2, Z1, Z2, and Fama-MacBeth t-statistic. "prnt1" prints coefficient estimates. "prnt2" prints R2's and sample sizes.  Just set option to 'yes' to print them, anything else doesn't.  "minobs" allows you to require a minimum # of observations per regression.  Thanks to Steve Stubben and Bill Mayew.

 

6) Abbreviated regression outputs - Abbreviated_regression_output_macro.sas

Description: 

This file contains a macro that will generate abbreviated regression outputs.  The outputs will only contain coefficient estimates, t-stats, number of observations, and adjusted R2. "dset" means dataset. "yvar" is the dependent variable. "xvars" are the independent variables just list them out with spaces.  Thanks to Steve Stubben and Bill Mayew.

 

7) Descriptive Statistics by Group - descriptives.sas

Description: 

This file contains a macro that will generate descriptive statistics by group for datasets and variables you specify.  Thanks to Steve Stubben.

 

8) Dummy variable - dummy.sas

Description: 

This file contains a macro that will generate dummy variables for any dataset or variables you specify (i.e. industries or years).  Thanks to Steve Stubben.

 

Helpful Links and Documentation:

1) If you don't have access to the CRSP/Compustat merged database, you can recreate the actual date variable "fqenddt" using this code (comp_dates.sas) to get the actual year and month.  It also includes the Compustat annual year fix.

 

2) Helpful pdf file on how to work with dates in SAS - Thanks to Bill Mayew.

 

3) Some helpful STATA and SAS codes about Standard errors can be found on Professor Mitchell Petersen's page http://www.kellogg.northwestern.edu/faculty/petersen/htm/papers/se/se_programming.htm

 

Disclaimer:  The users and owners of this site provide no assurance as to the accuracy of these programs.  This site is merely a tool to share various codes that replicate accounting and finance research studies. 

*The site owners thank individuals for their submission and not necessarily for their creation of the code or documents submitted.

 

 

 


Nader M. Hafzalla
University of Michigan

Copyright 2005. All rights reserved.
Revised: 06/13/06.