Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / sm_install.sh
Last active August 29, 2015 13:56
Minimal working environment for virtualenv for statsmodels
export BLAS=/home/skipper/.local/lib/libopenblas.a
export LAPACK=/home/skipper/.local/lib/libopenblas.a
pip install numpy
pip install scipy
pip install nose
pip install patsy
pip install Cython
pip install pandas
@jseabold
jseabold / math.tex
Created January 9, 2014 23:36
Cheat sheet for stochastic independence and conditional probability in latex.
% stochastic independence
\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}
% conditional probability pipe
\mid
@jseabold
jseabold / write_dates.R
Created January 3, 2014 20:46
Write dates to file in R. Must be a better way. What is this? SAS?
library(fpp)
data(usmelec)
write.csv(as.data.frame(list(date=as.Date(usmelec), usmelec=coredata(usmelec))), "usmelec.csv", row.names=FALSE)
@jseabold
jseabold / chroot32.md
Last active December 26, 2015 10:49
Create a 32-bit chroot environment

Create the chroot

sudo apt-get install debootstrap schroot
CHROOT=/tmp/saucy-i386; mkdir -p $CHROOT; sudo debootstrap --arch=i386 --include=python-pandas,sudo,wget --components=main,universe,multiverse saucy $CHROOT http://debian.lcs.mit.edu/ubuntu

echo -e "[saucy-i386]\ndescription=Ubuntu saucy  i386 architecture\ndirectory=$CHROOT\ntype=directory\nusers=$USER\nroot-groups=root\n" | sudo bash -c 'cat - > /etc/schroot/chroot.d/saucy-i386'

Enter the chroot

"""
Frisch-Waugh-Lovell Theorem.
In a multiple regression, the effect of any single covariate can be obtained
by removing the effects of the other covariates from both the dependent and
independent variables.
"""
import numpy as np
import statsmodels.api as sm
@jseabold
jseabold / url_gal.py
Created September 26, 2013 14:40
pysal gal reader monkey-patched to open urls
class MonkeyOpen(pysal.IOHandlers.gal.GalIO):
FORMATS = ['gal']
MODES = ['r', 'w']
def __init__(self, *args, **kwargs):
self._typ = str
pysal.core.FileIO.FileIO.__init__(self, *args, **kwargs)
self.file = urlopen(self.dataPath)
@staticmethod
def getType(*args, **kwargs):
@jseabold
jseabold / wide_to_long.py
Created September 21, 2013 18:47
Go from wide format panel data to long format. Similar to Stata's reshape.
def wide_to_long(df, stubnames, i, j):
"""
User-friendly wide panel to long format.
Parameters
----------
df : DataFrame
The wide-format DataFrame
stubnames : list
A list of stub names. The wide format variables are assumed to
@jseabold
jseabold / patr7079.csv
Created September 21, 2013 16:57
Cameron and Trivedi Patent data
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 25 columns, instead of 12 in line 5.
CUSIP,ARDSSIC,SCISECT,LOGK,SUMPAT,LOGR70,LOGR71,LOGR72,LOGR73,LOGR74,LOGR75,LOGR76,LOGR77,LOGR78,LOGR79,PAT70,PAT71,PAT72,PAT73,PAT74,PAT75,PAT76,PAT77,PAT78,PAT79
800,15,0,6.08360,354.00000,0.99684,0.88311,0.94196,1.06678,1.02901,0.92327,1.02309,0.97240,1.09500,1.07624,30.00000,28.00000,22.00000,34.00000,31.00000,32.00000,41.00000,60.00000,57.00000,77.00000
1030,14,1,1.97492,13.00000,-0.45815,-0.21637,0.08434,-0.15087,-0.68464,-1.48519,-1.19495,-0.60968,-0.58082,-0.60915,3.00000,1.00000,2.00000,1.00000,2.00000,3.00000,2.00000,1.00000,1.00000,1.00000
2824,4,1,5.64899,493.00000,3.39054,3.40697,3.44199,3.52962,3.58542,3.67343,3.77871,3.82205,3.88021,3.90665,48.00000,43.00000,61.00000,63.00000,58.00000,49.00000,42.00000,63.00000,77.00000,80.00000
4644,13,0,0.68377,2.00000,0.54340,0.48454,0.58779,0.48840,0.53714,0.43436,0.33836,0.36561,0.43860,0.42459,1.00000,0.00000,0.00000,1.00000,0.00000,0.00000,0.00000,1.00000,0.00000,0.00000
7842,16,0,2.06433,12.00000,0.39511,-0.88895,-0.31471,-0.21752,-0.36157,-1.29773,-1.6
@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 / 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"