Skip to content

Instantly share code, notes, and snippets.

View iangow's full-sized avatar
🏠
Working from home

Ian Gow iangow

🏠
Working from home
View GitHub Profile
@iangow
iangow / sql_server_odbc.md
Created February 24, 2025 18:56
Setting up the ODBC driver on MacOS.

Setting up the ODBC driver on MacOS

The following instructions improve on those here by avoiding the need to:

a. Compile the Homebrew binary itself b. Set the path for the Homebrew binary

Steps

  1. Install HomeBrew using the .pkg file available here.
@iangow
iangow / rets_all_tables.sas
Created January 17, 2025 15:54
SAS code for making `rets_all` without views.
libname home '.';
PROC SQL;
CREATE TABLE crsp_dates AS
SELECT date, intnx('MONTH', date, 0, 'BEGINNING') AS month format=yymmdd10.
FROM crsp.msi
ORDER BY date;
QUIT;
DATA crsp_dates;
@iangow
iangow / rets_all_views.sas
Last active January 17, 2025 15:41
SAS code for making `rets_all` using views
libname home '.';
PROC SQL;
CREATE TABLE crsp_dates AS
SELECT date, intnx('MONTH', date, 0, 'BEGINNING') AS month format=yymmdd10.
FROM crsp.msi
ORDER BY date;
QUIT;
DATA crsp_dates;
@iangow
iangow / walker_stats.R
Created September 19, 2024 07:41
Code to produce AUC stats from Walker's data
library(farr)
library(tidyverse)
original <- read_csv("~/Downloads/WalkerDataCodeMar2021/original.csv")
original |>
group_by(fyear) |>
summarize(auc = auc(prob, aaer), .groups = "drop") |>
mutate(avg_auc = mean(auc))
@iangow
iangow / other_packages.R
Created September 19, 2024 04:59
Other packages
install.packages(c("formatR", "markdown", "tinytex", "downlit", "xml2"))
@iangow
iangow / pq_to_pg.R
Last active September 19, 2024 00:02
Code to get a parquet file into PostgreSQL.
library(dplyr, warn.conflicts = FALSE)
library(DBI)
db <- dbConnect(duckdb::duckdb())
dbExecute(db, "ATTACH '' AS pg (TYPE POSTGRES);")
dbExecute(db, "COPY pg.crsp.dsf FROM '/Users/iangow/Library/CloudStorage/Dropbox/pq_data/crsp/dsf.parquet'")
create_view <- function(conn, table, schema = "",
@iangow
iangow / get_players.R
Created September 6, 2024 04:25
Code to get player lists from AFL tables
library(httr2) # request(), req_*(), resp_body_html()
library(rvest) # html_elements(), html_table()
library(tidyverse)
extract_team_ids <- function(link_text) {
matches <- str_match(link_text, '<a href="teams/(.*)_idx.html">(.*)</a>')
team_id <- matches[, 2]
team_name <- matches[, 3]
tibble(team_id, team_name)
}
@iangow
iangow / nnhs.md
Created July 3, 2024 15:19
Destinations
library(tidyverse)
library(DBI)
library(googlesheets4)

options(gargle_oauth_email = TRUE)

gs_2024 <- as_sheets_id("1Qymhw_LGN1Z00ip_qswa29yPeZzWvTymD-u-lMY8b-A")

nnhs_2024 &lt;- read_sheet(gs_2024, na = c("", "N/A"))
@iangow
iangow / summ_table.md
Last active June 19, 2024 08:46
Illustration of a function to make summary tables with totals
library(tidyverse)

regions <- c("USA", "Australia", "China")
years <- 2017:2023L
markets <- letters[1:4]

nn <- 1000
sample_n <- function(var, n = nn) {
  var <- rlang::ensym(var)
@iangow
iangow / port_sorts.md
Created June 9, 2024 21:32
Another version of `port_sorts.qmd`.

Fast Portfolio Sorts Revisited

library(tidyverse)
library(dtplyr)
library(data.table)
library(bench)
library(DBI)