Clean up TRACE Enhanced dataset

WRDS provides an excellent manual (link) and SAS code (link) for cleaning up the raw TRACE Enhanced bond transaction data, primarily based on the work done by Dick‐Nielsen, Jens, How to Clean Enhanced TRACE Data (December 3, 2014). Available at … Continue reading

Posted in SAS | Leave a comment

Stata command to perform Chow test

A Chow test is simply a test of whether the coefficients estimated over one group of the data are equal to the coefficients estimated over another. I find two useful articles from Stata’s official website: Can you explain Chow tests? … Continue reading

Posted in Stata | 4 Comments

SAS macro to count the number of analysts following a firm

This macro is used to count the number of analysts who followed a specific firm. Although this is a commonly used measure in literature, prior studies often give a vague description on what they do. The question is—what does “analysts … Continue reading

Posted in SAS | Leave a comment

The art of regular expression

Regular expression is a powerful tool to do text search. It is the foundation of a lot of textual analysis research, though today’s textual analysis in computer science has gone far beyond text search. Regular expression operations are programming language … Continue reading

Posted in Python | 1 Comment

Stata commands to change variable names or values of string variables to all lowercase

Stata is a case-sensitive application. Sometimes this will cause a trouble. So, we may want to change variable names or values of variables to all lowercase before we start processing data. This post gives a fast way to do this. … Continue reading

Posted in Stata | 2 Comments

Common commands to deal with date in Stata

egen compdatadate=eom(fiscalmonth fiscalyear) format compdatadate %td To be continued …

Posted in Stata | Leave a comment

Stata command to order tabulation result with only top values shown

tabulate varname command is handy in Stata, but sometimes it returns a too long result, if varname contains too many unique values. The third-party command, groups, will solve the problem by showing top values only. Please use ssc install groups … Continue reading

Posted in Stata | Leave a comment

Empower “and” and “or” in IF statement in Stata

Stata is a little bit awkward when using and and or in if statement, compared to SAS. For example: In SAS, we can write if 2001 <= fyear <= 2010. But in Stata, we usually write: if fyear >= 2001 … Continue reading

Posted in Stata | Leave a comment

Display mean and median test results in Stata

Sometimes we may want to produce the following table to compare the mean and median of two groups: First of all, please refer to this post to see Stata commands to test equality of mean and median. However, it is … Continue reading

Posted in Stata | 9 Comments

Stata commands to do Heckman two steps

We often see Heckman’s two steps in accounting literature. But how to do it in Stata? The two steps refer to the following two regressions: Outcome equation: y = X × b1 + u1 Selection equation: Dummy = Z × … Continue reading

Posted in Stata | 2 Comments