Skip to content

Instantly share code, notes, and snippets.

View edwinhu's full-sized avatar

Edwin Hu edwinhu

View GitHub Profile
@edwinhu
edwinhu / sp500.sas
Created August 5, 2021 20:44
S&P 500 Constituents from CRSP
proc sql;
create table out.sp500 as
select distinct a.permno, a.date,
a.permco,
c.ncusip as CUSIP,
c.exchcd,
c.tsymbol,
c.shrcls
from crsp.msf a,
@edwinhu
edwinhu / adv2.sh
Last active April 22, 2020 02:44
get and section adv2 brochure item 11s
# curl to get all of the zip files of PDFs
curl https://www.sec.gov/foia/docs/adv/formadv_part2_[1-112].zip -o "/data/hue/adv2/formadv_part2_#1.zip"
# list files
unzip -l formadv_part2_1.zip
# awk extract the part I care about
unzip -p formadv_part2_100.zip 103705_325511_1_20200131.pdf | pdftotext - - | awk 'BEGIN{IGNORECASE=1};/^item 11/,/^item 12/'
# build an index
for f in *.zip
@edwinhu
edwinhu / extract.R
Last active September 30, 2019 22:12
extract functions for bife and feglm
extract.bife <- function(model) {
s <- summary(model)
names <- rownames(s$coefmat_beta)
co <- s$coef[, 1]
se <- s$coef[, 2]
tstat <- s$coef[, 3]
pval <- s$coef[, 4]
aic <- s$AIC
bic <- s$BIC
@edwinhu
edwinhu / ALL_COMP_NAMES.sas
Created September 10, 2018 20:37
Get all COMPUSTAT names
/* The goal of this code is to identify all gvkeys in Compustat,
and to estimate approximate start/end dates for these gvkeys */
proc sql;
/* All NA Companies */
create table comp_name_range as
select *
from
/* Company files contains all NA gvkeys */
(select gvkey, ein, cik,
UPCASE(COMPBL(PRXCHANGE('s/[\W_]+/ /',-1,conm))) as conm,
@edwinhu
edwinhu / GET_FFDATA.SAS
Last active August 29, 2015 13:57
Macro to download and parse the Fama French Factors
/*******************READ ME*********************************************
* - Macro to download and parse the Fama French Factors -
*
* SAS VERSION: 9.4.0
* DATE: 2014-03-06
* AUTHOR: eddyhu at the gmails
*
****************END OF READ ME******************************************/
%macro GET_FFDATA(file=F-F_Research_Data_Factors,
dsetout=ff_factors,
@edwinhu
edwinhu / HELMERT.sas
Last active August 29, 2015 13:56
Macro to [Helmert transform](http://en.wikipedia.org/wiki/Helmert_transformation) (forward mean-difference) panel data
/*******************READ ME*********************************************
* - Macro to Helmert transform (forward mean-difference) panel data -
*
* SAS VERSION: 9.4.0
* DATE: 2013-05-05
* AUTHOR: eddyhu at the gmails
*
****************END OF READ ME******************************************/
%macro HELMERT(dsetin = &syslast.,
@edwinhu
edwinhu / header.ipynb
Last active August 29, 2015 13:56
My IPython Header
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.