This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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") |
NewerOlder