Skip to content

Instantly share code, notes, and snippets.

View bquistorff's full-sized avatar

Brian Quistorff bquistorff

View GitHub Profile
@bquistorff
bquistorff / normalize_dta.py
Created November 20, 2014 02:11
Normalizes a Stata dta file
#!/usr/bin/env python
#
# Rewrites a dataset without the timestamp nor junk in padding
# Helps making things bit-reproducible.
# Doesn't convert byte-order for numerical types.
import struct, sys, datetime, glob, tempfile, shutil, os, getopt
def error(message):
sys.stderr.write(message + '\n')
@bquistorff
bquistorff / normalize_log.sed
Created November 20, 2014 02:10
Utility for normalizing Stata log files
#!/usr/bin/sed -f
#### Standard Stata output ####
### Time/speed-specific specific
s/[ 0-9][0-9] [A-Z][a-z][a-z] [0-9]\{4\},\? ..:..\(:..\)\?/-normalized-/g
### Machine-specific
##OS-dependent: file path
@bquistorff
bquistorff / normalize_log.sh
Created November 20, 2014 02:08
Normalizes a Stata log file
#!/bin/bash
#
# File to normalize Stata log files. Remove computer-specific,
# time-specific, and random components from log files.
# This enables identification of differences in Stata runs by
# using binary diffs (easy with a versioned project like one on SVN).
#To do:
# deal with the unversioned env variable (quieted for now in ipums_migr...)
@bquistorff
bquistorff / cli-install-module.do
Created October 7, 2014 19:16
Callable from the command line for install packages from local store (that need machine-specific installation)
*Callable from the command line for install packages from local store (that need machine-specific installation)
global dir_base ".."
* Use the -net set- line before installing other packages
net set ado "${dir_base}/code/ado/"
local letter1 = substr("`1'",1,1)
net install `1' , all force from("`c(pwd)'/${dir_base}/code/ado-store/`letter1'/")
@bquistorff
bquistorff / gen-makefile.sh
Last active April 4, 2018 13:51
Generates a makefile keep Stata module installed files up-to-date with changes to the installation files
#!/bin/bash
#make a package-specific makefile
# Requirement: set the environment variable STATA_PLATFORM
# The platform names are:
# WIN (32-bit x86) and WIN64A (64-bit x86-64) for Windows;
# MACINTEL (32-bit Intel, GUI), OSX.X86 (32-bit Intel, console), MACINTEL64 (64-bit Intel, GUI), OSX.X8664 (64-bit Intel, console), MAC (32-bit PowerPC), and OSX.PPC (32-bit PowerPC), for Mac;
# LINUX (32-bit x86), LINUX64 (64-bit x86-64), SOL64, and SOLX8664 (64-bit x86-64) for Unix.
# To do: generate this automatically
@bquistorff
bquistorff / store-mod-install-files.sh
Created October 7, 2014 18:56
Downloads to a folder the necessary installation files for a Stata module
#!/bin/bash
# Example usage
#./store-mod-install-files.sh http://fmwww.bc.edu/repec/bocode/s/synth.pkg ado-store
# Assumes the standard first-letter directory structure.
pkgfilename=$(basename "$1")
pkgdirpath=$(dirname "$1")
pkgbase="${pkgfilename%.*}"
pkgbase_letter=${pkgbase:0:1}
orig_dir=$PWD
@bquistorff
bquistorff / statab.sh
Last active June 5, 2019 18:21 — forked from pschumm/statab
Wrapper for launching Stata in batch-mode
#! /bin/bash
# Wrapper for Stata batch-mode which:
# -issues an informative error msg and appropriate (possibly non-zero) return code
# -allows an implicit -do- when called with just a do file
# Requirements: set $STATABATCH (e.g. 'stata-mp -b')
# updated from Phil Schumm's version at https://gist.github.com/pschumm/b967dfc7f723507ac4be
args=$# # number of args
@bquistorff
bquistorff / patch-mlibs.do
Last active August 29, 2015 14:07
Patch system mata functions with personal ones
*Make sure -mata: mata mlib index- has been executed previously
cap di regexm("`c(matalibs)'", "(.*);lpersonal(.*)")
mata: mata set matalibs "lpersonal;`=regexs(1)'`=regexs(2)'"
@bquistorff
bquistorff / beamer_outputs_bash.sh
Created September 27, 2014 15:01
Creates the various versions of a presentation from a beamer LyX document (command line version).
#!/bin/bash
# Creates three PDFs from a Beamer LyX document.
# Doesn't assume anything about existing options
# so makes all docs with new file suffixes.
#
# Added to Right-click menu with FileMenu Tools by lopesoft
# Pass in the filename with extension
filename=${1%%.*}
@bquistorff
bquistorff / beamer_outputs.sh
Last active August 29, 2015 14:05
Creates the various versions of a presentation from a beamer LyX document.
#!/bin/bash
# Creates three PDFs from a Beamer LyX document.
# Doesn't assume anything about existing options
# so makes all docs with new file suffixes.
#
# Added to Right-click menu with FileMenu Tools by lopesoft
# Pass in the filename with extension
filename=${1%%.*}