Announcement

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

  • outreg2 "long" format instead of "wide"

    Hi,

    I would like to have the dependent variables of my regressions listed in the left column and the independent variables because I have a lot a regression results that will not fit in the width of a word document.

    I have found what I think should fix the problem in the "outreg2" help file but the example code does not work in my Stata version 16.1.

    I am using the "long" option but I am getting an error when I copy/paste the code:

    Code:
        sysuse auto, clear
        
        tab rep78, gen(repair)
        regress mpg foreign weight repair1-repair4
        
        /*
        outreg2 weight foreign using myfile, drop(repair*)
    
        outreg2 using myfile, drop(repair*) replace
        outreg2 using myfile, keep(mpg foreign)
        outreg2 using myfile, nocons
        seeout
    */
        * multiple equations
        reg3 (mpg rep78 head trunk weight) (head trunk weight rep78 gear)
        outreg2 using myfile, replace long
        reg3 (mpg rep78 head weight turn disp ) (mpg rep78 head trunk weight gear)
        outreg2 using myfile, sortvar(trunk turn) see long
    Can someone help me there? Thanks

  • #2
    I am getting an error
    Then you made a mistake.

    With 732 posts at this time, you have yet to internalize the advice of the Statalist FAQ. So let me repeat an important portion here.

    12. What should I say about the commands and data I use?

    Help us to help you by producing self-contained questions with reproducible examples that explain your data, your code, and your problem. This helps yet others too, as they will find it easier to learn from your questions and the answers to them.

    12.1 What to say about your commands and your problem

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    When you decline to provide a reasonable statement of your problem, you signal to the reader that you value the readers time spent trying to guess the details of your problem less than you value the time you would take to provide a full statement of the problem.

    Eventually other members come to understand this and choose to spend their time on questions that show respect for their time.

    Comment


    • #3
      The version of outreg2.ado available from SSC was most recently updated by the author in 2014. I have not been able to find a later version on the internet.

      In outreg2.ado we see the following code, executed when the regression command reports multiple equations:

      Code:
                             count if `blanks'==0 & eq~="" & eq~="EQUATION"
                              local _firstN=_N
                             set obs `=_N+`r(N)''
                              local times 1
                              forval num=2/`_firstN' {
                                      if eq[`num']~="" & eq[`num']~="EQUATION" {
                                              replace id5=`num'-.75 in `=`_firstN'+`times''
                                              replace coef=eq[`num'] in `=`_firstN'+`times''
                                              local times=`times'+1
                                      }
                              }
                              
                              sort id5
                              
                             drop eq id5 `blanks'
                              
                              * change `bottomBorder' by the number of equations inserted
                             local bottomBorder=`bottomBorder'+`r(N)'
      The count command is an r-class command that returns the result in the scalar r(N).

      We see that r(N) is used in the set obs command to increase the size of the dataset.

      In 2017 Stata 15.1 made the following change to the drop command, per the output of help whatsnew15.

      Code:
          13. drop and keep now store the number of observations dropped in r(N_drop) and the
              number of variables dropped in r(k_drop).  This change means that these commands now
              clear results previously stored in r() by other commands.  The old behavior is
              preserved under version control.
      After the drop command r(N) is no longer defined, because version control is not used correctly in outreg2.ado, as discussed below.

      Unfortunately, then, the subsequent local command is interpreted as
      Code:
      local bottomBorder=`bottomBorder'+
      which produces a syntax error, which I am guessing is the error message omitted from post #1. (The first error message I received when running the code in post #1 was "variable head not found" which results from the way I configure my copy of Stata. This is why taking the time to include the error message is important: to be help the reader know that they are working on the same error as the poster.)

      Now, in the quoted passage from help whatsnew15 Stata told us that this should not happen, but the use of version control in outreg2.ado is not straightforward. I cannot figure out what it hopes to accomplish, and prefixing the outreg2 command with e.g. version 14: does not seem to resolve the problem.

      So the mistake appears to be relying on popular well-documented community contributed software that is in fact no longer actively maintained by the author.
      Last edited by William Lisowski; 07 Dec 2022, 12:11.

      Comment

      Working...
      X