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.

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.

Same as above, except it also copies the filename in the path as well.

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."

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.

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.

This 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.

  • 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.

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.

Note: This program has been superseded by listfirst, written by Nick Cox and available on SSC.

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()

Same thing for naics codes. Since naics codes fully nest, the user doesn't need to specify the digit.

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.

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.

If you use Sublime Text you may be aware of the useful command line call subl which takes a file or directory as it's argument and opens that file or directory in Sublime Text from the shell. This Stata program is a wrapper for this shell command with an added feature. If the input to subl within the Stata terminal contains a space or a period, Stata will interpret this as a file or directory within the current path (or global path if it begins with a /) and open it in Sublime Text as usual.

If it does not, then Stata will search the ado paths for the ado file with that name and open it, wherever it is in the filesystem. This is useful if you are executing an installed program and want to quickly peek at the source code to try and figure out where it does. It only saves a couple of steps, but I find myself doing this all the time and it makes asking "wait, what specifically does this this program do?" a very simple process.

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.