87
2 Some perl applications
There are many resources for learning perl, including Phil Spector's excellent presenta-
tion which is available in PostScript and PDF formats from http://stat.berkeley.edu/
~spector. Rather than introduce perl, I want to show several ways I've applied perl to make
my work easier. Please feel free to ask me about the code in these applications
The rst application is used in conjunction with on-line data extraction from the Panel
Study of Income Dynamics (http://www.umich.edu/~psid). The perl script (psidcode.pl)
takes as input the variable list chosen by the user and generated by the PSID web site.
The perl script then reads through all (16 codebooks representing 24 years of family and
individual data) of the compressed PSID codebook stored as zip les on the EML and
extracts only the chosen variable denitions. The script is currently available from ~mash/
access/psidcode.pl and is reprinted in Appendix A.
One of the most useful features of perl for me is that it can write L
A
T
E
X2
"
code. I
did this to mass produce my job market letters and I also use it to write Stata output to
L
A
T
E
X2
"
les. Remember that you need to use double backslashes (nn) when you print in
perl to generate a single backslash in the L
A
T
E
Xle perl generates. The following code,
stat2lat.pl parses Stata output, extracts regressions results, and writes a L
A
T
E
Xle that
presents the regressions in a set of user-specied tables. For the time being, you can copy
this code from ~mash/access/stat2lat.pl, and the script is reprinted in Appendix B.
Another application I wrote parses Job Openings for Economists and writes addresses to
ale which L
A
T
E
Xcan use for mailing labels and another perl script can use to address form
letters. This application is reprinted in Appendix C and is available from ~mash/jobmarket/
joe.pl.
3 xg
Unix oers an excellent drafting program called xfig which you can use to draw and label
diagrams, e.g. indierence curves, phase diagrams, market equilibria, etc. The program
has a mouse-driven graphical user interface with a helpful menu. It also has a nice snap-
to-grid feature; it's easy to edit, move, and align objects; etc. Documentation on xg is
available from the xg home page, http://www.xfig.org, and from http://duke.usask.
ca/~macphed/soft/fig/index.html
Figures are saved in simple ASCII les with the sux .g.
3
You can export xg gures to
various formats, including Encapsulated PostScript and other formats suitable for import to
L
A
T
E
X. The easiest way import an xg gure (myg.g) to L
A
T
E
Xis touse the menu to export
it from xg as an Encapsulated PostScript le (myg.eps) and then to import it to L
A
T
E
X
with nincludegraphicsfmyfig.epsg. Remember that you must nusepackagefgraphicxg
in the preamble to use this command.
It is possible to embed L
A
T
E
Xcode in the text of an xg gure; so you can use a full range
of symbols, subscripts, superscripts, etc. Trying to insert sub/superscripted characters by
hand is incredibly tedious and frustrating. To embed L
A
T
E
Xcode in an xg gure, you should
3Infact,youcanlearnhowtowritetoandtomanipulatetheselesdirectly.
12