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 / get_libraries.R
Created February 8, 2024 21:55
Small script to identify needed packages
library(stringr)
library(dplyr)
path = getwd()
file_list <-
tibble(full_path = list.files(path, full.names = TRUE)) |>
filter(str_detect(full_path, "\\.(qmd)$"))
get_libraries <- function(file) {
@iangow
iangow / basu_scopus.csv
Created January 27, 2024 17:51
Scopus data on cites for Basu (1997)
We can't make this file beautiful and searchable because it's too large.
Authors,Author(s) ID,Title,Year,Source title,Volume,Issue,Art. No.,Page start,Page end,Page count,Cited by,DOI,Link,Document Type,Publication Stage,Open Access,Source,EID
"Biehl, H., Bleibtreu, C., Stefani, U.","58793833200;57200334948;54582932500;","The real effects of financial reporting: Evidence and suggestions for future research",2024,"Journal of International Accounting, Auditing and Taxation","54",,"100594","","",,,"10.1016/j.intaccaudtax.2023.100594","https://www.scopus.com/inward/record.uri?eid=2-s2.0-85181527482&doi=10.1016%2fj.intaccaudtax.2023.100594&partnerID=40&md5=34a90aa58abcb7c16af7d1555a2b3bb4",Article,"Final","All Open Access, Hybrid Gold",Scopus,2-s2.0-85181527482
"Collins, D.W., Nguyen, N.Q., Nguyen, T.T.","7403253898;57219198785;57212090956;","Manager sentiment and conditional conservatism",2024,"Journal of Business Finance and Accounting",,,,"","",,,"10.1111/jbfa.12780","https://www.scopus.com/inward/record.uri?eid=2-s2.0-85182461797&doi=10.1111%2fjbfa.12780&partnerID=40&md5=98353953fa
@iangow
iangow / vic_plot.R
Created January 15, 2024 21:24
Code for some plot about Victoria
library(tidyverse)
library(readabs)
raw_abs <- read_abs("5601.0")
candidate_series <-
raw_abs %>%
filter(str_detect(series, "Owner occupier"),
str_detect(series, "External refinancing"),
str_detect(series, "New loan commitments"),
@iangow
iangow / make_restate.md
Created January 13, 2024 16:39
R version of SAS code from Dan Taylor
Sys.setenv(PGHOST= "wrds-pgdata.wharton.upenn.edu",
           PGPORT= 9737L,
           PGDATABASE = "wrds",
           PGUSER = "iangow")

library(dplyr, warn.conflicts = FALSE)
library(DBI)

db <- dbConnect(RPostgres::Postgres())
@iangow
iangow / rows_append.md
Created January 13, 2024 16:35
Illustrate `rows_append()`.
library(dplyr, warn.conflicts = FALSE)
library(DBI)
set.seed(1)
make_dat <- function(nrow=1, ncol=5) {
  df <- 
    cbind.data.frame(name=stringi::stri_rand_strings(n=nrow, length=3), 
                     matrix(data=sample(c(T, F), nrow*ncol, T), ncol=ncol))
  names(df) <- c("name", paste0("v_", 1:ncol))
  df
@iangow
iangow / fruit_baskets.md
Last active January 13, 2024 14:59
Benchmarking approaches to summing prices for fruit baskets.

See StackOverflow for the original question.

library(data.table)
library(dplyr, warn.conflicts = FALSE)
library(tidyr)
library(DBI)

# Make the data
fruits_tbl <- tibble(fruit_name = c('orange', 'apple',
@iangow
iangow / polars_bench.R
Created January 10, 2024 14:51
Benchmark of `rpolars`.
install.packages(
'tidypolars',
repos = c('https://etiennebacher.r-universe.dev', getOption("repos"))
)
library(tidypolars)
library(polars)
library(collapse, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(DBI)
@iangow
iangow / camp_participants.R
Created January 3, 2024 15:59
Code to scrape data from a PDF
library(dplyr, warn.conflicts = FALSE)
library(tidyr)
library(readr) # For read_lines(), read_fwf(), etc.
library(stringr) # For str_c(), str_detect()
library(pdftools) # For pdf_text()
library(lubridate) # For ymd()
library(ggplot2)
url <- paste0("https://aaahq.org/portals/0/documents/meetings/2023/RC/",
"2023%20Rookie%20Camp%20Alphabetical%20Presentation%20Schedule.pdf")
@iangow
iangow / penguins_ibis.ipynb
Created January 2, 2024 19:03
Tidy Data Manipulation: dplyr vs polars using Ibis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iangow
iangow / regr_slope.R
Created December 30, 2023 15:48
Code to generate fake return data and estimate rolling betas.
library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)
library(DBI)
set.seed(2023)
n <- 100
betas <- tibble(id = 1:n, beta = runif(n, min = 0.7, max = 1.3))
start_date <- as.Date("1980-01-01")
end_date <- as.Date("2023-01-01")