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 / 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)
@iangow
iangow / port_sorts.md
Created June 9, 2024 13:35
DuckDB/parquet version of Tidy Finance benchmark.

Fast Portfolio Sorts with DuckDB/parquet

Load a few packages. Here farr provides system_time().

library(tidyverse)
library(DBI)
library(farr)
@iangow
iangow / fig-alt-code.qmd
Created April 26, 2024 18:21
Code to produce a Word document detailing alternative text
---
title: "Alternative text for figures"
author: Ian D. Gow
date: 2024-04-25
date-format: "D MMMM YYYY"
bibliography: book.bib
format: docx
---
```{r}
@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