benjann / estout

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

is there any method to separate the interaction terms into two rows? #49

Open dreistein543 opened 2 years ago

dreistein543 commented 2 years ago

if our models contain interaction terms, considering the length of their name/label, the table may be too wide, especially when you output too many models once a time.

many journals display their interactive terms as a two row thing as follow:

截屏2022-11-04 11 37 20

the first term is the default result of esttab while the second term is what I want so that i can reduce the width of my table and it could fit the textwidth.

have i miss something esttab can do? or is it tricky?

NilsEnevoldsen commented 2 years ago

It's tricky.

Here's an excerpt from my own code that does this. Maybe you can adapt it for your purposes.

// HERE BE DRAGONS
// The following lines takes the last item of the triple interactions — whether VariableC or VariableD — and puts
// them onto new lines (the line with the standard errors).
// I think this flavor of sed might only work on macOS, and you'd need to change the hardcoded path names.
// (Update: as of macOS Catalina and the switch to zsh from bash, some of the triple backslashes below are now sextuple backslashes.)
// It's very difficult to pass the appropriate paths through while handling the tilde and spaces correctly.
// What is this doing exactly? Well by uncommenting the following "echo" command, you'll see the command that actually
// gets passed to bash. 
*  shell echo sed -Ei '.orig' 's/(\\$\\times\\$ )VariableC(.*)$/\1\\ldots\2'$'\\\n \\\\\\quad\\\\\\ldots VariableC/g' "/path/to/output.tex"
shell sed -Ei '.orig' 's/(\\$\\times\\$ )VariableC(.*)$/\1\\ldots\2'$'\\\n \\\\\\quad\\\\\\ldots VariableC/g' "/path/to/output.tex"
shell sed -Ei '.orig' 's/(\\$\\times\\$ )VariableD(.*)$/\1\\ldots\2'$'\\\n \\\\\\quad\\\\\\ldots VariableD/g' "/path/to/output.tex"
shell sed -Ei '.orig' '/^[& ]+\\\\\\\\$/d' "/path/to/output.tex"
dreistein543 commented 2 years ago

Wow! I think the best news is I do use Stata on macOS so that I may replicate your method. No matter whether I can handle them, thank you Nils.