Bookmark and Share

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


[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 <[email protected]>
To   [email protected]
Subject   RE: st: Beginner questions re saving/storing/exporting graphs in Windows
Date   Mon, 18 Oct 2010 10:55:06 +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.

--- On Thu 14/10/10, Maarten Buis wrote 
> > 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 ----------------------

--- On Mon, 18/10/10, Garry Anderson wrote:
> The basic.html file that is created by Maarten's code does not seem to
> contain the .png files when the basic.html file is sent to others. Ben's
> requirement was that he sends the basic.html file to other
> users so that they can see the graphs.
> 
> Is there a method to embed the .png files into the .html file so that
> when the .html file is opened on another computer the graphs are
> visible? 

.html files are basically plain text files that contain links to other
element, like pictures. So Ben should take care to sent a the .png 
files together with the .html file.

Alternatively, you could expand the basic file a bit, like this:
*------------begin basic example ------------------- 
cd "c:\temp"
file open basic using basic.html, write replace
file write basic `"<html><body>"' _n  // <-- new
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 write basic `"<\body><\html>"' _n // <-- new
file close basic
*----------- end basic example ----------------------

Now you should be able to open it in MS Word and save it as a 
Word file, such that the graphs are embedded.

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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index