Auto-Tabulate Regression Results in Stata for Publication

Jun 21, 2019

This post describes a convenient way to automate the tabulation of regression outputs in Stata for publication.

Setup and Usage

First, you’ll need to be familiar with program in Stata, which essentially is a function or macro to be called elsewhere in the .do file.

What I like to do is to store all control variables in a macro controls. For example, let’s control for Tobin’s Q, firm size, book leverage, cash holding, sales and ROA.

capture global controls "q size bleverage cash sale roa"

If we are to do a panel regression where we have four different dependent variables to examine, and we control for both industry fixed effect and year fixed effect. We cluster standard errors at the firm level. A sample program may look like this:

capture program drop panelRegression
program panelRegression
    args controls
    eststo clear
    eststo: quiet reghdfe dependent1 c.treat##c.post  $`controls', absorb(industry year) vce(cluster stkcd)
    eststo: quiet reghdfe dependent2 c.treat##c.post  $`controls', absorb(industry year) vce(cluster stkcd)
    eststo: quiet reghdfe dependent3 c.treat##c.post  $`controls', absorb(industry year) vce(cluster stkcd)
    eststo: quiet reghdfe dependent4 c.treat##c.post  $`controls', absorb(industry year) vce(cluster stkcd)
    local c_date = c(current_date)
    local c_time = c(current_time)
    local c_time_date = "`c_date'"+"_" +"`c_time'"
    local time_string = subinstr("`c_time_date'", ":", "_", .)
    local time_string = subinstr("`time_string'", " ", "_", .)
    display "`time_string'"
    esttab using "path\to\your\project\panelRegression_`time_string'_.csv", label r2 ar2 interaction(" X ") star(* 0.10 ** 0.05 *** 0.01) nogaps b(3) t(3) ar2(3) r2(3)
    esttab, label r2 ar2 interaction(" X ") star(* 0.10 ** 0.05 *** 0.01) nogaps b(3) t(3) ar2(3) r2(3)
    eststo clear
end

It uses reghdfe for fast panel regression with multi-dimensional fixed effects and the eststo package for tabulation. The results are stored in a .csv file named with the current date and time.

To run the regression, simply use:

panelRegression controls

And the result will be available in the destination folder specified in the program.

Example

An example output will be:

demo output

comments powered by Disqus