Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Beginner questions re saving/storing/exporting graphs in Windows


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Beginner questions re saving/storing/exporting graphs in Windows
Date   Thu, 14 Oct 2010 09:49:47 +0100 (BST)

--- 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.
<http://www.stata-journal.com/article.html?article=pr0020>

Hope this helps,
Maarten

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

http://www.maartenbuis.nl
--------------------------


      

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index