# Dynamic Markdown Documents with Stata

Stata has the ability to process text documents written with unexecuted Stata code and Markdown formating, and produce HTML documents. Paired with Pandoc, this is also capable of producing Word and PDF documents.

Take for example the following document, "ttest example.stmd".

``````# Homework 5
#### Doug Hemken

Demonstrate a two-group t-test using Stata.  Illustrate with a box plot.

First, simulate some data.

```{stata}
clear
set obs 2
generate group = _n - 1
expand = 15
generate y = rnormal(group)
```

Let's check the data we created.

```{stata}
table group, contents(freq mean y sd y semean y) row
```

Next, do the t-test.

```{stata}
ttest y, by(group)
```

Finally, a box plot.

```{stata}
graph box y, by(group)
```
``````

In Stata this may be processed with the following command

``````stmd "ttest example.stmd"
``````

which produces a file named "ttest example.html". The contents of this file are included below.

# Homework 5

#### Doug Hemken

Illustrate a two-group t-test using Stata. Illustrate with a box plot.

First, simulate some data.

``````. clear

. set obs 2
number of observations (_N) was 0, now 2

. generate group = _n - 1

. expand = 15
(28 observations created)

. generate y = rnormal(group)

``````

Let’s check the data we created.

``````. table group, contents(freq mean y sd y semean y) row

----------------------------------------------------------
group |      Freq.     mean(y)       sd(y)      sem(y)
----------+-----------------------------------------------
0 |         15   -.0062374    .6081133    .1570142
1 |         15    .7164829    .8867842    .2289667
|
Total |         30    .3551227    .8326126    .1520136
----------------------------------------------------------

``````

Next, do the t-test.

``````. ttest y, by(group)

Two-sample t test with equal variances
------------------------------------------------------------------------------
Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
0 |      15   -.0062374    .1570142    .6081134   -.3429993    .3305246
1 |      15    .7164829    .2289667    .8867842    .2253982    1.207568
---------+--------------------------------------------------------------------
combined |      30    .3551227    .1520136    .8326126    .0442201    .6660254
---------+--------------------------------------------------------------------
diff |           -.7227203    .2776314               -1.291422   -.1540181
------------------------------------------------------------------------------
diff = mean(0) - mean(1)                                      t =  -2.6032
Ho: diff = 0                                     degrees of freedom =       28

Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
Pr(T < t) = 0.0073         Pr(|T| > |t|) = 0.0146          Pr(T > t) = 0.9927

``````

Finally, a box plot.

``````. graph box y, by(group)

``````