Create custom output files using @statdocrun - mas802/statdoc GitHub Wiki

This is a feature introduced in statdoc v0.9.2-beta

Statdoc allows you to leverage its templating engine to produce custom output files. You can do this by adding the marker @statdocrun to the first documenting comment of a do file.

/**
 * example for using statdocrun
 *
 * @author Markus Schaffner
 * @statdocrun do
*/

This do file no be run by statdoc automatically when it processes the folder. So you must make sure the path in the file are set up such that it can run this way.

You can then store information by just displaying it in the statdoc key-value format (@key value).

sysuse auto, clear

sum price
di "@N " %9.0f `r(N)'
di "@max " %9.2f `r(max)'
di "@min " %9.2f `r(min)'

Then you can use this data in custom velocity templates that you have to put in the statdoc/templates folder. There is already a template called dumpdata.vm, which just prints out all available data in a txt format. You can invoke is like this:

di ">>>>> dumpdata.vm -> dumpdata.txt"

Of course it is more useful to write your own templates. You can access the data in a map called $data either directly ( $data.N ) or by invoking get ( data.get( "N" ) ).

templates/custom.vm

<html>
<body>

<h1>$data.title</h1>

<table>
	<tr>
		<td>N</td>
		<td>$data.N</td>
	</tr>
	<tr>
		<td>max</td>
		<td>$data.get( "max" )</td>
	</tr>
	<tr>
		<td>min</td>
		<td>$data.get( "min" )</td>
	</tr>
</table>

<p>Produced by statdoc</p>

Then you can invoke this the same way as before.

sum price
di "@N " %9.0f `r(N)'
di "@max " %9.2f `r(max)'
di "@min " %9.2f `r(min)'
di "@title Custom Template Output"

di ">>>>> custom.vm -> custom.html"

The real power of this of course comes now that you can run this in a loop for different categories:

levelsof foreign, local( groups )

foreach group of local groups {
	sum price if foreign == `group'
	di "@N " %9.0f `r(N)'
	di "@max " %9.2f `r(max)'
	di "@min " %9.2f `r(min)'
	di "@title Custom Template Output for Group `group'"

	di ">>>>> custom.vm -> custom_`group'.html"
}
⚠️ **GitHub.com Fallback** ⚠️