Announcement

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

  • Generate an empty word document

    I am using outreg in a foreach loop but I need to manually delete the previously created Word document each time I rerun the do file. If I wasn't using foreach, I could specify "replace" after the first outreg and then "merge" for the others. Is there a way to create an empty Word document- something like "save name.doc, replace"?

    Here's a sample of the code:

    foreach var of varlist $outcomes {
    reg `var' x y z
    outreg regressions.doc, merge
    }

  • #2
    You can add an erase command before the loop.
    Code:
    erase "regressions.doc"
    foreach var of varlist $outcomes {
      reg `var' x y z
      outreg regressions.doc, merge
    }

    Comment


    • #3
      Thanks, that is what I was looking for. However, now all of my outreg commands append the previous estimates as well.

      erase regressions1.doc
      foreach var of varlist $outcomes1 {
      reg Y X
      outreg regressions1.doc, merge
      }

      erase regressions2.doc
      foreach var of varlist $outcomes2 {
      reg Y X
      outreg regressions2.doc, merge
      }

      regressions2.doc includes estimates from regressions1.doc. How can I tell outreg to ignore prior estimates? I thought having a different document name would do it.

      Sean

      Comment


      • #4
        clear all resets outreg but then you have to load your data again. I don't know if there are other solutions that don't require clear all.
        Code:
        erase regressions1.doc
        foreach var of varlist $outcomes1 {
          reg Y X
          outreg regressions1.doc, merge
        }
        
        clear all
        * Add commands here to load data again
        erase regressions2.doc
        foreach var of varlist $outcomes2 {
          reg Y X
          outreg regressions2.doc, merge
        }

        Comment


        • #5
          Is there a way to create an empty Word document ... ?
          Yes. You can create an empty Word document once (with Word), save it somewhere. Then in your scripts you copy it to the desired location where your scripts can populate the blank files with content.

          This works for other programs too (e.g. you can prepare an elaborate Excel file with a title sheet, which you extend by adding tables to additional sheets).


          How is this supposed to work? (`var' is not used in the loop body and hence there will be identical regressions run many times)

          Code:
          foreach var of varlist $outcomes2 {
            reg Y X
            outreg regressions2.doc, merge
          }
          Best, Sergiy Radyakin

          Comment

          Working...
          X