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.
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 "". 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.
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. It takes as its input a list of all the files you want to download (with their full directory path). It also works with wildcards such as "/path/to/files/*.sas7bdat", which is useful for downloading the full contents of a particular data group in WRDS or all the output from a server batch job.  It then compresses them into a zip file, downloads and uncompresses them into a local temporary directory, and then invokes StatTransfer to copy them all to Stata files in the current working directory.  NOTE: This script has been updated to work with the new WRDS Cloud.

A few notes
  • You will obviously need to alter the file to put in your own username and make sure the path to your StatTransfer command line program is correct to your install. You will also need to replace the temporary WRDS directory "/scratch/YourInstitution" with your institution. 
  • 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.
  • Avoid the temptation to run this command on something like "/wrds/taq/sasdata/*.sas7bdat". This may cause the WRDS server and/or your computer to catch fire. If you want to cause a server to catch fire and have your access revoked, there are more efficient scripts for that.

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 last condition is necessary for all models in which the individual fixed effects are not recovered by the estimation.

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