View ols-vs-iv.R
library(estimatr) | |
library(data.table) | |
## Function for single simulation | |
dm_sim = function(...) { | |
## Params | |
b0 = 1; b1 = 1; rhoXZ = 0.5; rho1 = 0.25 | |
rho2_vec = c(0.5, 0.25, 0, -0.25, -0.5) | |
nobs1 = 1000; nobs2 = 100 | |
## "In" sample draw |
View augment_interval_ex.R
## 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
#' 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 |
View gh_commit_msgs.R
## Context: https://twitter.com/grant_mcdermott/status/1272747522562244608 | |
## Note: To get the most out of this function (private repos, etc.), I recommend | |
## adding a GitHub Personal Access Token to your .Renviron file. The easiest way | |
## to do this is with the {usethis} package. See here: | |
## https://happygitwithr.com/github-pat.html#step-by-step | |
library(gh) | |
library(purrr) | |
library(data.table) |
View hidpi.sh
#!/bin/sh | |
DDIR='/usr/share/applications' | |
## There are two basic hidpi cases that we need to distinguish and correct for: | |
## 1) Electron-based apps and 2) QT-based apps | |
## 1) Electron-based apps (append '--force-scale-device-factor=2' to executable) | |
for FILE in atom.desktop brave-browser.desktop code-oss.desktop google-chrome.desktop skypeforlinux.desktop slack.desktop | |
do |
View replace_comp.R
## Context: https://twitter.com/grant_mcdermott/status/1249825585175523328 | |
set.seed(123) | |
m = matrix(1:10000000, ncol = 1000) | |
x_pos = sample.int(nrow(m), size = nrow(m)/2) | |
y_pos = sample.int(ncol(m), size = ncol(m)/2) | |
m_pos = (y_pos-1)*nrow(m) + x_pos | |
library(data.table) |
View zip_census.R
## Context: https://twitter.com/grant_mcdermott/status/1220409051013697553 | |
library(tidycensus) | |
# census_api_key("YOUR KEY GOES HERE", install = TRUE) | |
library(tigris) | |
options(tigris_use_cache = TRUE) | |
library(sf) | |
library(tidyverse) | |
## Get ZIP codes for whole US. First time you run this it will take a while, but |
View coef-plots.R
## Context: https://twitter.com/grant_mcdermott/status/1210654424600731648 | |
library(tidyverse) | |
library(broom) | |
library(hrbrthemes) ## theme(s) I like | |
df = | |
mtcars %>% | |
mutate(vs = factor(vs), am = factor(am)) |
View hsantanna_scrape.R
## Context: https://twitter.com/hsantanna/status/1196184374481506304 | |
## Thanks to Will May: https://twitter.com/williamcmay/status/1196268860418281472?s=20 | |
library(tidyverse) | |
library(rvest) | |
library(memoise) | |
ssp_url = 'http://www.ssp.sp.gov.br/estatistica/pesquisa.aspx' | |
## get the region/municipality form |
View bland_scrape.R
## Background: https://twitter.com/JamesBland_Econ/status/1192519670009434114 | |
# devtools::install_github("ropensci/RSelenium") | |
library(RSelenium) | |
## Start Selenium driver and browser client | |
rsd = rsDriver(browser = "firefox") # "chrome" is the default | |
rsc = rsd$client | |
## Navigate to the page |
NewerOlder