Stata is a statistical software package popular in the economics field.

Stata Markdown is a user-written package that allows one to use the code-editor (DO Editor) to combine text and code to create html/pdf output.

Getting Started

Start with a .stmd and open it. .stmd is the file format for “STATA markdown” and we provide a template that you can download here

Now move this file to a folder you created for your STATA assignment.

Example 1: Load data and create html

Let’s use a modified version of the Police Violence Data Source: Mapping Police Violence that documents victims of police violence. Download this example dataset and move it to your STATA assignment folder.

Set the path

Open the Stata Markdown file .stmd. Change the path to the assignment folder where the markdown file and dataset reside.

cd "PATH NAME

cd "PATHNAME"

How to find the path

Code Fences

STATA Markdown uses code fences to denote code chunks. Each code chunk starts with ```{s} and ends with ```.

To load the data

use pviolence_example.dta, clear

Run Chunks

To run a code chunk, highlight the chunk, and then select “DO”.

Create html output

To create a final .html file that combines text, code, and results go to the Command line and type.

markstat using Stata_Markdown_example1

Example 1 .stmd file and .html output.

Example 2: Import .csv and histograms

Import .csv file

Let’s load this .csv file into STATA

import delimited "pviolence_example.csv", clear 

Histograms

histogram vicblack_per000, width(3)
graph export vicblack_per000.png, width(500) replace

Then to insert the .png histogram you will include the following OUTSIDE of the code block.

![Black Victims of Police Violence](vicblack_per000.png)

Create html output

To create a final .html file that combines text, code, and results go to the Command line and type.

markstat using Stata_Markdown_example2

Example 2 .stmd file and .html output.

** Yes, there is a certain irony involved with writing a guide for Stata Markdown in R Markdown. Until Stata has a similar RPubs site, this is the way.