Bookmark and Share

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]

--- On Thu, 14/10/10, Benhoen2 wrote:
> I need a quick primer on how to get multiple graphs from the
> graph window into a file that then I can save for later, send
> to others.

The easiest way of doing that is probably to create a .html file.
To create such a file you can use the -file open-, -file write-,
and -file close- commands. 

A minimum file will use two html tags (="html commands"):

1) <img src = "file.ext">, which includes the graph stored in
file.ext in the webpage. To do that you need to have stored your
graphs using an extension that can be readily read in webbrowsers,
.png is a common format for that.

2) <br> tells that you want to start a new line.

An example of such a miminum file looks like this. The code creates
an html document c:\temp\basic.html.

*------------begin basic example -------------------
cd "c:\temp"
file open basic using basic.html, write replace

sysuse auto, clear
foreach var of varlist mpg-trunk {
    hist `var'
    graph export `var'.png, replace
    file write basic `"<img src="`var'.png"> <br>"' _n
file close basic
*----------- end basic example ----------------------

If you know a bit more html, you can add more bells and wistles, like
the example below:

*------ begin example with bells and wistles ----------
cd "c:\temp"
file open graphs using graphs.html, write replace
file write graphs `"<html><body>"'
file write graphs `"<p>You can write comments on top of the file</p>"' _n

sysuse auto, clear
foreach var of varlist mpg-trunk {
    hist `var'
    graph export `var'.png, replace
    file write graphs `"<p>You can also type some comments above each"'
    file write graphs `" graph, like the name of the variable being"'
    file write graphs `" plotted: <b>`var'</b>.</p>"' _n 
    file write graphs `"<img src="`var'.png"  width="484" height="322""' 
    file write graphs `" alt="histogram of `var'"> <br>"' _n

file write graphs `"<p>You can write comments at the bottom"' 
file write graphs `"of the file</p>"' _n
file write graphs `"</body></html>"'
file close graphs
*------ end example with bells and wistles ----------

A text that expands on this basic approach can be found in:

Rosa Gini and Jacopo Pasquini (2006) "Automatic generation of 
documents", The Stata Journal, 6(1):22--39.

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index