Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
"""
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"
@jseabold
jseabold / pysal_auto.ipynb
Created September 9, 2013 16:58
Try to replicate some spatial autocorrelation statistics.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jseabold
jseabold / hepatitis.csv
Created September 9, 2013 16:54
For this example we will consider the distribution of hepatitis rates for the counties of California. The data are taken from the Department of Health Services of the State of California (1999). Obtained from: http://www.nku.edu/~longa/geomed/ppa/doc/globals/Globals.htm
County X Y Rate
Alameda 195 500 14.4
Alpine 318 560 0.0
Amador 265 550 12.1
Butte 220 630 52.9
Calaveras 280 530 22.6
Colusa 195 598 23.8
Contra Costa 192 515 12.5
Del Norte 100 790 301.5
El Dorado 260 580 32.0
@jseabold
jseabold / schedule_sleep.sh
Last active December 19, 2015 20:58
Use rtcwake to sleep immediately and wake up in 23 hours (to do some stuff for an hour). Intended to be called from cron.
#!/bin/bash
DATE=`date -d "now + 23 hour + 0 min + 0 sec" +%s`
rtcwake -lv -m disk -t $DATE
exit
@jseabold
jseabold / alias.sh
Created July 2, 2013 18:36
Handy aliases.
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../../;'
alias c='clear'
alias ping='ping -c 5'
alias ports='netstat -tulanp'
alias apt-get="sudo apt-get"
## pass options to free ##
alias meminfo='free -m -l -t'