Skip to content

Instantly share code, notes, and snippets.

View tyleransom's full-sized avatar

Tyler Ransom tyleransom

View GitHub Profile
@tyleransom
tyleransom / container_btiming.jl
Created November 16, 2023 02:47
Julia Benchmarking of Data Containers
using Statistics, BenchmarkTools, DataFrames, Random
Random.seed!(1234)
mutable struct allParmsM
x::Float64
end
# fill in the mutable struct with the values
allpM = allParmsM(
5.784 # x
@tyleransom
tyleransom / linking_with_embeddings.R
Last active January 17, 2024 01:59
Using embeddings to fuzzy match databases
library(tidyverse)
library(openai)
#-------------------------------------------------------------------------------
# Step 1: Open AI API key
#-------------------------------------------------------------------------------
# Your OpenAI API key should be an environment variable you set in ~.Renviron
# ... you should never put your API key directly in your code!
* Dodging local macros (backtick)
* works
file open tb using "test1.tex", write replace
file write tb "These are backticks: " "`" "`" "air quotes''. "_n
file close tb
* works
!echo "These are backticks:" "`=char(92)'`=char(96)'""`=char(92)'`=char(96)'""air quotes''." > test2.tex
@tyleransom
tyleransom / grapher.R
Created February 21, 2023 04:12
graph-spline
library(ggplot2)
# create a matrix with the given points
pts <- matrix(c(3, 3, 3, 3, 3, 3, 3, 0.5, -1, -3, 1, 1.5, 2.75, 3, 1.25, 1.75, 0, 4, 8, 12, 16, 20, 23, 24, 25, 37, 38.5, 48, 60, 69, 71, 84), ncol = 2, byrow = F)
# sort the points by x value
pts <- pts[order(pts[, 2]), ]
# create the spline interpolation function
interp <- splinefun(pts[, 2], pts[, 1], method = "natural")
@tyleransom
tyleransom / test-optional.R
Last active July 13, 2022 12:35
Adoption of test-optional admissions policies over time
library(tidyverse)
library(magrittr)
library(pdftools)
# get a timeline of movement to test optional from fairtest.org
# url accessed on 30 Jun 2022
optl <- pdf_text(pdf = "https://www.fairtest.org/sites/default/files/Optional-Growth-Chronology.pdf") %>% str_split('\n')
optdf <- list()
for (i in seq(1:18)) {
print(length(optl[[i]]))
@tyleransom
tyleransom / chutesAndLadders.jl
Created February 5, 2022 19:26
Chutes and Ladders in Julia
wait_for_key(prompt) = (print(stdout, prompt); read(stdin, 1); nothing)
user_input(prompt) = (print(prompt); p = readline(); p)
function spin()
wait_for_key("Press enter to spin\n")
spun = rand(1:6)
println("You spun a ",spun)
return spun
end
@tyleransom
tyleransom / JHRchecklist.md
Last active July 2, 2023 12:30
Checklist for converting LaTeX PDF to Microsoft Word for *Journal of Human Resources* publication process

Make following formatting changes in LaTeX before importing the resulting PDF into Word

  • Sections and subsections numbered like "II.A.1" (add following to end of preamble)
    • \renewcommand{\thesection}{\Roman{section}}
    • \renewcommand{\thesubsection}{\thesection.\Alph{subsection}}
    • \renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
  • roman numeraled endnotes instead of footnotes (add following to preamble)
    • \usepackage{endnotes}
    • \let\footnote=\endnote
    • \renewcommand{\theendnote}{\roman{endnote}}
  • put "\theendnotes" just before the online appendix
@tyleransom
tyleransom / NHANES.R
Last active October 13, 2022 21:48
Data manipulation code files for undergrad econometrics class
library(NHANES)
library(tidyverse)
library(magrittr)
library(modelsummary)
df <- as_tibble(NHANES)
datasummary_skim(df, type="categorical")
datasummary_skim(df, type="numeric")
@tyleransom
tyleransom / analysis.R
Last active November 15, 2020 15:33
Bag of Letter Beads
library(tidyverse)
letters <- read_csv("https://gist.githubusercontent.com/tyleransom/c197d17b745870a464926435b95d7d9c/raw/3fd2cf7f50ecd9c04bd5adfbe4892f490730a560/beads.csv")
ggplot(data=letters, aes(x=`letter/character`)) +
geom_bar() +
geom_text(stat='count', aes(label=..count..), vjust=-1) +
theme_minimal()
@tyleransom
tyleransom / lfetest.R
Created October 9, 2020 03:00
test of lfe development branch by @grant_mcdermott
library(tidyverse)
library(magrittr)
devtools::load_all('~/lfe') # dev branch of lfe from @grant_mcdermott; see https://twitter.com/grant_mcdermott/status/1313900416342474752?s=20
df <- read_csv("https://raw.githubusercontent.com/OU-PhD-Econometrics/fall-2020/master/ProblemSets/PS4-mixture/nlsw88t.csv")
df %<>% mutate(occ_code = as.factor(occ_code))
felm(elnwage5 ~ occ_code | year + idcode, data=df)
# stata equivalent:
# insheet using "https://raw.githubusercontent.com/OU-PhD-Econometrics/fall-2020/master/ProblemSets/PS4-mixture/nlsw88t.csv", comma case
# areg elnwage5 i.occ_code i.year, absorb(idcode)