Announcement

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

  • Export Word putdocx

    Hi

    I have not had Stata for too long and am trying to create a Word export from Stata.
    Unfortunately, Stata rounds down or up my data when exporting.

    In the Stata browse, the number is stored as follows:
    2.501e+09
    Type: double, Format: %10.0g

    My syntax is:
    Code:
    putdocx table Table1(1,1) = ("sample number")
    putdocx table Table1(1,2) = (samplenr), nformat(%-16.0g)
    The output in the Word: 2501500000 instead of 2501466707.

    As soon as the number has fewer digits, it works fine and the number is not rounded - but it is then stored in Stata as long, %12.0g.

    Does anyone on the forum have experience with putdocx commands and would be kind enough to help me? I'm using Stata, version 17 and Microsoft365, thanks in advance. :-)

  • #2
    Maybe try inputting it as a string.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double samplenr
    2501466707
    1876980097
    end
    
    putdocx begin
    putdocx table Table1 = (2, 2)
    putdocx table Table1(1,1) = ("sample number 1")
    putdocx table Table1(2,1) = ("sample number 2")
    putdocx table Table1(1,2) = (string(samplenr[1], "%11.0f"))
    putdocx table Table1(2,2) = (string(samplenr[2], "%11.0f"))
    putdocx save myfile, replace
    Res.:

    Click image for larger version

Name:	Screenshot 2022-03-28 120957.png
Views:	1
Size:	20.1 KB
ID:	1656599

    Comment


    • #3
      Many, many thanks, Andrew!
      It works perfectly!
      I wish you a nice day.

      Comment

      Working...
      X