# Example of a MarkDoc document

## Standard Features

### Some simple Stata input and output

Here is a regression example using the obligatory `auto` dataset, using good physics

          .  clear

          . sysuse auto
          (1978 Automobile Data)

          .  gen gp100m = 100/mpg

          . regress gp100m weight displacement gear_ratio foreign

                Source |       SS           df       MS      Number of obs   =        74
          -------------+----------------------------------   F(4, 69)        =     56.84
                 Model |  91.7374232         4  22.9343558   Prob > F        =    0.0000
              Residual |  27.8388375        69  .403461414   R-squared       =    0.7672
          -------------+----------------------------------   Adj R-squared   =    0.7537
                 Total |  119.576261        73  1.63803097   Root MSE        =    .63519

          ------------------------------------------------------------------------------
                gp100m |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                weight |   .0014428    .000216     6.68   0.000     .0010118    .0018737
          displacement |   .0012388   .0021161     0.59   0.560    -.0029828    .0054603
            gear_ratio |  -.2037991   .3258603    -0.63   0.534    -.8538726    .4462744
               foreign |    .733736   .2301493     3.19   0.002     .2746007    1.192871
                 _cons |   .8147969   1.239181     0.66   0.513    -1.657301    3.286895
          ------------------------------------------------------------------------------

### Including a result in the body of a sentence.

This is useful for including results in sentences in a paper.

Markdoc can use inline expansion. As an example, we can see that the coefficien t for the foreign variable is 0.734. It is, however, a shortcoming that any par agraph including an inline result must all be in a `txt` command in the Stata p ortion of the file.

Note that the next paragraph can be written as a standard paragraph.

### Including a graph

Here is an example scatterplot command:

          .  twoway (scatter gp100m weight if !foreign) ///
             (scatter gp100m weight if foreign), ///
             legend(order(1 "US" 2 "Non-US"))

Here is the graph.

An example scatterplot

### Hiding commands and showing only results

It can be useful to hide commands and show just their output. Here, for example, is the output from a summarize command:

              Variable |        Obs        Mean    Std. Dev.       Min        Max
          -------------+---------------------------------------------------------
                gp100m |         74     5.01928    1.279856   2.439024   8.333333
                weight |         74    3019.459    777.1936       1760       4840
          displacement |         74    197.2973    91.83722         79        425
            gear_ratio |         74    3.014865    .4562871       2.19       3.89

Showing just commands works similarly.

Showing just commands or output is done line by line.

### Splitting input and output.

Markdoc cannot directly split input and output from Stata commands. This is typical for programs producing documents directly from Stata log files, because Stata itself mixes input and output in its log files. It is possible to split output by running commands multiple time and sometimes showing the comma nd, sometimes showing the output.

## Some other features to check

### Showing Mata code and output

Here is some Mata code. We don't want to see the output from the initial mata co mmand, so we can hide it.

          .  mata
          ------------------------------------------------- mata (type end to exit) -------
          : X = (76, 53, 48 \ 53, 88, 46 \ 48, 46, 63)

          : Xi = invsym(X)

It is useful to see the output from checking that Xi is really the inverse of X.

          : Xi*X
                            1              2              3
              +----------------------------------------------+
            1 |             1   -1.11022e-16   -1.11022e-16  |
            2 |  -1.11022e-16              1              0  |
            3 |             0              0              1  |
              +----------------------------------------------+

          : end
          ---------------------------------------------------------------------------------

          . quietly log close example_md