Announcement

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

  • putdocx table r(110) error

    Hello all,

    I was working on a do file to generate my -dtables- and adding the putdocx statements to export two tables out. The code below is the final putdocx statements and save statement. I am getting a very persistent r(110) error indicating document is already open. The docx file never saved. I have tried several variations of clearing memory, putdocx and collect including clear, -exit, clear-, -collect clear-.Even tried exiting the session and coming back. But it still persists.

    What else can I do? I do have a header script (listed below the first code block) for initializing folders for the project (that Clyde Schechter had recommended) which works wonderfully in all the other files. If there is anything else you need to troubleshoot, I am glad to share. Tried looking at other topic on this forum but could not find the right solution.


    Code:
    // Final layout & export
    *-----------------------
    collect layout (vargrp#var var[`binvars']) (icc2#result#_dtable_sample_dim)
    collect preview
    
    putdocx begin
    collect style putdocx, layout(autofitcontents) ///
    title("Table 1: Cohort characteristics by TP53 allelic state.")
    
    collect export "`prfold'/outputs/table1_demo.docx", replace
    Error portion:
    Code:
    . collect style putdocx, layout(autofitcontents) ///
    > title("Table 1: Cohort characteristics by TP53 allelic state.")
    
    . 
    . collect export "`prfold'/outputs/table1_demo.docx", replace
    document already open in memory
    r(110);
    Initialization code:
    Code:
    local prfolder Prj_akp53
    include DIRECTORY_INITIALIZATION.DOH, adopath
    
    
    ****************************************************************************************************
    *Title: Spectrum of TP53-mutated myeloid leukemia: A single institution cohort across 8 years
    ****************************************************************************************************
    // Program: p53_tables.do
    // Task   : Uses an01-merged.dta
    // Outputs: Tables for first submission
    // Project: TP53 mutations in myeloid neoplasms and outcome
    // Author : GV \date: 2023-10-12
    
    
    use "`prfold'/dtafiles//an01-merged.dta", replace
    qui do "`prdo'//p53select.doh"
    
    
    qui include "`pwork'//unicoder.do"                        // Need for Superscript units 
    collect clear 
    putdocx clear

  • #2
    Changing the code to exclude the -putdocx begin- line fixed the issue. Guess collect and dtables already indicates that -putdocx- is open and that is why I got the error?

    Code:
    // Final layout & export
    *-----------------------
    collect layout (vargrp#var var[`binvars']) (icc2#result#_dtable_sample_dim)
    collect preview
    
    collect style putdocx, layout(autofitcontents) ///
    title("Table 1: Cohort characteristics by TP53 allelic state.")
    
    collect export "`prfold'/outputs/table1_demo.docx", replace

    Comment


    • #3
      Thanks for closing the loop by posting your solution so that others (including me) can learn from your experience.

      Comment


      • #4
        If you are using putdocx to build a report or other such document, then you should use putdocx collect to place your tables from dtable (etable, table, or collect) in your document. collect export will try to build a stand-alone document for your table, which is probably not what you want.

        Comment


        • #5
          Originally posted by Jeff Pitblado (StataCorp) View Post
          If you are using putdocx to build a report or other such document, then you should use putdocx collect to place your tables from dtable (etable, table, or collect) in your document. collect export will try to build a stand-alone document for your table, which is probably not what you want.
          Thanks for the tips, Jeff Pitblado (StataCorp). My intent was to create a standalone document for the two tables with both of their legends in a single word document. Thereafter, I am using a master merging do file to merge my Introduction.docx (generated outside Stata), results.docx (coming entirely from several putdocx do files), then this table.docx (and then figures) to generate the working draft. I am still trying to figure out a do file way to automatically renumber in-text and legend numbers for figures via macros. I hate it when I delete a figure as an afterthought and then have to go to multiple do-files generating the results.docx to change out the figure number calls intext and in the figure legends. I will separately start a thread later to ask for pointers. Sorry for digressing off topic here.

          Comment

          Working...
          X