Skip to content

Instantly share code, notes, and snippets.

View tyleransom's full-sized avatar

Tyler Ransom tyleransom

View GitHub Profile
@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 / 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 / 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 / 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 / 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
using BenchmarkTools
using Optim, NLSolversBase
function datagen(n=5500,k=13)
b = rand(k)
l = rand(2)
x = randn(n,k)
abil = randn(n,1)
vabil = randn(n,1)
sector = 1.0.*(rand(n,1).>0.8)
@tyleransom
tyleransom / optimexample.jl
Last active June 22, 2018 14:13
Optimize memory usage in Julia
using Optim, NLSolversBase
function datagen(n=5500,k=13)
b = rand(k)
l = rand(2)
x = randn(n,k)
abil = randn(n,1)
vabil = randn(n,1)
sector = 1.0.*(rand(n,1).>0.8)
weight = rand(n,1)

Rosetta Stone

This consists of a "Rosetta Stone" of code syntax between R, Python, and Julia. The aim is to help those who are proficient in one language easily translate their code/understanding to another.

Basic actions (REPL, package ecosystem, etc.)

Action R code Python code Julia code
execute script from REPL source('script.R') execfile('script.py') include("script.jl")
install a package install.packages("pkg") [from OS terminal]: pip install pkg Pkg.add("pkg")
load a package library(pkg) or require(pkg) import pkg using pkg
@tyleransom
tyleransom / gcc-5.4.0-install.sh
Last active January 11, 2024 05:47 — forked from jdhao/gcc-5.4.0-install.sh
The script will install GCC 5.4.0 on your CentOS 7 system, make sure you have root right.
echo "Downloading gcc source files..."
curl https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2 -O
echo "extracting files..."
tar xvfj gcc-5.4.0.tar.bz2
echo "Installing dependencies..."
yum install gmp-devel mpfr-devel libmpc-devel
echo "Configure and install..."
@tyleransom
tyleransom / NppVimCrosswalk.md
Last active February 29, 2024 17:10
Crosswalk between Notepad++ and Vim utilities

Crosswalk between Notepad++ and Vim utilities

Action Notepad++ shortcut Vim shortcut
Duplicate line Ctrl+D yyp
Cut line Ctrl+L dd
Move line up/down Ctrl+Shift+<up/down> dd<k/j>p
Compare files File compare plugin wizard :vsplit <filename> or vimdiff file1 file2 (from command line)
Select all (from here to top/bottom of file) Ctrl+Shift+<home/end> v<gg/G>
Select all (from here up/down one page) Ctrl+Shift+ v Ctrl+