Categories
 Data (8)
 Learning Resources (8)
 Python (8)
 SAS (14)
 Stata (23)
 Uncategorized (1)

Recent Posts
Recent Comments
 Anja on Use Python to calculate the tone of financial articles
 Kai Chen on Display mean and median test results in Stata
 R Zhang on Display mean and median test results in Stata
 Frederic on Stata command to create FamaFrench industry classifications based on SIC codes
 Khin Phyo Hlaing on Stata command to create FamaFrench industry classifications based on SIC codes
Archives
Meta
Author Archives: Kai Chen
Use Stata to do propensity score matching (PSM)
Most propensity score matching (PSM) examples are using crosssectional data instead of panel data. However, accounting research often uses panel data (i.e., observations with two subscripts i and t, e.g. firmyears) in a differenceindifferences (DID) research design, so that there are … Continue reading
Posted in Stata
Leave a comment
Export a SAS dataset to Stata with all variable names converted to lowercase
I use both SAS and Stata and often need to transfer data between the two. SAS is casesensitive and Stata is not. I always prefer working with lowercase variable names in Stata. The following code is used to export a … Continue reading
Posted in SAS
Leave a comment
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
5 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
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
Stata commands to change variable names or values of string variables to all lowercase
Stata is a casesensitive 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 thirdparty 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