Jeph Herrin wrote:
After many years of resistance, I am trying my hand
at generating attractive reports directly from Stata
via SMCL. I have run into a quietly/noisily problem.
The general idea is that I have to create a massive
set of tables of variables that are one of several
types. I can trap their type, and then depending on
their type I call a program which takes an integer
argument to determine if the table will run off the
page; if so, I want to insert a {newpage} first, and
reset the line counter accordingly.
[code redacted]
The problem is that the program -checkend- is NOT producing
any output.
When I take the contents of the program and paste it into
each location, everything works fine. However, there are 10
different types of variables, and when I fiddle with the font
and header, I have to go back through and edit each one. It
will be much better if I can keep it in a program.
I CAN get -checkend- to produce output by using
noi di as smcl "{newpage}"
but then what I get isn't smcl, and the postscript translator
produces something that is broken (ie, can't be translated to
PDF). Moreover, the log file is defined as SMCL, so this seems
superfluous.
I'm thinking the problem may be that the log file -mylog- isn't
passing to the program? I have to use a named log file because
I need a second log file open to track some other output for
each variable.
Otherwise, it must be that I'm not using quietly noisily
correctly, but I thought
quietly noi myprog
would let -myprog- output whatever it wanted to.
--------------------------------------------------------------------------------
I'm not sure what your problem is, but it might be that you have a few too
many quietly-noisily-quietly-noisily recursions in your code. The do-file
below does the kind of thing that you're trying to do with regard to page
breaks. It and its imbedded called program produce output in the log files
in accordance with when the -noisily- command qualifier is used. In
addition, when the called program uses the -in smcl- directive for the page
break (as in the "yourlog" example), it produces page breaks properly. (It
doesn't, of course, when the -_asis- directive is used, as in the "mylog"
example below.) The SMCL log files produced aren't broken, either, because
ultimate Portable Document Format (PDF) files produced are okay, regardless
of whether printed via PDFCreator from a View window of the SMCL log file
within Stata or by converting from -translate-'s PostScript file to PDF from
within GSview.
Joseph Coveney
Note that -pagem- isn't doing any keeping track of line counts; it's just
producing output and SMCL page-break directives.
clear *
set more off
*
program define pagem
version 10
syntax , logfile(string) [Smcl]
local type = cond("`smcl'" == "", "_asis", "in smcl")
quietly log on `logfile'
forvalues page = 1/2 {
if `page' == 2 display `type' "{newpage}"
forvalues line = 1/10 {
display `type' "Called program " _continue
display "Page `page' of 2, line `line' of 10"
}
}
quietly log off `logfile'
end
*
capture log close mylog
capture log close yourlog
quietly {
log using mylog.smcl, smcl name(mylog) replace
log off mylog
log using yourlog.smcl, smcl name(yourlog) replace
log off yourlog
}
quietly foreach stuff in here there everywhere {
log on mylog
if "`stuff'" != "here" noisily display in smcl "{newpage}"
noisily display in smcl as text "Do-file loop item: `stuff'"
log off mylog
noisily pagem, logfile(mylog)
log on yourlog
if "`stuff'" != "here" noisily display in smcl "{newpage}"
noisily display in smcl as text "Do-file loop item: `stuff'"
log off yourlog
noisily pagem, logfile(yourlog) smcl
}
quietly {
log close mylog
log close yourlog
}
translate mylog.smcl mylog.ps, replace
translate yourlog.smcl yourlog.ps, replace
exit
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/