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 / seattle_benchmark.R
Created November 29, 2023 11:42
Benchmarks based on Seattle data
library(DBI)
library(dplyr, warn.conflicts = FALSE)
library(farr) # for load_parquet()
library(arrow)
db <- dbConnect(duckdb::duckdb(),
dbdir = "~/Downloads/seattle.duckdb",
read_only = TRUE)
dbListTables(db)
@iangow
iangow / duckdb_dsf.md
Created November 24, 2023 20:35
Benchmarking DuckDB with parquet version of crsp.dsf.
library(ggplot2)
library(DBI)
library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)

now <- Sys.time()
conn <- dbConnect(duckdb::duckdb())

file_path <- "~/data/crsp/dsf.parquet"
@iangow
iangow / pg_to_parquet.R
Created November 24, 2023 17:22
Code to get data from WRDS as parquet
library(dplyr, warn.conflicts = FALSE)
library(DBI)
Sys.setenv(PGHOST = "wrds-pgdata.wharton.upenn.edu",
PGDATABASE = "wrds",
PGUSER = "iangow",
PGPORT = 9737)
db <- dbConnect(duckdb::duckdb())
@iangow
iangow / ssrn_downloads.R
Created June 14, 2023 18:39
Code to compare SSRN downloads from ranking files from two dates
library(tidyverse)
library(rvest, warn.conflicts = FALSE)
css_selector <- "#main-table > tbody:nth-child(6)"
read_df <- function(page, prefix = "pre_") {
url <- paste0("~/Desktop/SSRN/", prefix, page, ".html")
html <- read_html(url)
df <-
html |>
@iangow
iangow / make_betas_sqlite.R
Created May 10, 2023 22:15
Code to calculate betas using SQLite and (mostly) dplyr
library(tidyverse)
library(DBI)
library(slider)
library(furrr)
tidy_finance <- dbConnect(
RSQLite::SQLite(),
"data/tidy_finance.sqlite",
extended_types = TRUE)
@iangow
iangow / make_beta_duckdb.R
Created May 10, 2023 22:14
Code to calculate betas using DuckDB
library(tidyverse)
library(DBI)
library(dbplyr)
ddb <- dbConnect(
duckdb::duckdb(),
"data/tidy_finance.duckdb",
read_only = FALSE
)
@iangow
iangow / refi.md
Last active April 11, 2023 23:40
Refinancing plot
library(tidyverse)
library(readabs)
#> Environment variable 'R_READABS_PATH' is unset. Downloaded files will be saved in a temporary directory.
#> You can set 'R_READABS_PATH' at any time. To set it for the rest of this session, use
#>  Sys.setenv(R_READABS_PATH = <path>)

raw_abs <- read_abs("5601.0")
#> Finding URLs for tables corresponding to ABS catalogue 5601.0
#> Attempting to download files from catalogue 5601.0, Lending Indicators
@iangow
iangow / lln.R
Last active February 28, 2023 04:04
Code to demonstrate LLN graphically
library(tidyverse)
hgt_mean <- 165
hgt_sd <- 8
get_hgt_sample <- function(n) {
rnorm(n, mean = hgt_mean, sd = hgt_sd)
}
get_hgt_samples <- function(n_samples, n) {

Cosmic habituation

The following simulation examines the phenomenon of cosmic habituation discussed in a New Yorker article, "The Truth Wears Off", and examined in Thinking Clearly with Data.

I conjecture that this is driven by underpowered initial studies, which are only observed if "statistically significant" results are found. Follow-up studies tend to have larger samples and find smaller apparent effects.

library(tidyverse)
@iangow
iangow / update_postgres.sh
Last active November 9, 2022 13:38
Script to update Postgres
mkdir /Volumes/OWC1/pg_data15
/Applications/Postgres.app/Contents/Versions/15/bin/initdb -D /Volumes/OWC1/pg_data15 \
--encoding=UTF-8 --locale=en_US.UTF-8 -U postgres
/Applications/Postgres.app/Contents/Versions/15/bin/pg_upgrade \
-b /Applications/Postgres.app/Contents/Versions/14/bin \
-B /Applications/Postgres.app/Contents/Versions/15/bin \
-d /Volumes/OWC1/pg_data14 -D /Volumes/OWC1/pg_data15 -v