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 / aaer_data_comparison.md
Last active October 7, 2022 23:07
Comparison of AAERs across two files from Bao et al. (2020).
library(readr)
library(dplyr, warn.conflicts = FALSE)
site_url <- "https://raw.githubusercontent.com/JarFraud/FraudDetection/master/"

final_df_filename <- "data_FraudDetection_JAR2020.csv"
final_df <- read_csv(paste0(site_url, final_df_filename),
                     col_types = "d") 

aaer_df_filename <- "AAER_firm_year.csv"
@iangow
iangow / wirecard.md
Created October 4, 2022 02:48
Stock prices for Wirecard
library(quantmod)
#> Loading required package: xts
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric
#> Loading required package: TTR
@iangow
iangow / freq_to_vec.R
Last active September 9, 2022 00:01
Convert frequency table to vector
library(tidyverse)
scores <-
tribble(
~value, ~count,
1, 0,
2, 2,
3, 7,
4, 5,
5, 6,
@iangow
iangow / temps_mel.R
Created September 8, 2022 22:16
Boxplot of temps by month
library(tidyverse)
library(lubridate)
read_weather <- function(file, var) {
read_csv(file,
col_names = c("code", "station", "year", "month", "day",
var, "days_accum", "quality"),
col_types = "ciiiiddc",
skip = 1) %>%
filter(!is.na(year), !is.na(month), !is.na(day)) %>%
library(dplyr, warn.conflicts = FALSE)
library(dbplyr)
library(DBI)
library(ggplot2)
library(stargazer)
library(sandwich)
library(robustbase)
library(lfe)
library(purrr)
library(tidyr)
@iangow
iangow / hundred_words.ipynb
Created August 12, 2022 02:44
Get list of words with value 100.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iangow
iangow / perf_plots.qmd
Last active July 27, 2022 13:24
Performance over time
---
title: "Performance over time"
format: pdf
editor: visual
---
```{r, message=FALSE, include=FALSE}
library(DBI)
library(dplyr, warn.conflicts = FALSE)
library(dbplyr)
@iangow
iangow / size_schemas.R
Created July 22, 2022 18:03
Get details on size of schemas
table_sql <- "SELECT n.nspname AS \"Name\",
pg_catalog.pg_get_userbyid(n.nspowner) AS \"Owner\"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'
ORDER BY 1"
library(dplyr, warn.conflicts = FALSE)
library(DBI)
pg <- dbConnect(RPostgres::Postgres())
@iangow
iangow / mmwr.R
Created February 7, 2022 17:13
Some crunching of numbers from MMWR study
library(dplyr)
df <- tibble(test = c(rep(TRUE, 24), rep(FALSE, 11),
rep(TRUE, 112), rep(FALSE, 104),
rep(TRUE, 113), rep(FALSE, 139),
rep(TRUE, 10), rep(FALSE, 21)),
mask = c(rep("None", 24 + 11),
rep("Cloth", 112 + 104),
rep("Surgical", 113 + 139),
rep("N95", 10 + 21))) %>%
@iangow
iangow / ma_death_data.R
Created May 19, 2021 10:54
Code to scrape data on daily Covid-19 deaths
library(readxl)
library(dplyr, warn.conflicts = FALSE)
get_data <- function(date) {
date <- as.Date(date)
date_str <- gsub(" ", "", tolower(format(date, "%B-%e-%Y")))
url <- paste0("https://www.mass.gov/doc/covid-19-raw-data-", date_str,
"/download")
t <- tempfile()