Announcement

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

  • Saving margins effects instead of coefficients

    Dear all,
    I am trying to save the margins effects instead of coefficients for several models using estout commands but it keeps saving the coefficients here is the commands i use:

    quietly regress savingrate i.age_group agesq logincome rururb female dependancy hnum earn married i.education i.employment i.occhd if year==2010, robust
    eststo margin: quietly margins, dydx(*)
    estimates store m1, title(Model Regression)

    quietly tobit savingrate i.age_group agesq logincome rururb female dependancy hnum earn married i.education i.employment i.occhd if year==2010, ll(0)
    eststo margin: quietly margins, dydx(*) predict (ystar(0,.))
    estimates store m2, title(Model Tobit)

    quietly probit saving i.age_group agesq logincome rururb female dependancy hnum earn married i.education i.employment i.occhd if year==2010, nolog
    eststo margin: quietly margins, dydx(*)
    estimates store m3, title(Probit)

    quietly truncreg savingrate i.age_group agesq logincome rururb female dependancy hnum earn married i.education i.employment i.occhd if year==2010, ll(0)
    eststo margin: quietly margins, dydx(*) predict(e(0,.))
    estimates store m4, title(Truncated)

    esttab m1 m2 m3 m4 , cells(b(star fmt(3)) se(par fmt(2)))

    esttab m1 m2 m3 m4 , cells(b(star fmt(3)) se(par fmt(2))) ///
    legend label varlabels(_cons Constant)

    esttab m1 m2 m3 m4 , cells(b(star fmt(3)) se(par fmt(2))) ///
    legend label varlabels(_cons constant) ///
    stats(r2 df_r bic)

    esttab m1 m2 m3 m4 using final8.txt, cells(b(star fmt(3)) se(par fmt(2))) delim("&") ///
    legend label varlabels(_cons constant) ///
    stats(r2 df_r bic, fmt(3 0 1) label(R-sqr dfres BIC))

  • #2
    Your code is difficult to read, as it contains so much unnecessary detail. When you present problems like this, it's better to use a publicly available data set with the simplest example that presents your problem.

    This might show you the way:

    Code:
    webuse lbw, clear
    logit low i.smoke
    webuse lbw, clear
    logit low i.smoke
    margins smoke
    margins smoke,  coeflegend post
    lincom _b[1.smoke] -_b[0.smoke]
    Output starting from the first margins command. In the second margins statement, post makes the estimated effects available and coeflegend shows how to refer to the effects. In this case, you can use a simpler version of the coefficient for the baseline group.

    Code:
    . margins smoke
    
    Adjusted predictions                              Number of obs   =        189
    Model VCE    : OIM
    
    Expression   : Pr(low), predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           smoke |
      nonsmoker  |   .2521739    .040495     6.23   0.000     .1728052    .3315427
         smoker  |   .4054054   .0570741     7.10   0.000     .2935421    .5172687
    ------------------------------------------------------------------------------
    
    . margins smoke,  coeflegend post
    
    Adjusted predictions                              Number of obs   =        189
    Model VCE    : OIM
    
    Expression   : Pr(low), predict()
    
    ------------------------------------------------------------------------------
                 |     Margin  Legend
    -------------+----------------------------------------------------------------
           smoke |
      nonsmoker  |   .2521739  _b[0bn.smoke]
         smoker  |   .4054054  _b[1.smoke]
    ------------------------------------------------------------------------------
    
    . lincom _b[1.smoke] -_b[0.smoke]
    
     ( 1)  - 0bn.smoke + 1.smoke = 0
    
    ------------------------------------------------------------------------------
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |   .1532315   .0699807     2.19   0.029     .0160718    .2903912
    ------------------------------------------------------------------------------
    Last edited by Steve Samuels; 16 Aug 2014, 21:35.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      I am really sorry but am trying to be as clear as possible. what i need is to save the marginal effects of the below models in table using estout or outreg. the commands i use below only save the coefficients in the table and not the marginal effect. i have been trying a lot and nothing is working

      code:

      sysuse auto

      reg price mpg rep78 foreign, robust
      margins, dydx(*)
      estimates store m1, title(Model 1)

      tobit price mpg rep78 foreign, 11(0)
      margins, dydx(*) predict (ystar(0,.) )
      estimates store m2, title(Model 2)

      probit price mpg rep78 foreign
      margins, dydx(*)
      estimates store m3, title(Model 3)

      truncreg price mpg rep78 foreign
      margins, dydx(*) predict(e(0,.))

      estimates store m4, title(Model 4)

      estout m1 m2 m3 m4 , cells(b(star fmt(3)) se(par fmt(2)))
      Last edited by Nourhan Eid; 17 Aug 2014, 06:23.

      Comment


      • #4
        I have never used -esttab- myself, and only rarely use -estout-, but if I understand these programs correctly, they are designed to work only with the values posted in e(). To get the results of -margins- there, you have to use the -post- option in the -margins- commands you issue.

        Hope this helps.

        Comment


        • #5
          Have you looked at the Advanced documentation pages at http://repec.org/bocode/e/estout/advanced.html, specifically http://repec.org/bocode/e/estout/adv...ml#advanced002? The latter states "In esttab or estout ... use the margin option to display the marginal effects." An example is given.
          [The Examples section of esttab states " Additional examples can be found at http://repec.org/bocode/e/estout] .

          Comment


          • #6
            Thank you all for your helpful comments, the following commands worked somehow

            code:

            sysuse auto

            eststo raw: reg price mpg rep78 foreign, robust
            eststo margin: margins, dydx(*) post
            estimates store m1, title(Model 1)

            eststo raw: tobit price mpg rep78 foreign, 11(0)
            eststo margin: margins, dydx(*) post
            estimates store m2, title(Model 2)

            eststo raw: truncreg price mpg rep78 foreign, 11(0)
            eststo margin: margins, dydx(*) predict(e(0,.)) post
            estimates store m3, title(Model 3)

            estout m1 m2 m3 , cells(b(star fmt(3)) se(par fmt(2)))

            Comment


            • #7
              A much more easier way using outreg2

              Code:

              sysuse auto

              tobit price mpg rep78 foreign, 11(0)
              margins, dydx(*) predict (ystar(0,.)) post
              outreg2 using test.doc, word replace ctitle(Marginal effects)

              truncreg price mpg rep78 foreign, 11(0)
              margins, dydx(*) predict(e(0,.)) post
              outreg2 using test.doc, word append ctitle(Marginal effects 2)

              Comment


              • #8
                This is what ive been cracking my head about..... thank you.

                Comment


                • #9
                  This is very late for posting. But when you use estso margin, you are saving in "margin" all your marginal effects output. So you have been replacing your marginal effects in "margin", And, m1 m2 just have coefficient output. If you save with different name your margins you will be able to use tabstat


                  eststo raw: reg price mpg rep78 foreign, robust
                  eststo margin1: margins, dydx(*) post
                  estimates store m1, title(Model 1)

                  eststo raw: tobit price mpg rep78 foreign, 11(0)
                  eststo margin2: margins, dydx(*) post
                  estimates store m2, title(Model 2)

                  eststo raw: truncreg price mpg rep78 foreign, 11(0)
                  eststo margin2: margins, dydx(*) predict(e(0,.)) post
                  estimates store m3, title(Model 3)

                  esttab margin1 margin2 margin3

                  Comment

                  Working...
                  X