Convert a log to a do-file

August 28, 2009 at 5:31 am 1 comment

| 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 >
awk '{ gsub("^\. ", ""); print $0;}' "" > ; mv

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

Production of culture Appropriateness, professionalism, the body, etc

1 Comment

The Culture Geeks

%d bloggers like this: