Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: RE: RE: Plots: save, log, ...

From   "MA V" <>
Subject   RE: Re: st: RE: RE: Plots: save, log, ...
Date   Wed, 17 May 2006 19:19:18 +0000

Thanks for all your help!

From: "David Harrison" <>
To: <>
Subject: RE: Re: st: RE: RE: Plots: save, log, ...
Date: Tue, 16 May 2006 13:23:41 +0100

I missed some of the earlier posts on this thread being off Statalist
for a few days, but as far as I can see no-one has mentioned the program
-log2html- available from SSC (-ssc describe log2html-). This makes use
of an undocumented command -log html- to convert smcl log files to html.

As smcl files cannot contain graphics, this does not quite answer your
question, but it is a pretty straightforward process to get around this.
First, I write two new little commands: -htmlgph1- and -htmlgph2-.

-htmlgph1- exports a graph and writes the line of html to include it...

prog htmlgph1
    syntax anything(name=filename id="filename") [, htmlopts(string) *]
    qui graph export `filename', `options'
    local filename `filename'
    display as text `"<img src="`filename'" `htmlopts'>"

Now when log2html is run, it cleverly converts the "<" and ">" to "&lt;"
and "&gt;", so we need to change them back...

prog htmlgph2
    syntax anything(name=filename id="filename")
    tempfile f1 f2
    tempname h1 h2
    copy `filename' `f1'
    file open `h1' using `f1', read
    file open `h2' using `f2', write
    file read `h1' newline
    while r(eof)==0 {
        if substr(`"`newline'"',1,12)=="&lt;img src=" {
            local newline : subinstr local newline "&lt;" "<", all
            local newline : subinstr local newline "&gt;" ">", all
        file write `h2' `"`newline'"' _n
        file read `h1' newline
    file close `h1'
    file close `h2'
    copy `f2' `filename', replace

So now the process is:
1. Log your output in a smcl log
2. Whenever you want a graph included in the log, export it with
-htmlgph1- instead of -graph export-
3. When you have finished, run -log2html- to convert the smcl file to
4. Run -htmlgph2- once to make the final corrections to the html file
You now have an html log file including graphics!


cd c:\temp\log2html
sysuse auto
log using test
sum price mpg
scatter price mpg
htmlgph1 graph1.wmf, htmlopts(width=100%)
log close
log2html test
htmlgph2 test.html

Hope this helps


This email has been scanned by the MessageLabs Email Security System.
For more information please visit

*   For searches and help try:
Donít just search. Find. Check out the new MSN Search!

* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index