Skip to content

Instantly share code, notes, and snippets.

View mgao6767's full-sized avatar
😀

Adrian Gao mgao6767

😀
View GitHub Profile
Running 0.00 km ░░░░░░░░░░░░░░░░░░░ 0.00/h
Cycling 1264.55 km ███████████████████ 28.76/h
Last month 236.90 km 21 achievements 8:46h
@mgao6767
mgao6767 / Calculate Institutional Ownership, Concentration, and Breadth Ratios.sas
Created January 24, 2019 05:19
Calculate Institutional Ownership, Concentration, and Breadth Ratios
/* ********************************************************************************* */
/* ************** W R D S R E S E A R C H A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary : Calculate Institutional Ownership, Concentration, and Breadth Ratios */
/* Date : May 18, 2009 */
/* Author : Luis Palacios, Rabih Moussawi, and Denys Glushkov */
/* Variables : - INPUT : Thomson-Reuters 13F Data (TR-13F) S34TYPE3 Holdings data */
/* S34TYPE1 data for FDATE and RDATE variables */
/* - OUTPUT: IO_TimeSeries dataset with IO variables for common stocks */
/* ********************************************************************************* */
@mgao6767
mgao6767 / Shumway.sas
Last active April 5, 2024 19:32
Original SAS code in Bharath and Shumway (2008 RFS) for Merton DD. See comment below for some minor issues.
/* This SAS program calculates the distance to default using the KMV-Merton model
with the iterated estimate of the volatility of firm value. Many of the results
of Bharath and Shumway (2004) are generated by this program. The program
requires the data described below, and it generates a permanent sas data file
called ssd.kmv which contains distances to default. The program calculates
monthly distances to default every year from 1980 to 1990 as it is currently written*/
/* This program requires two datasets:
ssd.comp, which contains monthly observations taken from the quarterly compustat
@mgao6767
mgao6767 / discretionary accruals.sas
Last active March 28, 2024 00:23
Compute 5 measures of firm-year discretionary accruals.
/* Use Jackknife method to compute discretionary accruals */
/* see https://mingze-gao.com/posts/compute-jackknife-coefficient-estimates-in-sas/ */
/* UseHribarCollinsTotalAccruals:
- true: use Hribar-Collins Cashflow Total Accruals
- false: use normal method */
%let UseHribarCollinsTotalAccruals = false;
/* Include %array and %do_over */
filename do_over url "https://mingze-gao.com/utils/do_over.sas";
@mgao6767
mgao6767 / common financial ratios.sas
Created January 27, 2019 04:24
Computes a broad range of financial ratios at both firm and the industry level using Fama-French industry classification.
/* ********************************************************************************* */
/* ******************** W R D S R E S E A R C H M A C R O S ******************** */
/* ********************************************************************************* */
/* WRDS Macro: INDRATIOS */
/* Summary : Computes a broad range of financial ratios aggregated at */
/* the industry level using Fama-French industry classification */
/* Date : Apr, 2009 */
/* Modified : Nov, 2010 */
/* Author : Denys Glushkov, WRDS */
/* Parameters: */
options mprint;
%macro lowcase(dsn);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nvars));
%put #
data &dsn;
set &dsn(rename=(
%do i = 1 %to #
/*function of varname returns the name of a SAS data set variable*/
%let var&i=%sysfunc(varname(&dsid,&i));
@mgao6767
mgao6767 / Tobin's Q and Altman Z Score for Compustat Companies.sas
Created January 22, 2019 14:53
Tobin's Q and Altman Z Score for Compustat Companies
/* ********************************************************************************* */
/* ************** W R D S R E S E A R C H A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary : Tobin's Q and Altman Z Score for Compustat Companies */
/* Date : August 24, 2011 */
/* Author : Rabih Moussawi */
/* Variables : - Computes proxies for Tobin's Q and Altman Z using Financial Ratios */
/* - Proxy for Age of company using number of years with available data */
/* - Adds delisting reason and delisting date information */
/* ********************************************************************************* */
@mgao6767
mgao6767 / hist_hq_state_zipcode_from_8k.py
Created March 19, 2023 22:42
Script to get firm historical HQ state and zipcode from 8K filings. See https://mingze-gao.com/posts/firm-historical-headquarter-state-from-10k/
import sqlite3, sys, os, pathlib, logging
import pandas as pd
# fmt: off
states = [ 'AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA',
'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME',
'MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM',
'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX',
'UT', 'VA', 'VT', 'WA', 'WI', 'WV', 'WY']
# fmt: on
@mgao6767
mgao6767 / Industry Classification.sas
Created January 27, 2019 00:10
Constructs 4 different industry classifications based on SIC, NAICS, GICS and Fama-French industry classifications
/* ********************************************************************************* */
/* ******************** W R D S R E S E A R C H M A C R O S ******************** */
/* ********************************************************************************* */
/* WRDS Macro: INDCLASS */
/* Summary : Constructs 4 different industry classifications based on SIC, NAICS, */
/* GICS and Fama-French industry classifications */
/* */
/* Date : Feb, 2010 */
/* Author : Denys Glushkov, WRDS */
/* Variables : */
@mgao6767
mgao6767 / DGTW (1997) Return.sas
Created January 24, 2019 05:27
Calcualte Daniel, Grinblatt, Titman, and Wermers (1997) Excess Return
/* ********************************************************************************* */
/* ************** W R D S R E S E A R C H A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary : Construct Daniel Grinblatt Titman and Wermers(1997) Benchmarks */
/* Date : January, 2011 */
/* Author : Rabih Moussawi and Gjergji Cici */
/* Variables : - BEGDATE: Sample Start Date */
/* - ENDDATE: Sample End Date */
/* ********************************************************************************* */