Announcement

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

  • putdocx and tab2docx command

    Hi! I have been having some problems with the putdocx and tab2docx commands.

    Here is something that I have run successfully:

    local school_tab "school_dropwhy textbooks_maths textbooks_chewa textbooks_eng textbooks_sci textbooks_his textbooks_bio notebooks penspencils erasers edu_aspire readingability edu_important glasses"
    quietly foreach x in `school_tab' {
    putdocx clear
    putdocx begin
    tab2docx `x' if survey_string == "1f" & School == 0
    putdocx save "`x'", replace
    }

    The above commands have enabled me to export the tabulation results to Word documents. Unfortunately, it is tedious since Stata exports the results of each tabulation to a separate Word file.

    To export the tabulation results into one single Word file, I have tried to re-arrange the commands:

    putdocx clear
    putdocx begin
    local school_tab "school_dropwhy textbooks_maths textbooks_chewa textbooks_eng textbooks_sci textbooks_his textbooks_bio notebooks penspencils erasers edu_aspire readingability edu_important glasses"
    quietly foreach x in `school_tab' {
    tab2docx `x' if survey_string == "1f" & School == 0
    putdocx save "`x'", replace
    }

    However, this has rendered the tab2docx command invalid, which I don't understand.

    Could someone please help me out?

    Very much appreciated!



  • #2
    In your second code a docx document was closed (saved) after the first variable. So when the loop continued to the second variable no docx document was open and tab2docx returned an error. To solve that you also need to move putdocx save outside the loop:
    Code:
    putdocx clear
    putdocx begin
    local school_tab "school_dropwhy textbooks_maths textbooks_chewa textbooks_eng textbooks_sci textbooks_his textbooks_bio notebooks penspencils erasers edu_aspire readingability edu_important glasses"
    quietly foreach x in `school_tab' {
        tab2docx `x' if survey_string == "1f" & School == 0
    }
    putdocx save "`x'", replace
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Sir! Many thanks for your reply!

      I have tried to run your codes. However, it says "invalid file specification".

      Is there anything else that I should add?

      Millions of thanks!

      Comment

      Working...
      X