Announcement

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

  • Adding stats in regression output

    Hello Everyone,

    I would like to ask aquick question (I assume that a data example here is not necessary):

    I am using this code:
    Code:
    regress depn_var x1 x2 x3 i.time_y, vce(cluster country)
    outreg2 using results_1.xls, replace excel   title("Main Results") nocons dec(3) label
    I need to add the mean of the dependent variable (similar to the number of obs and R-squared... at the end of the results (outcome) table). I did not find how to do it using outreg2.

    Thank you
    Li

  • #2
    I don't know whether a data example is needed to answer your question, but it wouldn't do any harm.

    I'll just note that outreg2 from SSC remains a popular download, but questions on it are rarely answered here. Its author left Statalist many years ago. I don't know if he replies to direct email. I don''t use it, so I will stop there.

    Comment


    • #3
      Thank you Mr. Cox,

      I am open to other Stata-commands or codes that would be also helpful. I mean a code that generates the Excel table and adds the mean of dependent var too.

      Kind wishes
      Jade

      Comment


      • #4
        Sorry, but like everyone else my expertise is bounded. Although re-presenting model fit output is an extraordinarily common activity, it's not what I ever do myself, except by writing my own code, which won't help here, not least because exporting to Excel is not what I want to do. So I don't have advice on translating to similar commands.

        But -- much more importantly -- you may get advice to that effect from others and your title is suitably inclusive.

        Comment


        • #5
          The procedure does not differ from adding any other statistic. As the statistic is not stored, place it in a local macro. Otherwise, take a look at

          Code:
          help outreg2

          Comment


          • #6
            Dear Mr. Musau,

            Thank you, that was very helpful!

            I adjusted my code as follows:

            Code:
              local avDV = e(ymean)
             regress depn_var x1 x2 x3 i.time_y, vce(cluster country) outreg2 using results_1.xls, replace excel   title("Main Results") addstat(avDV, `e(ymean)') nocons dec(3) label
            However, the results did not show me the mean of the dependent variable. Is there something wrong with my code?
            Last edited by Jade Li; 26 Sep 2023, 07:52.

            Comment


            • #7
              I do not know where you get "e(ymean)" from. I suggested that you store the statistic in a local.

              Code:
              qui sum depn_var if e(sample)
              local ymean = r(mean)
              ...., addstat(`ymean')

              Comment


              • #8
                Thank you! I found a similar one from Nick I guess:

                Code:
                  program estadd_mu, eclass
                      syntax [ , prefix(name) * ]
                      su `e(depvar)' if e(sample), meanonly
                    ereturn scalar `prefix'mu = r(mean)
                end
                and it worked out well!
                Kind wishes
                Jade

                Comment

                Working...
                X