Scripts and small programs
Files here are served directly from this site. They used to live on Google Drive, which was a nuisance for everyone involved.
AppleScripts and shell scripts
I am a Macintosh user, and I have a handful of customizations that help with my workflow. Many of them involve AppleScripts, which I usually invoke through Alfred. As a side note, I cannot recommend Alfred enough. The dock is for suckers.
PathFinder.scpt- Copies the full path of the directory of a selected file in the Finder window to the clipboard, as a quoted string. Useful for quickly navigating to directories in interactive shells like Stata and IPython, or simply reconciling where you are in a Finder window with where you want to be in the terminal.
FilePathFinder.scpt- The same, except it copies the filename in the path as well.
remove_page_1.scptandremove_p1.sh-
Invokes
pdftkto remove the first page of the PDF in the active Preview window. I use it to strip the cover page automatically appended to many academic papers, JSTOR being the primary but not the only offender. Those cover pages are a real pain, since they are often a different paper size from the rest of the document and mess up the page zoom. Installpdftkfirst, then point the shell script at it, then point the AppleScript at wherever you putremove_p1.sh. The two are separated for convenience: the AppleScript exists so the thing can be invoked from Preview. With minor edits it will work in Adobe Reader or whatever your preferred reader is. booklet.scptandbooklet.sh-
Uses
pdflatexto make a two-page booklet of the paper in the current Preview window. I find this more reliable than the booklet printing baked into most printer drivers, and it respects cropped margins extremely well. The shell script also usespdfinfofrom the xpdf package to count pages and do the arithmetic for page ordering. All the paths need pointing at your particular install. Hide_LaTeX_Aux_Files.scpt-
Hides all the auxiliary helper files in the open Finder window by setting the
hiddenBSD flag on every file with a given extension. Not particularly elegant, but in a pinch it cleans up an ugly LaTeX directory. wrdsget.sh- Downloads files directly from the WRDS server and converts them to Stata files. Inputs are the SAS library name followed by a list of SAS tables, omitting the extension. To get the CRSP monthly file and the monthly header:
wrdsget crsp msf msfhdr
: That downloads msf.dta and msfhdr.dta into the local directory. Open the file and replace username with your WRDS username and institution with your institution as it appears in the scratch directory. Historically I downloaded the raw SAS file and converted locally, because the WRDS server was slow and SAS exports were wonky. With the WRDS cloud the speed has improved dramatically, so the conversion is done remotely, which also removes the need for a Stat/Transfer license. Stat/Transfer still gives a cleaner, more optimized result, but this is now good enough. Note the resulting file may not be stored efficiently, since SAS likes to cast variables as double precision floats for no good reason, so consider compressing it for long term use. You will also need to enter your password if you have not installed an RSA key, and it is a lot easier to just install an RSA key. For large files the SAS export can take a while, and it is unfortunately difficult to monitor the export log, so you will be in the dark while it runs.
Stata programs
Some Stata programs I have written. I have tried to make them somewhat fault tolerant, but some are a bit of a hack and may produce errors that need manual debugging. Email me with suggestions.
listif.ado-
Lists variables using both the
ifandinoptions, listing a number of observationsin x/ythat first satisfy a given criterionif a==b, in order. Since it preserves sort order and observation numbers within the data, it is very useful for quickly examining a conditional chunk of data in the console. Superseded bylistfirst, written by Nick Cox and available on SSC. sicencode.ado-
Quickly labels 2, 3, and 4 digit SIC codes. Takes a
digit()option for the level, and optionallylabelname()to name the label. naicsencode.ado- The same for NAICS codes. Since NAICS codes fully nest, no digit needs specifying.
estpdf.ado-
Outputs tables stored in
eststodirectly into LaTeX, compiles them, and opens the result. Useful for quickly viewing output with many columns and checking how it will look typeset. Passes through allesttaboptions exceptbooktabs, which it calls automatically. Currently something of a hack: it only works on macOS and Linux with a pdftex distribution in/usr/texbin/, since it shells out directly, and it assumesopenwill open PDFs in your preferred viewer. Minor edits should make it work on Windows. subl.ado-
A wrapper for the Sublime Text
sublcommand with one added feature. If the argument contains a space or a period, Stata treats it as a file or directory in the current path and opens it as usual. If it does not, Stata searches the ado paths for the ado file of that name and opens it wherever it lives in the filesystem. Useful when you are running an installed program and want to peek at the source to work out what it does. It saves only a couple of steps, but I do this constantly, and it makes “wait, what specifically does this program do?” a very simple question to answer.
Other
- Keynote Beamer-like theme
- A Keynote theme that looks like the stock Beamer theme. I like writing most documents in LaTeX, but I find Beamer close to insufferable. I put up with it for years because it looked good and it seems fancy to have a deck obviously made in Beamer. So I faked it in Keynote. A couple of things are kludged, like the callout boxes, which will not look right if you resize them, but it is usually close enough. Since PDF rendering is native to macOS, tables and equations can be typeset to PDF with LaTeXit and pasted straight into Keynote, then resized with no loss of fidelity.