Skip to content

Instantly share code, notes, and snippets.

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

vikjam

💭
👨🏾‍💻
View GitHub Profile
@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 / 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 / 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 / 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 / README.md
Last active April 5, 2020 16:54
COVID-19 Cases (San Diego County, by ZIP Code) - Updated April 4, 2020

COVID-19 Cases (San Diego County, by ZIP Code) - Updated April 4, 2020

Sources:

County officials stressed the presence of cases, or lack thereof, should not affect how people operate during the coronavirus pandemic.

Staying at home, practicing social distancing and washing your hands are just some practices to maintain, regardless of the number of cases reported in your community.

@vikjam
vikjam / .gitignore
Last active November 6, 2020 18:18
Ignore .env and specific folders in Git
# Ignore everything in this directory (place in the directory you want to ignore)
*
# Except this file
!.gitignore
@vikjam
vikjam / make_gifs.sh
Last active April 30, 2020 23:24
Making GIFs, but convert them to .gif beforehand
# https://github.com/kohler/gifsicle/issues/12
# brew install imagemagick gifsicle
convert *.jpeg GIF:- | gifsicle --delay=50 --loop --optimize=2 --colors=256 --multifile - > out.gif
@vikjam
vikjam / g_see.R
Last active October 22, 2021 17:16
Data browser in the browser with googleVis (gvisTable)
g_see <- function(dat) {
plot(
googleVis::gvisTable(dat,
options = list(page = "enable")
)
)
}
@vikjam
vikjam / example.py
Created January 30, 2021 01:05
Python mutable default arguments
l = ["m"]
def return_list(lst=l):
return(f"lst={lst} and l={l}")
l.append("n")
print(return_list()) # lst=['m', 'n'] and l=['m', 'n']
print(return_list(lst=l)) # lst=['m', 'n'] and l=['m', 'n']
l = ["n"]
print(return_list()) # lst=['m', 'n'] and l=['n']
@vikjam
vikjam / display_more.py
Created February 13, 2021 06:54
Display many rows of a pandas DataFrame
# Adapted from https://www.kaggle.com/jamesleslie/titanic-neural-network-for-beginners
def display_more(df, nrows=1_000, ncols=1_000):
with pd.option_context("display.max_rows", nrows, "display.max_columns", ncols):
display(df)