help for dta2html

Title

dta2html --- Generate HTML code to display a Stata dataset on the web

Syntax

dta2html [varlist] [if] [in], saving(html_filename,[sub_option])
[pagetitle("title") tabtitle("title")
datalink("address") todisp("todisname", "txt"|"img") css("path")]

Description

dta2html generates minimum HTML code necessary to display a Stata dataset loaded in memory on the
web. At the completion of the process, an HTML file containing the code is created and placed in the
working directory, and two links are created. Whereas clicking on the first link will display the HTML
file contents in Stata's result window, clicking on the second link will display the data in Internet
Explorer, assuming you are running Windows and Internet Explorer is your default browser. To display
the data in Google Chrome, with Google Chrome being your default browser or not, follow these steps:
1) Open Google Chrome if it is not already open 2) While in Google Chrome, press "CTRL O" 3) Navigate
to the HTML file and select it 4) Finally click "Open."

dta2html is intended to provide a quick way to display a sample dataset on the web. Unless instructed
otherwise (e.g., varlist is specified), dta2html will provide HTML code for the entire dataset.

Stata 11.0 or higher is required.

Options

Options

saving(html_filename, sub_option) requests that the dataset be written to the file html_filename, where
html_filename is the name for the HTML file to be created. Extension .html will be added to the file name.
If sub_option, where sub_option must equal replace, is specified, dta2thml will overwrite an
existing file with the same name. This option is required.

pagetitle("title") specifies the browser page title; default is pagetitle("Stata Dataset in your Browser").

tabtitle("title") specifies a caption or a title for the displayed dataset; default is tabtitle("Stata Dataset").

datalink("address") provides a link where the displayed data or a related dataset can be downloaded. This can
be a web link or a link to a file on your personal computer (see examples below). Note that some web servers do not
allow uploading .dta files. In this case, you might want to save your .dta file to a compressed zip file. In the case
of a web link, you need to find out what the address is and then supply it with option datalink(). The link will be
placed on top of the displayed data in your browser.

todisp("dispname", txt|img) indicates whether to display the link as a clickable text or a clickable image.
Links sometimes look better when adorned with fancy image buttons. A not-so fancy button image to be used with option
datalink() is provided with dta2html. The file must be placed in the current directory. You can provide a file,
web or server address where your own fancy image file resides.

Option todisp() must be combined with datalink().

css("path") provides the cascading style sheet for the web page. dta2html provides the minimum HTML
code necessary for a nice looking page. To obtain a fancier look, you might want to provide your own CSS file using this
option and edit the tags appropriately, or you can just edit the provided style sheet after the creation of the HTML file.

Examples

1) Generate HTML code to display the auto dataset on the web

. sysuse auto, clear

. dta2html, saving(auto_dataset) pagetitle("The Auto Dataset in my Browser") tabtitle("Auto Dataset")

--> Click to run

2) Generate HTML code to display the auto dataset on the web and provide a link to download the data

. dta2html, saving(auto_dataset, replace) datalink("http://www.stata-press.com/data/r12/auto.dta") todisp("Download data from here", "txt")

//www.stata-press.com/data/r12/auto.dta") todisp("Download data from here", "txt")"':--> Click to run

3) Try the same thing on your PC but with the provided image file (dta2html_img.png) assumed to be saved to the current directory

. dta2html, saving(auto_dataset, replace) datalink("file:///`c(sysdir_base)'a/auto.dta") todisp("file:///`c(pwd)'/dta_img.png", "img")

///`c(sysdir_base)'a/auto.dta") todisp("file:///`c(pwd)'/dta_img.png", "img")"':--> Click to run

4) Specify a CSS file

. dta2html, saving(auto_dataset, replace) css("./mystyles.css")

Author

P. Wilner Jeanty, Rice University,

Email to pwjeanty@rice.edu.

Also see

hlp2html if installed