View gg-floating-axes.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(), |
View baker.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View collapse_mask.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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') |
View syllabus.qmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 |
View bboot.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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')) | |
View ggiplot-examples.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
View mixtape-tidysynth.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Libraries --------------------------------------------------------------- | |
library(tidysynth) | |
library(haven) | |
# Data -------------------------------------------------------------------- | |
texas = read_dta('https://raw.github.com/scunning1975/mixtape/master/texas.dta') |
View ols-vs-iv.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ivreg) | |
## Convenience functions | |
rmse = function(y, yhat) sqrt(mean((y - yhat)^2)) | |
mae = function(y, yhat) mean(abs(y - yhat)) | |
## Function for single simulation | |
dm_sim = function(...) { | |
## Params | |
b0 = 1; b1 = 1; rhoXZ = 0.5; rho1 = 0.25 |
View augment_interval_ex.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Context: https://twitter.com/grant_mcdermott/status/1293673082352099328 | |
library(broom) ## remotes::install_github('tidymodels/broom') | |
library(ggplot2) | |
## gen fake data | |
set.seed(123) | |
x = sort(runif(100, min = 0, max = 5)) | |
y = x^2 + rnorm(100) | |
dat = data.frame(x, y) |
View refi-comp.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Compare expected returns of 15- vs 30-year home refi. | |
#' | |
#' This very simple function assumes you split your disposable income between | |
#' mortgage repayments and stock investments. The goal is to compare ROI at the end | |
#' of 30 years, assuming you initially have a choice between 15- and 30-year fixed rate | |
#' mortgage. | |
#' | |
#' @details Under the 15-year scenario, we assume that you pay the monthly premium | |
#' until the loan is fully repaid (i.e. after 15 years) and then immediately switch | |
#' over to investing the exact same amount for another 15 years. Under the 30-year |
NewerOlder