Some Programs

Applescripts and Terminal (bash) Scripts

I'm a Macintosh user, and I have a hand full of customizations that I make to my system to help with my workflow. Many of them involve Applescripts, which I usually invoke through Quicksilver. As a side note, I cannot recommend Quicksilver 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). This is very useful for quickly navigating to directories in interactive programming shells like Stata and IPython, or simply reconciling where you are in a finder window with where you want to be in the Terminal bash shell.
FilePathFinder.scpt Same as above, except it also copies the filename in the path as well.
remove_page_1.scpt
remove_p1.sh
This script invokes the command line tool pdfk to remove the first page of a file from the pdf file in the active Preview window. I primarily use it to quickly strip the cover page that is automatically appended to many academic papers, JSTOR being the primary but not only offender. These cover pages are a real pain since they are often not the same paper size as the rest of the document and mess up the page zoom.

You first need to install pdftk and then make sure the shell script is pointing to the directory. Then make sure the applescript is pointing to wherever you put "remove_p1.sh". The bash script is separated from the Applescript for convenience. The Applescript exists in order to allow it to be easily invoked from Preview. With some edits, the script can be made to work in Adobe Reader or whatever your preferred PDF reader is.
booklet.scpt
booklet.sh
This script uses "pdflatex" to create a two page booklet of the paper in the current Preview window. I find this script somewhat more reliable in printing booklets than the printer script baked into many printer drivers. In particular, this script respects cropped margins extremely well.

The associated shell script also uses pdfinfo from the xpdf package in order to count the pages and to the necessary math to order the pages. All of the paths need to be pointed to the right paths in your particular install.
Hide_LaTeX_Aux_Files.scpt This script hides all of the auxiliary helper files from a given directory in the open finder window. All it does is set the "hidden" BSD system flag for all files with a given set of extensions. It's not particularly elegant, but in a pinch it can clean up an ugly LaTeX directory.
wrdsget.shThis is a shell script which downloads files directly from the WRDS server and converts them to Stata files.

This is a convenience shell script for locally downloading wrds datasets as local .dta files. The inputs are the formal "SAS library name" followed by a list of "SAS tables", omitting the extension. For example, to download the CRSP monthly file and the monthly header you would type:

wrdsget crsp msf msfhdr

This will download msf.dta and msfhdr.dta into your local directory, where crsp is the WRDS sas library and msf and msfhdr are the relevant tables.

In order to make the script work for you, you need to open the file and replace the "username" with your WRDS username and "institution" with the name of your institution as it appears in the "scratch" directory.

A few notes
  • In the past, because the wrds server was fairly slow and SAS exports to other formats were a little wonky, I downloaded the raw SAS file and did the conversion locally. With the new wrds cloud, the speed has improved dramatically, so the conversion is done remotely. This also has the benefit of not requiring a Stat/Transfer license. I still find that Stat/Transfer provides a cleaner, more optimized result, but this method now appears to be good enough.
  • Do note that the resulting file may not be stored very efficiently (SAS really likes to cast variables as double precision floats for no good reason), so you may wish to compress the file if you are using it long term.
  • You would also need to put in your password if you haven't installed an RSA key. FYI, it's a lot easier to just install an RSA key.
  • For large files, the SAS export can take a while and it is unfortunately too difficult to monitor the SAS export program log, so you will be in the dark while the SAS program runs.

Stata Programs

Here are some Stata programs I've written. While I've tried to make these programs somewhat fault tolerant, some of them may be a bit of a hack and produce errors which must be manually debugged. Please email me with any suggestions for improvement.

listif.ado A brilliant little program which lists variables using both the -if- and -in- options, listing a number of observations (in x/y) which first satisfy a given criteria (if a==b) in order. Since it also preserves the sort order and observation numbers within the data, it is very useful for quickly examining a conditional chunk of the data in console.
sicencode.ado A program for quickly labeling 2,3, and 4 digit sic codes. Requests ",digit()" option for the level of sic code. Optionally allows defining the label name using labelname()
naicsencode.ado Same thing for naics codes. Since naics codes fully nest, the user doesn't need to specify the digit.
xtpoissonFE.ado This program allows fixed-effects poisson models to be clustered at a level other than the -xtset- group id, so long as all group id observations are fully nested in a given cluster.

This nested condition not strictly speaking necessary, but if your clusters involve cross-cutting concerns you need to be a lot more meticulous about your degrees of freedom and your assumptions about the within group correlation. In general I've found (a) in practice it rarely makes any meaningful difference, and (b) if you're trying to cluster by some cross-cutting concern, you probably need to step back and take a long hard look at your modeling assumptions. Clustering is not a silver bullet, and naively assigning a complex cluster structure to the variance-covariance matrix because of some vaguely defined concern is sort of counter-productive.


Note that the program works by calling -xtpoisson- directly, clustering the standard errors after it completes, reposting the new standard errors to e() and then calling -estimates replay-. Thus the program is fully compatible with -estout-. However, it suppresses the "Iteration #" output, so if the model is failing to converge you might not be immediately aware of it. The syntax uses the ,cluster(cluster_id) option.
estpdf.ado Outputs tables stored in -eststo- directly into LaTeX files, which it then compiles and opens. This is particularly useful for quickly viewing output with lots of columns and testing how it will look under LaTeX. Note that -estpdf- will passthrough all options available to -esttab-, with the exception of booktabs which it calls automatically.

Warning: This program is currently kind of a hack. In it's current form, it only works under OSX and Linux users which have their pdftex distribution installed in /usr/texbin/ since it makes a call directly to the bash shell. It also assumes that the shell command "open" will open pdf files with the preferred PDF viewer. However, some minor edits to the command call should allow it to work under Windows as well.
fred.ado A program for quickly downloading data from Fred at the St. Louis Fed. The functionality of this program has effectively been superseded by -freduse- available through SSC. But then, I'm sentimental.
crsp_cal.stbcal
A Stata business calendar for CRSP daily data. Will account properly for all allowable trading days in which prices and returns were registered in the construction of the CRSP value weighted index. Properly excludes weekends, except Saturday prior to the NYSE Saturday close of 1952. Properly excludes the close of trading post 9/11 and during the Emergency Banking act of 1933.

Some Other Stuff

Here is a theme for Keynote that looks like the stock Beamer theme: Keynote Beamer-Like Theme.key

I really like writing most documents in LaTeX, but I find Beamer kind of insufferable. I put up with it forever just because it looked good and it seems fancy to have a slide deck obviously made in Beamer. So I faked it using Keynote. I had to kluge a couple of things like the callout boxes which won't look right if you resize them, but it's usually close enough. Since PDF rendering is native to OSX, things like tables and equations can simply be typeset to PDF using LaTeXit or something and then pasted directly into keynote and resized without loss of fidelity.