Convert a log to a do-file

August 28, 2009

| Gabriel |

I was looking at some old files (untouched for about 18 months) and realized that I’d done everything in Stata interactive mode (boo, hiss), but at least had enough semblance of responsibility to keep a log file. Wanting to do it right from here on (ie, do everything from scripts and always start from the raw data) I wrote a simple bash shell script to change a log file into a do file. In this script “foo” is the name of your log file. If for some reason you use smcl, first translate to text (the “.log” extension) using Stata’s “translate” command.

grep '^\. ' foo.log > foo.do
awk '{ gsub("^\. ", ""); print $0;}' "foo.do" > tmp.do ; mv tmp.do foo.do

Note that the do-files generated from your log-files are not ready to run and must be hand-cleaned for several reasons, including but not limited to:

  • This code makes no attempt to check whether Stata choked on the command.
  • This code doesn’t keep long commands that are separated by a hard return.
  • This code leaves in commands like “help” and “browse” that are only useful in interactive mode.

It would be technically feasible to write a script that wouldn’t have these limitations but it’s a pain (most Unix commands look at data one line at a time so it’s hard to edit text across multiple lines) and I figured there’s more bang for the buck to writing the simpler version since even a better version should probably still be hand-checked.

Entry Filed under: Uncategorized. Tags: , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


The Culture Geeks

Tags

bayesian cleaning culture diffusion economics economic sociology ethnomethodology financial crisis graphs history IMDB loops lyx macros networks phenomenology philosophy of science R random variables regular expressions resampling shell sociology of organizations sociology of science st Stata superstar text editor typesetting

Archives

Recent Posts

Recent Comments

Blogroll