Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: RE: Output regression table with significance at some level indicate in bold font

 From "Andreas Peichl" To Subject st: RE: Output regression table with significance at some level indicate in bold font Date Thu, 9 Dec 2010 17:35:10 +0100

Dear Statalisters,

I've asked a question about highlighting the significant results in bold (ot
italics) after -estab- (see below). I was asked whether I found a solution.
I did it manually - and so far it heavily depends to the exact layout of my
table. Maybe it is helpful for someone. Any comments and suggestions are of
course welcome.

Cheers,
Andreas

The code works as follows:
file open original using results/tab'.tex, read text
file open new using results/tab'_bold.tex, write replace
local linenum = 0
while r(eof)==0 {

you read in the tex table from esttab

at the end, it will be written to another file:
file write new "macval(newline)'"' _n
}
file close original
file close new

in between is the manipulation of each line using tex codes and regular
expressions.

e.g.:
if
regexm("ww''","^(.*)\sym{.*}&$") == 1 { //.* --> bold for 3 stars if CONSline' == 0 local to = "\textbf{" + regexs(1) +"}&" else if CONSline' == 1 { local expres = regexs(1) local expres : subinstr local expres "\" "" , all local to = "\textbf{expres'}&" if regexm("expres'","^(.*)\.[0-9][0-9][0-9]$") == 1 local to = "\textbf{" +
regexs(1) +"}&"
}
local newword : subinstr
local ww' "ww''" "to'", all
local newword : subinstr
local newword "\}&" "}&", all
} // if

This searches for anything that end with "\sym{.*}&" In the tex code and
replace it with \textbf{ anything }

At the end, I define a macro newline which will then be written to the file:

local newline "newline'newword' "
mac shift
} // w / while

I hope this helps.

Cheers,
Andreas

Here is the full code:

cap file close _all
file open original using results/tab'.tex, read text
file open new using results/tab'_bold.tex, write replace
local linenum = 0
while r(eof)==0 {
local linenum = linenum' + 1
*display %4.0f linenum' _asis "  macval(line)'"'
*** local    lclname [=exp | :extended_fcn |
[]"[string]"['] ]
local oldline "macval(line)'"'
*** word count /  word # of
*local words : word count "oldline' "
tokenize "oldline'"
local newline ""
local w 0
while "1'" !="" {
local w= w' + 1
local ww' 1'
if w' ==1 {
local ww' : subinstr local ww'
"BVmX\_" "", all
local ww' : subinstr local ww'
"u\_Vm" "Unobserved", all
if "ww''" == "Constant" local
CONSline = 1
else local CONSline = 0
} // if
***  subinstr local mname "from" "to", all
word
local newword "ww''" //
"macval(oldline)'"'
if linenum'>=7 { // lines 1-6 are headers
necessary prob with mutlicolumn line; be careful if using different esstab
options !!!
if
regexm("ww''","^(.*)\sym{.*}&$") == 1 { //.* --> bold for 3 stars if CONSline' == 0 local to = "\textbf{" + regexs(1) +"}&" else if CONSline' == 1 { local expres = regexs(1) local expres : subinstr local expres "\" "" , all local to = "\textbf{expres'}&" if regexm("expres'","^(.*)\.[0-9][0-9][0-9]$") == 1 local to = "\textbf{" +
regexs(1) +"}&"
}
local newword : subinstr
local ww' "ww''" "to'", all
local newword : subinstr
local newword "\}&" "}&", all
} // if
if
regexm("ww''","^(.*)\sym{.*}\\") == 1 { // end of line 3 stars
if CONSline' == 0 local to
= "\textbf{" + regexs(1) +"}\\"
else if CONSline' == 1 {
local expres =
regexs(1)
local expres :
subinstr local expres "\" "" , all
local to =
"\textbf{expres'}\\"
if
regexm("expres'","^(.*)\.[0-9][0-9][0-9]$") == 1 local to = "\textbf{" + regexs(1) +"}\\" } local newword : subinstr local ww' "ww''" "to'", all local newword : subinstr local newword "\}\\" "}\\", all } // if if regexm("ww''","^(.*)\sym{\*\*}$") == 1 { //.*   --> bold italics for 2
stars
if CONSline' == 0 local to
= "\textbf{\emph{" + regexs(1) +"}}"
else if CONSline' == 1 {
local expres =
regexs(1)
local expres :
subinstr local expres "\" "" , all
local to =
"\textbf{\emph{expres'}}"
if
regexm("expres'","^(.*)\.[0-9][0-9][0-9]$") == 1 local to = "\textbf{\emph{" + regexs(1) +"}}" } local newword : subinstr local ww' "ww''" "to'", all local newword : subinstr local newword "\}}" "}}", all } // if if regexm("ww''","^(.*)\sym{\*}$")
== 1 { //.*   --> bold for 1 stars
if CONSline' == 0 local to
= "\emph{" + regexs(1) +"}"
else if CONSline' == 1 {
local expres =
regexs(1)
local expres :
subinstr local expres "\" "" , all
local to =
"\emph{expres'}"
if
regexm("expres'","^(.*)\.[0-9][0-9][0-9]\$") == 1 local to = "\emph{" +
regexs(1) +"}"
}
local newword : subinstr
local ww' "ww''" "to'", all
local newword : subinstr
local newword "\}" "}", all
} // if
local newword : subinstr local
newword "\sym{***}" "\textbf{bold}", all
local newword : subinstr local
newword "\textbf{}" "\textbf{bold}", all
local newword : subinstr local
newword "\textbf{\emph{}}" "\textbf{\emph{bold italics}}", all
local newword : subinstr local
newword "\emph{}" "\emph{italic}", all
} // linenum if
local newline "newline'newword' "
mac shift
} // w / while
file write new "macval(newline)'"' _n
}
file close original
file close new
} // foreach tab

________________________________________
From: Stephanie Vermeer [mailto:vermeerstephanie@gmail.com]
Sent: Monday, December 06, 2010 7:20 PM
To: a.peichl@wiso.uni-koeln.de
Subject: Stata

Dear Andreas,

Did you find already an solution to highlight the significant results in
bold, using stata and -esttab- or -estout-? I'm dealing with the same
question!

Stephanie

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Andreas Peichl
Sent: Saturday, October 16, 2010 7:35 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Output regression table with significance at some level
indicate in bold font

Dear Statalisters,

I'm estimating regression models for 27 different countries and I'm using
-estout- and / or -eststo-, -esttab- to output the regression results to
LaTeX. The tables are getting rather big and I would like to highlight the
significant results in bold (ot italics) and surpress the standard errors /
t-stats as well as the "stars". Is it possible to do this with -estout- (I
couldn't find it in the help) or with any other program?

Any help is appreciated.
Cheers,
Andreas

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
`