Announcement

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

  • Outreg2: export table with marginal effect, standard error and p-value

    I would like to use outreg2 to export result of logistic regression as a .xls file with marginal effect, standard error and p-value using my own dataset. My code did work to export the xls file, but the xls file did not come with standard error and it has only columns of marginal effect and p-value. The below code is to reproduce the issue using other dataset. I'm happy if someone could help me.

    use http://www.stata-press.com/data/r7/auto.dta, clear
    logit foreign price-gear_ratio, robust
    margins, dydx(*) post
    outreg2 using "Logit_result.xls", excel replace noaster sideway pvalue noparen


    Best,
    Keita

  • #2
    Try

    Code:
     outreg2 using "Logit_result.xls", excel replace noaster sideway noparen stats(coef se pval)

    Comment


    • #3
      It worked! Thank you so much!

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        Try

        Code:
         outreg2 using "Logit_result.xls", excel replace noaster sideway noparen stats(coef se pval)
        Hi,

        Can you please elaborate on this? I can't get it to work.

        My code is:
        Code:
        probit PIP RD IRDS IPP CSM CSL NECD PG SVC
        margins, dydx(*)
        outreg2 using "C:\Stata\vmonteiro\models\modelos.doc", addstat(Pseudo R2, e(r2_p), P-value, e(p), Chi-square test, e(chi2))
        The middle part of the code
        Code:
        margins, dydx(*)
        is pointless, as having it or removing it, the table outreg2 returns is the same.

        I tried adding you code snippet to the end of my outreg2 command like so:
        Code:
        outreg2 using "C:\Stata\vmonteiro\models\modelos.doc", addstat(Pseudo R2, e(r2_p), P-value, e(p), Chi-square test, e(chi2), stats(coef se pval))
        But it doesn't work, it gives me the following error: invalid 'stats'


        Thank you,
        Manel

        Comment


        • #5
          is this what you want?
          Code:
           sysuse auto,clear probit foreign weight mpg  
          local R2=e(r2_p)
          local P=e(p)
          local Chi2=e(chi2)  
          margins,dydx(*) post
          outreg2 using 1.doc,addstat(PseuR2, `R2', P_value, `P', Chi-square,`Chi2')
          Last edited by Raymond Zhang; 21 Jun 2021, 13:26.
          Best regards.

          Raymond Zhang
          Stata 17.0,MP

          Comment


          • #6
            Originally posted by Manel Silva View Post

            Hi,

            Can you please elaborate on this? I can't get it to work.

            My code is:
            Code:
            probit PIP RD IRDS IPP CSM CSL NECD PG SVC
            margins, dydx(*)
            outreg2 using "C:\Stata\vmonteiro\models\modelos.doc", addstat(Pseudo R2, e(r2_p), P-value, e(p), Chi-square test, e(chi2))
            The middle part of the code
            Code:
            margins, dydx(*)
            is pointless, as having it or removing it, the table outreg2 returns is the same.

            I tried adding you code snippet to the end of my outreg2 command like so:
            Code:
            outreg2 using "C:\Stata\vmonteiro\models\modelos.doc", addstat(Pseudo R2, e(r2_p), P-value, e(p), Chi-square test, e(chi2), stats(coef se pval))
            But it doesn't work, it gives me the following error: invalid 'stats'


            Thank you,
            Manel

            As in #1 (and also Raymond's code), you need the -post- option of margins to send the marginal effects to e(b) and e(V), from where outreg2 can access them. Otherwise the regression results are still active.

            Comment


            • #7
              [deleted]
              Last edited by Manel Silva; 23 Jun 2021, 11:35.

              Comment


              • #8
                I am trying to use outreg2 to print margins predicted at means to an excel spreadsheet. My equation is a multinomial logistic with three outcomes. Here's my code:

                svy: mlogit dvar yearspline##(age sex race mstat kids pob)
                margins yearspline, atmeans predict(equation(1)) post
                margins yearspline, atmeans predict(equation(2)) post
                margins yearspline, atmeans predict(equation(3)) post
                outreg2 using myfile, replace noaster sideway stats(coef se pval)

                I get an error on the third line saying that margins cannot work with its own posted results. Can you advise me on how I can produce a table of predicted probabilities for each value of the dependent variable without running the equation multiple times?

                Comment


                • #9
                  Dear Andrew Musau, do you know how on outreg2 (from ssc install) you can get the asterisks not next to the coefficient, but next to the pval in the statistics displayed?

                  Comment

                  Working...
                  X