Haghish, E. F. (2014). Applied Statistics Using Stata.

Free Online Stata Tips & Tutorials. Data Management; Stata Graphs and Graphics; Data Analysis; Stata Programming; Advanced Statistics


Updated on 1 October 2015

Statax Package: do and ado to HTML convertor and syntax highlighter

| Quick Tips |     | Introduction |     | Installation |     | Using Statax |     | Syntax Highlighter Styles |     | Statax JavaScript |    

Quick Tips

Statax package converts do and ado files to HTML and highlight the syntax using Statax JavaScript Syntax Highlighter. The package allows users who are not familiar with web languages, to apply Statax syntax highlighter to their code files and create HTML documents.

ssc install statax /* installing Statax package */
statax using filename, replace append style(name) css(filename) /* create example HTML file */
statax convert filename, replace style(name) css(filename)/* convert do and ado files */

E. F. Haghish
Center for Medical Biometry and Medical Informatics
University of Freiburg, Germany
haghish@imbi.uni-freiburg.de
Twitter: @Haghish

Support further development of Statax (CodeMap Project)

Introduction

Statax Package is based on Statax JavaScript Syntax Highlighter that highlights Stata Commands, Functions, Strings, Local and Global Macrso, Comments, Operators, Numbers, and braces identical to Stata text editor, in web documents such as HTML, HTM, and XHTML. Here is an example:

* Introducing Statax package!
// JavaScript Syntax Highlighter for Stata

quietly erase "`This' $Example"
noisily do `Something' $Awesome
forvalues num = 5/13 {
    	count if vari`num' > 10
    	generate x = runiform()
}

/*
E. F. Haghish
Center for Medical Biometry and Medical Informatics
Unersity of Freiburg, Germany
*/

The Statax package aims to provide a quick way to:

  • Help Stata users who are not familiar with JavaScript and HTML, to get started with Statax JavaScript program
  • Provide a built-in example that can be edited by the users
  • Convert do and ado files to HTML and automatically highlight the syntax

Installation

Statax package is hosted on SSC server and can be installed by typing the following command in Stata

ssc install statax /* installing Statax package */

Using Statax

In order to use Statax for highlighting Stata code, the code should be wrapped with a <pre> tag and sh_stata class as shown below. The <pre> tag preserves the white-space and the sh_stata class refers to the class of CSS style sheet that defines the color of each Stata syntax element.


<pre class="sh_stata"> . Stata code . Stata code ... <pre>

Syntax Highlighter Styles

Statax Package comes with four built in CSS documents. These styles can be specified using the style(name) option. The available styles are stata (default), daring, sunset, and wrangler. A preview of these styles is shown below respectively.

Statax JavaScript

Statax JavaScript and CSS files can be downloaded on this page.