Announcement

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

  • Formating dtable into putdocx

    Hello all and thanks in advance for your help.

    I am just despairing of learning the new dtable command: I am currently trying to transfer dtables from descriptive tab1/tab2 commands to a word document via a putdocx command.
    Examplecode of a simple oneway tabulate dtable:
    Code:
    putdocx paragraph, style(Heading2)
    putdocx text ("Citydistrict")
    dtable i.Citydistrict
    collect title Table `Tblnb': Citydistrict (unweighted)
    collect notes "Unweighted."
    putdocx collect
    local `Tblnb++'
    The output contains all the important information, but the format of the output Word table troubles me.
    In Word the absolute case numbers per category are in the same table cell as the percentages per category (--> in the same column).
    So: Cell D2: [ 1.950 (0,50%) ]
    However, for a meaningful use I need the two values in separate columns.
    So: Cell D2: [ 1.950 ] Cell D3: [(0,50%)]

    I can't find any code for this presumably simple modification, and all the examples in the webinar and on the blog don't separate the two columns either.
    So: Is there a way to use the dtable command (or the collect/table command if applicable) to separate the columns? Or is it necessary to resort to ados? (Or even to the creation of matrices?)

    I apologize in advance if this is too trivial a question, unfortunately as a new user I am a bit desperate as I have to create a large number of tables.

    Thank you and best regards
    Max

  • #2
    Here is an example of how to split the results from dtable into
    separate columns.

    Code:
    sysuse auto
    dtable i.rep78
    
    * see what dimensions are used in the layout
    collect layout
    
    * see the autolevels of the column dimension
    collect query autolevels result
    
    * see how the composite result is defined
    collect query composite _dtable_stats
    
    * define our own composite results
    * put frequencies in column 1
    collect composite define col1 = frequency fvfrequency
    * put percentages in column 2
    collect composite define col2 = fvpercent
    * change result's autolevels to use our composite results
    collect style autolevels result col1 col2, clear
    
    * change result's label
    collect label dim result "Summary", modify
    * show result's label, hide result's levels
    collect style header result[col1 col2], title(label) level(hide)
    
    * see our changes in action
    collect preview
    Here is the resulting table

    Code:
    -----------------------------
                         Summary
    -----------------------------
    N                  74
    Repair record 1978
      1                 2  (2.9%)
      2                 8 (11.6%)
      3                30 (43.5%)
      4                18 (26.1%)
      5                11 (15.9%)
    -----------------------------
    Here is a screen shot from LibreOffice of the docx file I created via collect export.
    Click image for larger version

Name:	Screenshot 2023-10-18 at 1.43.21 PM.png
Views:	1
Size:	17.6 KB
ID:	1730760

    Comment


    • #3
      Thank you so much!
      This will help me implement it!

      Comment

      Working...
      X