Announcement

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

  • adjust column width with putdocx

    Hallo,

    I've got a question concerning the column width of tables and its assignment with "collect style putdocx". I understand that the sum must be equal to 100. However, even if the sum does equal 100, in some cases I get error messages implying that this is not the case.

    Are there any rules to be considered, when defining column width?

    Code:
    clear all
    set more off
    
    sysuse auto.dta
    
    putdocx begin
    
    table foreign rep78, statistic(freq) statistic(sumw) statistic(percent, across(foreign)) ///
                          sformat("%s%%" percent) nformat(%9.0f) totals(foreign)
    
    * does work
    *mat width1  = (37, 15.5, 9.5, 9.5, 9.5, 9.5, 9.5)
    *mat width1  = (37, 15, 9.6, 9.6, 9.6, 9.7, 9.5)
     
    * does not work
    mat width1 = (37, 15, 9.6, 9.6, 9.6, 9.6, 9.6)
     
    collect style putdocx, halign(left) width(80%) width(width1)
    
    putdocx collect
    
    putdocx save test, replace
    Code:
    . putdocx collect
    option width() specified incorrectly
        The sum of the column widths specified in matrix width1 must be equal to 100.
    What do I do: I generate a series of tables with table/collect layout and arrange them one below the other. The tables may have a different number of columns. However, the first column (with labels) and the second columns should have the same width. The other colums may vary in width.

    I define several vectors "width#" to set the width of each table. However, sometimes it is pretty difficult to find a vector which is working. The slightest change will result in the procedure either working or not. I don't really understand why this is the case.

    Thanks a lot!

  • #2
    Simon Pfaff,

    Thank you for bringing this to our attention. This is a bug caused by the precision issue. The sum of the vector that does not work, i.e., (37, 15, 9.6, 9.6, 9.6, 9.6, 9.6), does not have an exact finite-digit binary representation, compared with the other two vectors.

    We will fix the width() problem in putdocx to make it more robust to the above cases and release it to users in one of our future updates.
    Last edited by Zhao Xu (StataCorp); 19 Feb 2024, 11:09.

    Comment


    • #3
      @Zhao Xu (StataCorp)

      Thank you for your feedback, I appreciate it!

      Best, Simon

      Comment

      Working...
      X