Skip to content

Regression tables

outwrite reads multiple regressions saved with estimates store, consolidates them into a single table, and exports the results to a .xlsx, .xls, .csv, or .tex file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  sysuse auto.dta, clear
    reg price i.foreign##c.mpg
    est sto reg1
    reg price i.foreign##c.mpg##i.rep78
    est sto reg2
    estadd scalar h = 4
    reg price i.rep78
    est sto reg3
    estadd scalar h = 2.5

  outwrite reg1 reg2 reg3 using "test.xlsx" ///
   , stats(N r2 h)  replace col("TEST" "(2)") drop(i.rep78) format(%9.3f)

Writing regression tables to common filetypes in Stata.

Alternatively, as a programming command, it will accept a single matrix and print that; it will also look for matrix_STARS and affix that number of stars to each cell.

Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  outwrite estimates_1 estimates_2 [...]
    using /path/to/output.[xlsx|xls|csv|tex] ,
    [replace stats() drop(varlist)]
    [tstat|pvalue] [format(format)]
    [sheet(sheetname [,replace]) modify]
    [rownames("list" "of" "names") colnames("list" "of" "names")]

  ------------------------------------------------------------------------------------------
    Options

      replace         Allows outwrite to overwrite the output file.
      stats()         Adds statistics from e() at the bottom of the table, such as N, r2,
                        or scalars added by estadd.
      drop(varlist)   Suppresses reporting of all variables in in varlist from the output.
                        This can be a factor variable list.
      tstat|pvalue    Reports T-statistics or P-values in regression table, instead of the
                        default standard errors.
      format(format)  Format the table values. By default this is %9.2f.
      sheet()         Place results in a target sheet if using .xlsx format.
      modify          Allows outwrite to modify the output file. Often required with
                        sheet() to work as expected.
      rownames()      Manually renames rows of output. By default, the rows are named to
                        reflect the variables in the estimation command.
      colnames()      Manually renames columns of output. By default, the columns are
                        named to reflect the saved equation names.
    --------------------------------------------------------------------------------------
    Note: if used to export a matrix, stats(), drop(), and tstat|pvalue will not be
    accepted.

Acknowledgments

While the concept of outwrite is original, we borrowed core functionality from xml_tab by Zurab Sajaia and Michael Lokshin, and many ideas from such programs as estout by Ben Jann, outreg by John Luke Gallup, outreg2 by Roy Wada, modltbl by John H. Tyler, mktab by Nicholas Winter, outtex by Antoine Terracol, and est2tex by Marc Muendler.

outwrite is available on SSC and is open for development on GitHub. Submit bugs and feature requests here. If you like outwrite, be sure to visit my homepage and Stata boilerplate code.