Remove the double-spacing from estout

May 14, 2009 at 5:48 am 2 comments

| Gabriel |
As mentioned before, I love estout. However I dislike some of its features, such as that it leaves a blank line between rows. I wrote this code to go at the end of a do-file where it could clean all my tables and remove the gratuitous lines. You could also use it to accomplish other cleaning tasks or to clean other text-based files, including log files.

esttab using table_x.txt , se b(3) se(3) scalars(ll rho) nodepvars nomtitles  label title(Table X: THE NEW VARIABLES. 1936-2005) replace fixed
shell cp table_x.txt $tabledir
eststo clear
clear
set mem 250m
}
*clean the tables, eliminate extra lines
cd $parentpath
shell touch tmpfile
shell mv tmpfile filelist_text.txt
cd $tabledir
shell ls *.txt >”$parentpath/filelist_text.txt”
shell awk ‘{ gsub(“\.csv”, “”); print $0;}’ “$parentpath/filelist_text.txt” > tmp
shell mv tmp “$parentpath/filelist_text.txt”
shell perl -pe ‘s/\n/ /g’  “$parentpath/filelist_text.txt” > tmp
shell mv tmp “$parentpath/filelist_text.txt”
capture file close myfile
file open myfile using “$parentpath/filelist_text.txt”, read
file read myfile line
global filelist `line’
foreach file in $filelist  {
shell perl -ne ‘print unless /^$/’  `file’ > tmp
copy tmp `file’, replace
erase tmp
}
*each of several banks of regression commands throughout the code end with some variant on:
esttab using table_k.txt
shell cp table_k.txt $tabledir
*note, i prefer "shell cp" over the Stata command "copy" because "cp" assumes the target filename

*at the end of the do-files clean the tables
*this part merely seeds the loop and is adapted from my "do it to everything in the directory" post
cd $parentpath
shell touch tmpfile
shell mv tmpfile filelist_text.txt
cd $tabledir
shell ls *.txt >"$parentpath/filelist_text.txt"
shell perl -pe 's/\n/ /g'  "$parentpath/filelist_text.txt" > tmp
shell mv tmp "$parentpath/filelist_text.txt"
capture file close myfile
file open myfile using "$parentpath/filelist_text.txt", read
file read myfile line
global filelist `line'
*this is where the actual cleaning occurs
foreach file in $filelist  {
	shell perl -ne 'print unless /^$/'  `file' > tmp
	copy tmp `file', replace
	erase tmp
}

Entry filed under: Uncategorized. Tags: , .

Gretl Herd immunity, again

2 Comments

  • 1. ben  |  August 5, 2010 at 3:11 pm

    Hi Gabriel,
    there’s a -nogap- option. Simply type

    . estout …, nogap

    and the empty rows are gone.
    ben

    • 2. gabrielrossman  |  August 5, 2010 at 3:20 pm

      hi ben,
      i should have figured there was an option for this. thanks for writing such a great ado file


The Culture Geeks


%d bloggers like this: