Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / translate.py
Created December 13, 2011 18:58
Use Google Translate API from Python
# -*- coding: utf-8 -*-
"""
You need to fill in your API key from google below. Note that querying
supported languages is not implemented.
Language Code
-------- ----
Afrikaans af
Albanian sq
Arabic ar
@jseabold
jseabold / standardized_regressors.py
Created May 3, 2013 14:10
standardize each variable in a statsmodels regression
import statsmodels.api as sm
from statsmodels.formula.api import ols
# load some data
dta = sm.datasets.longley.load_pandas()
# make a standardized RHS formula
stand = "standardize(%s)"
std_rhs = ' + '.join([stand]*len(dta.exog_name)) % tuple(dta.exog_name)
print std_rhs
@jseabold
jseabold / zip_model.py
Last active June 6, 2022 12:45
Zero-Inflated Poisson Estimation
import numpy as np
from scipy import special, stats
from statsmodels.base.model import GenericLikelihoodModel
def vuong_test(p1, p2):
r"""
Vuong-test for non-nested models.
Parameters
----------
@jseabold
jseabold / Difference_in_Differences_Differences.ipynb
Last active March 14, 2021 18:13
Working out some differences between R and Python for Causal Inference: The Mixtape
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
This took me a while to figure out so posting for posterity.
plt.interactive(False) is important, if you want the grid to only show up
when `display`ed. Since `sns.FacetGrid` can take a few seconds depending
on the size of your data, this displays a spinner in the notebook cell
until the new graph is ready to render.
"""
import matplotlib.pyplot as plt
@jseabold
jseabold / spirals.py
Created January 30, 2013 00:51
draw a spiral in matplotlib
import numpy as np
import matplotlib.pyplot as plt
#As a path collection
from matplotlib.collections import LineCollection
fig, ax = plt.subplots()
r = np.arange(0, .075, 0.00001)
nverts = len(r)
@jseabold
jseabold / git_find_big.py
Created September 27, 2015 16:49
git filter-branch magic using Python
#! /usr/bin/env python
import glob
import os
import shutil
import re
from collections import namedtuple
import subprocess
from subprocess import PIPE
@jseabold
jseabold / zip_fe.ado
Created September 17, 2013 22:05
Fixed Effects Zero-Inflated Poisson from Majo and van Soest (2011).
set more off
capture program drop ZIP_FE_model
program define ZIP_FE_model
version 9.1
args todo b lnf
tempvar theta1 lambda last nonz w sln0 sln r0 r nb0 nb1 nb00 nb2 L2
local by "$MY_panel"
@jseabold
jseabold / tufte.py
Last active February 19, 2019 12:44
Recreation of Tufte graphic in Python based on an Rstats blog post and gist http://asbcllc.com/blog/2015/January/gotham_2014_weather/ https://gist.github.com/abresler/46c36c1a88c849b94b07
import os
import calendar
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, FixedFormatter
import pandas as pd
import seaborn as sns
to_colors = lambda x : x/255.
@jseabold
jseabold / spot_pricing.py
Created August 11, 2015 14:33
Plot EC2 spot pricing with boto3 and pandas
import pandas as pd
from boto3 import client
client = client(service_name='ec2')
prices = client.describe_spot_price_history(InstanceTypes=["m3.medium"],
AvailabilityZone="us-east-1a")
df = pd.DataFrame(prices['SpotPriceHistory'])
df.set_index("Timestamp", inplace=True)
df["SpotPrice"] = df.SpotPrice.astype(float)