Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to adjust (and export) row spacing in regression results with 'collect' ?

    Not sure if I should just be taking this up with STATA directly, but thought I'd check with this community first, just in case anyone has run into the same thing already...

    The STATA 17 'collect' set of routines allows a lot of customization of table layouts and formatting, but as far as I've been able to tell the only two options currently implemented for adding vertical spacing between result rows (e.g. regression results) are to either (1) add an entire full row space, e.g.
    Code:
    collect style row split, space
    (which seems excessive), OR (2) to add margin space to the results, e.g. either above or below the coefficients or standard errors:
    Code:
    collect style cell result[_r_b], margin( top, width(15) )
    The problem with the latter approach is that it seems to only render in STATA -- i.e. when the table is exported (esp. to Latex, but also to word) the margin spacing is not retained -- it DOES appear to be maintained (though the scaling is a bit off) when exporting to PDF) [examples of this behavior provided below].

    Is there not an option to customize the vertical cell spacing further for Latex or PDF table? (e.g. along the lines of " \addlinespace " in a Latex table?)


    Minimum working example:
    Code:
    sysuse auto,clear
    replace weight = weight/2000
    label var weight "Weight (tons)"
    collect clear
    collect: reg mpg weight length i.foreign
    collect layout (colname#result[_r_b _r_se]) (cmdset)
        collect style header result[_r_b _r_se], level(hide)  //drop "coef" and "se" labels
        collect style showbase off  //drop indicator base levels
        collect style cell, nformat(%5.2f)  //two decimal places 
        collect style cell result[_r_se], sformat("(%s)")  //format s.e. 
        
        collect style cell result[_r_se], warn margin( bottom, width(12) ) //add spacing below std. errors
        collect preview //spacing changes don't show up in results window, but DO show up in the STATA gui for 'collect' : Statistics >> Summaries, Tables and Tests >> Tables and Collections 
            collect export "test_table", as(docx) replace
            collect export "test_table", as(tex) replace
        collect style cell result[_r_se], warn margin( bottom, width(0.5) ) //add spacing below std. errors
        collect preview
            collect export "test_table", as(pdf) replace

  • #2
    Just a quick follow up that I received back from STATA support:

    *************************
    Thanks for contacting Stata Tech Support.

    Currently, the -margin()- option is only applicable for PDF and HTML
    files. If we type

    help collect style cell

    and scroll down to

    margin([margins] [, width(#[unit])]) specifies margins inside the
    cell. These margin style properties are applicable when publishing
    items from a collection to PDF and HTML files.

    margins specifies one or more margin locations and identifies
    where to apply the margin style edits. The margin locations are
    left, right, top, bottom, and all. If margins is not specified,
    all is assumed.

    width(#[unit]) specifies the margin width as a number optionally
    followed by units.

    and we can read that "These margin style properties are applicable when
    publishing items from a collection to PDF and HTML files", which aligns
    with your findings. They do not have effects on other types of files
    exported.

    In addition, we do not have much control over .tex files and for .docx,
    we could consider -collect style putdocx- which has a -cellmargin()- option,
    but it applies to all table cells, unlike -collect style cell- that you
    can specify individually, for instance,

    ***
    collect style putdocx, cellmargin(bottom, 1)

    collect export tab2.docx, replace
    ***

    I will add your descriptions/questions as requests for future
    developments and pass them to our developers.

    Hope you find the above helpful.

    Sincerely,


    Comment

    Working...
    X