Announcement

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

  • putdocx basic summary statistics

    I am running Stata 17 SE.

    I would like to send the output of basic summary statistics commands, namely
    Code:
    summarize
    Code:
    tabulate
    Code:
    codebook
    Code:
    describe
    However, I can't do the usual
    Code:
    putdocx table table1=etable
    presumably because the summary statistics commands do not generate tables, even though their output does look a lot like tables.

    For individual elements, the manual suggests
    Code:
    putdocx text (" ‘r(mean)’ ")
    etc

    But I am not interested in one element here or there to include in a largely text report...I would like to send to the docx file the whole output...
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    There are many better / more complete solutions (and probably a better way to do what I did), but this is something quick and dirty I wrote for myself. It simply stores the text output (not the command) of a Stata command as a text file (as a limited log file), and then you can use [putdocx textfile `filename', append] (after a putdocx paragraph, font(x) where x is a fixed width font). I use tempfiles for the filenames. Since it meets my needs, I never went back to make it Stata-perfect.

    example:

    tempfile sum1
    cmd2txt "summarize var1, detail" using `sum1', replace
    ...
    putdocx paragraph, font(Consolas, 10)
    putdocx textfile `sum1', append
    ...


    **# Program to export a text file from output of a Stata command
    program cmd2txt
    version 17
    syntax anything(equalok id="Stata command") using/ [, REPlace]
    tokenize `anything'
    forvalues i = 1/1 {
    tempname logname
    capture log close `logname'
    log using "`using'", text nomsg name(`logname') `replace'
    `*'
    log close `logname'
    }
    end

    Comment

    Working...
    X