8 Stata Output as Tables
library(Statamarkdown)
8.1 Overview
To include tables of Stata output in a document’s text (as opposed to including Stata output in a specially formatted output block), requires three steps
- save the Stata output in a form that can be used for a table
- read the output into R as a matrix or data frame
- display the output with
knitr::kable
8.2 Saving Stata output
Example data set:
sysuse auto
(1978 automobile data)
Use Stata’s putexcel
command to save a table of results.
quietly regress mpg weight displacement
quietly putexcel set regress.xlsx, replace
matrix coef = r(table)'
matrix(coef), names
putexcel A1 =
quietly putexcel save
file regress.xlsx saved