This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function respects the digits option | |
mkarray <- function(X, name) { | |
cat(name); cat(" = np.array(["); cat(X, sep=","); cat("])") | |
if (is.matrix(X)) { | |
i <- as.character(nrow(X)) | |
j <- as.character(ncol(X)) | |
cat(".reshape("); cat(i); cat(","); cat(j); cat(", order='F')") | |
} | |
cat("\n\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
capture program drop mat2nparray | |
program define mat2nparray | |
version 11.0 | |
syntax namelist(min=1), SAVing(str) [ Format(str) APPend REPlace ] | |
if "`format'"=="" local format "%16.0g" | |
local saving: subinstr local saving "." ".", count(local ext) | |
if !`ext' local saving "`saving'.py" | |
tempname myfile | |
file open `myfile' using "`saving'", write text `append' `replace' | |
file write `myfile' "import numpy as np" _n _n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas import MultiIndex, Factor | |
import numpy as np | |
import pandas | |
def _ensure_like_indices(time, panels): | |
n_time = len(time) | |
n_panel = len(panels) | |
u_panels = np.unique(panels) # this sorts! | |
u_time = np.unique(time) | |
if len(u_time) == n_time: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Context manager or function to send text messages to your phone when a | |
process is done. | |
Edit the global variables. You might be able to find your phone e-mail | |
address here: http://tinywords.com/about-old/mobile/ | |
Usage: | |
with SendText("long running process"): | |
do_something() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas | |
import numpy as np | |
def webuse(data, baseurl='http://www.stata-press.com/data/r11/'): | |
""" | |
Parameters | |
---------- | |
data : str | |
Name of dataset to fetch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Use a decorator to transform the params input to a likelihood function. | |
""" | |
from functools import wraps | |
from contextlib import contextmanager | |
import numpy as np | |
import inspect | |
def make_doc(func, wrapper): | |
argspec = inspect.getargspec(func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Put a variable or variable list into a Stata matrix even if it's bigger than | |
matsize. | |
Usage: | |
If you have some variables xb1 and xb2 | |
bigmat xb1 xb2, mat(new_mat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.model import LikelihoodModel | |
import numpy as np | |
from numpy import asarray | |
from scipy import optimize | |
def log_star(z, eps): | |
""" | |
Owens' log* function. Provides curvature at eps. | |
""" | |
log_idx = z > eps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# edit this to install whatever you want that depends on numpy after you | |
# reinstall numpy | |
# edit these variables or add to them | |
npsrc="$HOME/src/numpy/" | |
spsrc="$HOME/src/scipy/" | |
pdsrc="$HOME/src/pandas/" | |
smsrc="$HOME/statsmodels/statsmodels/" |
OlderNewer