Announcement

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

  • outreg2 after capture

    I'm running a bunch of regressions inside a loop, and saving the results to Excel files using outreg2.
    A few of the regressions generate errors and no output, for reasons I understand. I use capture noisily to continue running the loop after the error.
    Question: if a regression generates an error, and no output, what ends up in the file produced by the oureg2 command?

    forvalues ... {
    capture noisily xtivreg2 ...
    outreg2 ...
    }

    Details: As you see I'm using xtivreg2 instead of a simpler command like reg, but I don't think that affects the answer to my question.
    Also I suspect the answer would be the same if I were using outreg instead of outreg2.

  • #2
    outreg2 and xtivreg2 are user-written additions and (probably) from SSC. As stated, this does not matter for the problem.

    Consider coding

    Code:
    forvalues ... {
        capture noisily xtivreg2 ...
        if !(_rc) {
            // regression produced results
            outreg2 ...
        }
        else {
            // regression failed
            whatever
        }
    }
    or, if no output is desired if the regression fails, simply

    Code:
    forvalues ... {
        capture noisily xtivreg2 ...
        
        if (_rc) continue    // <- new
        outreg2 ...
    }
    Best
    Daniel

    Comment


    • #3
      No specific ideas from me, as I don't use either of these programs, although there is some excellent programming to be found in looking at the code.

      But I would counsel very general caution. Their joint history is slightly unusual.

      outreg2 (Roy Wada, SSC) started as an extension of outreg (then STB, now SJ, SSC) at a time when it appeared that the original author of outreg (John Gallup) was no longer working on it. The origin of outreg2 as an extension of outreg is politely and appropriately acknowledged in the help for outreg2.

      After a lengthy pause, that become quite wrong when John rewrote outreg very drastically.

      It can be inferred that neither author wishes to change the name of their program.

      But it is unfortunate that the help for outreg2 currently contains this statement

      outreg2 thus facilitates the convertion of regression outputs to a standard
      format suitable for inclusion in a scholarly publication. The functionality of
      outreg2 is based on the earlier package outreg, by John Gallup. Unlike outreg,
      outreg2 is capable of writing LaTeX-format tables, as well as ASCII, MS Word
      and MS Excel.
      which been incorrect since 2012 given John's updating of outreg, including LaTeX support.

      In short, it may not be at all true that outreg and outreg2 behave similarly. That has to be checked, problem by problem.

      Comment


      • #4
        A followup question. outreg2 formats the contents of the e(b) vector. If the regression runs successfully then the regression estimates populate the e(b) vector.

        If the regression fails, then by default the results of the previous regression are retained in the e(b) vector. But that's not the behavior I want. Instead I'd like to populate the e(b) vector with missing values. Is there an easy way to do that?

        Comment


        • #5
          If the regression fails, then by default the results of the previous regression are retained in the e(b) vector.
          Actually, that's not necessarily true.
          Code:
          sysuse auto
          regress price mpg
          ereturn list
          regress price mpg if rep78 == 10
          ereturn list
          That said, it may be that some estimation commands don't clear e() when they fail.

          But that's not the behavior I want. Instead I'd like to populate the e(b) vector with missing values. Is there an easy way to do that?
          If you do -ereturn clear- right before the regression command e() will be empty if the regression command does not calculate estimates. That's not exactly what you asked for, in that e(b) will simply not exist. But perhaps that will work for your purposes?
          Last edited by Clyde Schechter; 19 Apr 2015, 16:11.

          Comment

          Working...
          X