Skip to content

Instantly share code, notes, and snippets.

View tyleransom's full-sized avatar

Tyler Ransom tyleransom

View GitHub Profile
@tyleransom
tyleransom / normalMLE.jl
Last active August 3, 2018 16:43
Compare run time of Julia and Matlab optimization for simple Maximum Likelihood problem (normal linear model)
function normalMLE(b::Vector,Y::Array,X::Array,w::Array=ones(size(Y)),d::Array=ones(size(Y)),J::Int64=1)
@assert size(Y,1)==size(X,2) "X and Y must be the same length"
T = promote_type(eltype(b), eltype(X))
like = zero(T)
@inbounds for i=1:size(Y,1)
xb = zero(T)
for j in 1:size(X,1)
xb += X[j, i] * b[j]
end
@tyleransom
tyleransom / build-gcc-4.7.sh
Created August 31, 2018 22:33
Script to build GCC 4.7.x on newer Linux distributions (using
#!/bin/bash
#Download source
wget http://mirrors.concertpass.com/gcc/releases/gcc-4.7.2/gcc-4.7.2.tar.bz2
tar xvfj gcc-4.7.2.tar.bz2
cd gcc-4.7.2
./contrib/download_prerequisites
#Download and apply fix to be able to build GCC 4.7 with GCC 5.x
@tyleransom
tyleransom / jump_mwe.jl
Last active December 9, 2018 03:51
MWE for linear programming problem
using DataFrames
using HTTP
using uCSV
using JuMP
using GLPK
using Cbc
# read in the data
fname = "https://gist.githubusercontent.com/tyleransom/3738fa6cd1b3b5602e0621b08d068380/raw/5c4b139639d7b3c16716289b0232b8528d1bf494/mwe.csv"
data = DataFrame(uCSV.read(IOBuffer(HTTP.get(fname).body), quotes='"', header=1))
@tyleransom
tyleransom / autochoice.csv
Last active May 22, 2019 12:54
test for alternative-specific conditional logit
id male income size choicecat dealer1 dealer2 dealer3
1 1 46.7 2 3 18 8 5
2 1 26.1 3 1 17 6 2
3 1 32.7 4 1 12 6 2
4 0 49.2 2 2 18 7 4
5 1 24.3 4 1 10 7 3
6 0 39 4 1 13 4 1
7 1 33 2 1 24 7 4
8 1 20.3 4 1 9 3 3
9 1 38 3 2 14 10 2
@tyleransom
tyleransom / SMM_OLS.jl
Created September 26, 2020 12:50
attempt at using SMM.jl to estimate a basic linear model (that could be estimated by OLS)
using Random
using LinearAlgebra
using Statistics
using Distributions
using DataFrames
using OrderedCollections
using SMM
Random.seed!(1234)
@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)
@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 / 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 / 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 / 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