Skip to content

Instantly share code, notes, and snippets.

View grantmcdermott's full-sized avatar

Grant McDermott grantmcdermott

View GitHub Profile
@grantmcdermott
grantmcdermott / modelsummary_typst.R
Created December 4, 2024 18:42
fixest -> modelsummary -> typst
# Context: https://bsky.app/profile/thetahat.bsky.social/post/3lchztjxufc2t
library(fixest)
library(modelsummary)
library(tinytable)
mods = feols(
rating ~ complaints + privileges + learning + csw0(raises + critical),
data = attitude
)
@grantmcdermott
grantmcdermott / 100m-pace.R
Created August 6, 2024 02:36
100 m pace equivalents
# Context: https://bsky.app/profile/kjhealy.bsky.social/post/3kywqjin76i2r
library(rvest)
library(tinyplot)
tpar(grid = TRUE, las = 1, pch = 16)
# read the wiki page
wp = read_html("https://en.wikipedia.org/wiki/List_of_world_records_in_athletics")
# select the table of interest
@grantmcdermott
grantmcdermott / duckdb-dplyr-ex.R
Created September 30, 2023 01:22
Simple examples of how to use DuckDBs dplyr front-end in R
# preliminaries -----
# packages you'll need (install these if you don't have them)
# install.packages(c("arrow", "duckdb", "dplyr", "tidyr"))
# write a dummy parquet dataset (i.e., multiple parquet files) to disk
dir.create("airquality")
arrow::write_dataset(
airquality,
path = "airquality",
@grantmcdermott
grantmcdermott / gg-floating-axes.R
Created February 20, 2023 06:06
Floating axes in ggplot2 (via ggh4x)
# Context: https://mastodon.social/@gmcd/109895547902826763
library(ggh4x)
theme_set(
theme_bw() +
theme(
axis.line = element_line(linewidth = 0.4),
axis.ticks = element_line(linewidth = 0.4),
panel.grid.minor = element_blank(),
@grantmcdermott
grantmcdermott / baker.R
Created February 21, 2022 01:29
Generate the "Baker" simulated dataset for staggered treatment effects
set.seed(1234)
# Create the base dataset as a cross-join of 1,000 firms over 30 periods
baker = expand.grid(n = 1:30, id = 1:1000)
# Add additional columns
baker =
baker |>
within({
year = n + 1980 - 1
@grantmcdermott
grantmcdermott / collapse_mask.R
Created February 15, 2022 02:18
Benchmarking collapse_mask
## Context: https://twitter.com/grant_mcdermott/status/1493400952878952448
options(collapse_mask = "all") # NB: see `help('collapse-options')`
library(dplyr)
library(data.table)
library(collapse) # Needs to come after library(dplyr) for collapse_mask to work
flights = fread('https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv')
@grantmcdermott
grantmcdermott / syllabus.qmd
Created February 13, 2022 00:45
EC 311 syllabus
---
title: "Intermediate Microeconomics (EC 311)"
subtitle: "Syllabus"
author: "Grant McDermott"
date: "Department of Economics, University of Oregon"
format:
pdf:
pdf-engine: pdflatex
documentclass: article
toc: false
@grantmcdermott
grantmcdermott / bboot.R
Last active May 6, 2022 18:50
Bayesian bootstrap
# Context: https://twitter.com/grant_mcdermott/status/1487528757418102787
library(data.table)
library(fixest)
bboot =
function(object, reps = 100L, cluster = NULL, ...) {
fixest_obj = inherits(object, c('fixest', 'fixest_multi'))
@grantmcdermott
grantmcdermott / ggiplot-examples.R
Last active December 24, 2021 08:12
A ggplot2 implementation fixest::iplot()
## Examples, borrowing from the intro vignette
library(fixest)
library(ggplot2)
## Source the function
source('https://gist.githubusercontent.com/grantmcdermott/db8501b0281813792bf78393fef98481/raw/ggiplot.R')
## Vanilla TWFE
est_did = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did)
@grantmcdermott
grantmcdermott / mixtape-tidysynth.R
Created January 29, 2021 00:42
Testing out the new tidysynth package on Cunningham (2021, chap 10.)
# Libraries ---------------------------------------------------------------
library(tidysynth)
library(haven)
# Data --------------------------------------------------------------------
texas = read_dta('https://raw.github.com/scunning1975/mixtape/master/texas.dta')