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

Request: Html output #60

Open friosavila opened 1 year ago

friosavila commented 1 year ago

Hi Ben, I was wondering if I could request a "small" change (or option) for esttab when exporting regression results to HTML (although it may also affect other type of tasks)

Consider the following example:

sysuse auto
reg price mpg
est sto m1
esttab m1, html

which produces the following:


(1)
price

mpg -238.9***
(-4.50)
_cons 11253.1***
(9.61)

N 74

t statistics in parentheses
* p < 0.05, ** p < 0.01, *** p < 0.001

You will notice those lines between the heading and body of the table. So, would it be possible to change lines like <tr><td colspan=2><hr></td></tr> with <thead><\thead> and <body><\tbody>, so something like the following would be produced?

(1)
price
mpg -238.9***
(-4.50)
_cons 11253.1***
(9.61)
N 74
t statistics in parentheses
* p < 0.05, ** p < 0.01, *** p < 0.001

Modified HTML file

<table border="0" width="*">
<thead>
<tr><td>            </td><td>         (1)              </td></tr>
<tr><td>            </td><td>       price              </td></tr>
</thead>
<tbody>
 <tr><td>mpg         </td><td>      -238.9<sup>***</sup></td></tr>
<tr><td>            </td><td>     (-4.50)              </td></tr>
<tr><td>_cons       </td><td>     11253.1<sup>***</sup></td></tr>
<tr><td>            </td><td>      (9.61)              </td></tr>
</tbody>
<tbody>
<tr><td><i>N</i>    </td><td>          74              </td></tr>
</tbody>
<tr><td colspan=2>
<i>t</i> statistics in parentheses
<br /><sup>*</sup> <i>p</i> < 0.05, <sup>**</sup> <i>p</i> < 0.01, <sup>***</sup> <i>p</i> < 0.001
</td></tr>
</table>
benjann commented 1 year ago

Yeah, HTML support in esttab is very primitive. I would suggest to pack the header into thead, then each equation into a separate tbody, the footer containing the summary stats also in a tbody, and the notes at the end either in tfoot or in tbody (tfoot would seem natural, but tfoot is repeated when a table is larger than a page, I believe; this seem not what one usually would want, even it it is only relevant for printing; so tend to tbody for the notes, not to tfoot).

It is not much of an issue to add an improved HTML option, but I would not want to change the default (changing defaults in esttab does not seem like a good idea because the program has been around so long and so many people are using it). So I could either add another format type, like html2 (do you have a suggestion for a better name?) or add an extra option that changes the behavior of html (do you have a suggestion for a good name for such an option?). Yet another possibility would be to add thead, tbody, etc. once the user types option nolines, an option that already exists. This would maybe be slightly unintuitive, but it would do the trick... Do you have any thoughts on this?

friosavila commented 1 year ago

Hi Ben Thank you for your quick reply. My main motivation for changing the older behaivior to one that uses "thead" and "tbody" is that im trying to use Quarto combined with Stata (nbstata) to make more dynamic texts. Right now, im still exploring few options, including table creations using tex, as well as html. This is how i found the problem/suggestion I mentioned.

I think using html2 would suffice. However, If i may,it would be extremely convinient if one other things could be added.

To easily add html tables in quarto syntax, i find that one can use {{< include name.html>}}. However, for it to work correctly with Quarto, the HTML file needs to start with ```{=html} and finalize with ``` Could something like that be added? perhaps under "quarto" option?

Thank you! Fernando

On Wed, Aug 23, 2023 at 4:33 PM Ben Jann @.***> wrote:

Yeah, HTML support in esttab is very primitive. I would suggest to pack the header into thead, then each equation into a separate tbody, the footer containing the summary stats also in a tbody, and the notes at the end either in tfoot or in tbody (tfoot would seem natural, but tfoot is repeated when a table is larger than a page, I believe; this seem not what one usually would want, even it it is only relevant for printing; so tend to tbody for the notes, not to tfoot).

It is not much of an issue to add an improved HTML option, but I would not want to change the default (changing defaults in esttab does not seem like a good idea because the program has been around so long and so many people are using it). So I could either add another format type, like html2 (do you have a suggestion for a better name?) or add an extra option that changes the behavior of html (do you have a suggestion for a good name for such an option?). Yet another possibility would be to add thead, tbody, etc. once the user types option nolines, an option that already exists. This would maybe be slightly unintuitive, but it would do the trick... Do you have any thoughts on this?

— Reply to this email directly, view it on GitHub https://github.com/benjann/estout/issues/60#issuecomment-1690598943, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASZKKFWZRE72ZWA7KVQMXUTXWZSH5ANCNFSM6AAAAAA334GSO4 . You are receiving this because you authored the thread.Message ID: @.***>