benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
70 stars 17 forks source link

Is that possible to add two rows using refcat? #44

Closed fredericky123 closed 2 years ago

fredericky123 commented 2 years ago
sysuse auto,clear
eststo clear
eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign

esttab using output.rtf,refcat(_cons "{\b {\i Variables of main interests}}",nolab below) order(_cons) replace

The below is what I expected, two rows including "Controls" and "Variables of interest"

image
benjann commented 2 years ago

Not sure. You could do the following:

sysuse auto,clear
eststo clear
eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign

esttab using ~/output.rtf, order(_cons) replace indicate({\b Controls} = foreign) ///
    refcat(_cons "{\b {\i Variables of main interests}}", nolab below) 

But maybe this is not what you want...

dreistein543 commented 2 years ago

just focus on your case above, I suggest using indicate() function to specify your Control Variables.

sysuse auto, clear

// since you did not specify any control variable, I use variable “length” as one.
eststo: quietly regress price weight mpg length
eststo: quietly regress price weight mpg foreign length

esttab using output.rtf, ///
refcat(_cons "{\b {\i Variables of main interests}}",nolab below) ///
order(_cons length) replace ///
indicate(“{\b Controls}” = length, label(“{\i \b include}” “”))

and you shall get DB3145C5-C30E-4722-8EE8-EC72969CC0D6

fredericky123 commented 2 years ago

This an elegant alternative way, can we set the order of "controls" before "Variables of interest"

Thanks you all for your help!!

benjann commented 2 years ago

can we set the order of "controls" before "Variables of interest"

Cannot think of an easy solution. An approach could be to use varlabels(,elist()) to construct additional rows in the table. This is a bit involved because you have to write the complete RTF code of the row. Here's an example that can be used as a template:

sysuse auto,clear
eststo clear
eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign

local B  "{\trowd\trgaph108\trleft-108@rtfrowdef\pard\intbl\ql {"
local D  "}\cell \pard\intbl\qc {"
local E  "}\cell\row}`=char(13)'"
local c  "\b Controls"
local i  "\b\i included"
local ni "\b\i not included"
local v  "\b\i Variables of main interest"
esttab using ~/output.rtf, order(_cons) replace ///
    varlabels(,elist(_cons "`B'`c'`D'`ni'`D'`i'`E'`B'`v'`D'`D'`E'"))

Local B contains the definition of the beginning of a table row (estout will internally substitute @rtfrowdef with appropriate code; this is undocumented). Local D contains code that goes between table cells. Local E contains code that terminates the row (=char(13) adds a line break). ben

fredericky123 commented 2 years ago

Thanks so much!