Skip to content

Instantly share code, notes, and snippets.

View vikjam's full-sized avatar
💭
👨🏾‍💻

vikjam

💭
👨🏾‍💻
View GitHub Profile
@vikjam
vikjam / margins.do
Created November 27, 2019 04:43
Marginal means
* Marginal means in Stata
* https://www.stata.com/features/overview/marginal-analysis/
* Probit
webuse nlsw88, clear
quietly probit union wage c.age c.age#c.age collgrad
margins, dydx(age)
@vikjam
vikjam / install.sh
Last active May 15, 2019 17:35
Life on BasicTeX
# https://ryan-holben.github.io/tex/latex/installation/macos/2016/08/21/installing-tex-on-mac/
brew cask install basictex
sudo tlmgr update --self
sudo tlmgr install texliveonfly
sudo tlmgr install latexmk
sudo tlmgr install biber
sudo tlmgr install standalone
sudo tlmgr install preview
@vikjam
vikjam / lookfor.r
Last active March 7, 2019 21:33
Replicate the the lookfor command in Stata
# Required packages
# dplyr
# stringr
# glue
lookfor <- function(df, pattern) {
var_i <- names(df) %>% stringr::str_detect(stringr::regex(pattern, ignore_case = TRUE))
return(names(df)[var_i])
}
@vikjam
vikjam / tidy_regression_loop.r
Last active March 2, 2019 04:52
Looping regressions in the tidy verse
library(gapminder)
library(tidyverse)
library(broom)
library(huxtable)
library(lfe)
# Example dataset (via gapminder package)
glimpse(gapminder)
# Create a function to make looping easier
@vikjam
vikjam / output.Rout
Last active February 10, 2019 19:36
Summarize dplyr
Wrong mean: 5.84333333333333
Right mean: 5.936
The wrong mean didn't filter: 5.84333333333333
@vikjam
vikjam / copy_exif.rb
Last active January 21, 2019 17:11
Copy EXIF info from one photo to another
require 'mini_exiftool'
photo = MiniExiftool.new('new.jpg')
photo.tags.sort.each do |tag|
photo.copy_tags_from('original.jpg', tag)
end
photo.save
@vikjam
vikjam / install.sh
Created March 3, 2018 18:08
Academic Mac
brew tap caskroom/cask
brew install brew-cask
brew install Caskroom/cask/xquartz
brew cask install java
brew tap homebrew/science
brew install R
brew install Caskroom/cask/rstudio
@vikjam
vikjam / nonlinear.jl
Created October 28, 2017 19:57
Nonlinear solver
using JuMP, Ipopt
A = 1; δ = 0.1; θ = 0.3; β = 0.96; ɛ = 0.5; χ = 0.5;
r = (1 / β) - (1 - δ);
m = Model(solver = IpoptSolver())
@variable(m, 0 <= k <= Inf)
@variable(m, 0 <= n <= Inf)
@variable(m, 0 <= w <= Inf)
@vikjam
vikjam / rename.rb
Last active July 31, 2017 14:36
Quick renaming in Ruby
Dir.glob('*.mp3') do | the_filename |
track = the_filename[0..2].strip()
File.rename(the_filename, "05-#{track}.mp3")
end
@vikjam
vikjam / nytimes.py
Created June 30, 2017 13:39
NYT Headline Grabber
#!/usr/bin/env python
from lxml import html
import requests
import nltk
page = requests.get('http://nytimes.com')
tree = html.fromstring(page.text)
top_stories = tree.xpath('//*[@id="top-news"]/*//h2/a/text()')
more_stories = tree.xpath('//*[@id="main"]/div[10]/*//article/h2/a/text()')
all_stories = top_stories + more_stories