Announcement

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

  • Exporting Marginal effects from stata to excel/word.

    Hello All,

    I am beginner to stata, trying to learn. For my dataset I am using Oprobit model, to export marginal effects I have used esttab, and outreg2 however for both I am unable to export margins everytime it exports the coefficients from oprobit model.
    I have also tried using asdoc but asdoc is giving me the entire table where in I only want coefficient with pvalues sidewaves


    Thanks
    Palana

  • #2
    You need the -post- option of margins to overwrite the previous estimation results.

    Code:
    margins, dydx(*) post
    Last edited by Andrew Musau; 16 Feb 2023, 07:18.

    Comment


    • #3
      Here is a way of doing so with the new etable command.

      Code:
      . // open example data
      . sysuse auto, clear
      (1978 automobile data)
      
      .
      . // use some sensible units
      . replace weight = weight*0.00045359237
      variable weight was int now float
      (74 real changes made)
      
      . label var weight "weight (1000kg)"
      
      . replace price = price/1000
      variable price was int now float
      (74 real changes made)
      
      . label var price "price (1000$)"
      
      .
      . // estimate the model
      . oprobit rep78 price weight
      
      Iteration 0:   log likelihood = -93.692061  
      Iteration 1:   log likelihood = -84.869304  
      Iteration 2:   log likelihood = -84.824693  
      Iteration 3:   log likelihood = -84.824643  
      Iteration 4:   log likelihood = -84.824643  
      
      Ordered probit regression                               Number of obs =     69
                                                              LR chi2(2)    =  17.73
                                                              Prob > chi2   = 0.0001
      Log likelihood = -84.824643                             Pseudo R2     = 0.0946
      
      ------------------------------------------------------------------------------
             rep78 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
             price |   .1317976   .0548115     2.40   0.016     .0243691    .2392262
            weight |  -1.927944     .46756    -4.12   0.000    -2.844345   -1.011543
      -------------+----------------------------------------------------------------
             /cut1 |  -3.945445   .6535409                     -5.226361   -2.664528
             /cut2 |  -3.063049   .6031377                     -4.245177    -1.88092
             /cut3 |  -1.641716   .5561489                     -2.731748   -.5516842
             /cut4 |  -.6576951   .5204988                     -1.677854    .3624639
      ------------------------------------------------------------------------------
      
      .
      . // compute marginal effects
      . margins, dydx(*) post
      
      Average marginal effects                                    Number of obs = 69
      Model VCE: OIM
      
      dy/dx wrt: price weight
      
      1._predict: Pr(rep78==1), predict(pr outcome(1))
      2._predict: Pr(rep78==2), predict(pr outcome(2))
      3._predict: Pr(rep78==3), predict(pr outcome(3))
      4._predict: Pr(rep78==4), predict(pr outcome(4))
      5._predict: Pr(rep78==5), predict(pr outcome(5))
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
      price        |
          _predict |
                1  |  -.0087722   .0059431    -1.48   0.140    -.0204204     .002876
                2  |  -.0178039   .0086162    -2.07   0.039    -.0346914   -.0009164
                3  |   -.017579   .0078997    -2.23   0.026    -.0330621   -.0020959
                4  |   .0171142   .0073932     2.31   0.021     .0026238    .0316045
                5  |   .0270409   .0116786     2.32   0.021     .0041513    .0499305
      -------------+----------------------------------------------------------------
      weight       |
          _predict |
                1  |     .12832    .076828     1.67   0.095      -.02226    .2789001
                2  |   .2604368   .0867301     3.00   0.003      .090449    .4304246
                3  |   .2571468   .0774315     3.32   0.001     .1053839    .4089097
                4  |  -.2503475   .0698052    -3.59   0.000    -.3871632   -.1135317
                5  |  -.3955562   .1041235    -3.80   0.000    -.5996344   -.1914779
      ------------------------------------------------------------------------------
      
      .
      . // create a table from the marginal effects
      . etable, showeq
      
      ------------------------------
                                1   
      ------------------------------
      price (1000$)                 
        _predict                    
          1                   -0.009
                             (0.006)
          2                   -0.018
                             (0.009)
          3                   -0.018
                             (0.008)
          4                    0.017
                             (0.007)
          5                    0.027
                             (0.012)
      weight (1000kg)               
        _predict                    
          1                    0.128
                             (0.077)
          2                    0.260
                             (0.087)
          3                    0.257
                             (0.077)
          4                   -0.250
                             (0.070)
          5                   -0.396
                             (0.104)
      Number of observations      69
      ------------------------------
      
      .
      . // put the outcome categories in the columns
      . collect layout (coleq#result[_r_b _r_se]) ///
      >                (colname[]#stars[value])
      
      Collection: ETable
            Rows: coleq#result[_r_b _r_se]
         Columns: colname[]#stars[value]
         Table 1: 4 x 5
      
      -------------------------------------------------------
                                      _predict               
                         1       2       3       4       5   
      -------------------------------------------------------
      price (1000$)    -0.009  -0.018  -0.018   0.017   0.027
                      (0.006) (0.009) (0.008) (0.007) (0.012)
      weight (1000kg)   0.128   0.260   0.257  -0.250  -0.396
                      (0.077) (0.087) (0.077) (0.070) (0.104)
      -------------------------------------------------------
      
      .                            
      . // give those columns names                        
      . collect label levels colname ///
      >     1._predict "Poor"        ///
      >     2._predict "Fair"        ///
      >     3._predict "Average"     ///
      >     4._predict "Good"        ///
      >     5._predict "Excellent"
      
      . collect preview
      
      ---------------------------------------------------------
                        Poor    Fair  Average   Good  Excellent
                                                               
      ---------------------------------------------------------
      price (1000$)    -0.009  -0.018  -0.018   0.017     0.027
                      (0.006) (0.009) (0.008) (0.007)   (0.012)
      weight (1000kg)   0.128   0.260   0.257  -0.250    -0.396
                      (0.077) (0.087) (0.077) (0.070)   (0.104)
      ---------------------------------------------------------
      
      .
      . // add the number of observations
      . collect addtags colname[1._predict], fortags(result[N])
      (1 items changed in collection ETable)
      
      . collect layout (coleq#result[_r_b _r_se] result[N]) ///
      >                (colname[]#stars[value])
      
      Collection: ETable
            Rows: coleq#result[_r_b _r_se] result[N]
         Columns: colname[]#stars[value]
         Table 1: 5 x 5
      
      ----------------------------------------------------------------
                               Poor    Fair  Average   Good  Excellent
                                                                      
      ----------------------------------------------------------------
      price (1000$)           -0.009  -0.018  -0.018   0.017     0.027
                             (0.006) (0.009) (0.008) (0.007)   (0.012)
      weight (1000kg)          0.128   0.260   0.257  -0.250    -0.396
                             (0.077) (0.087) (0.077) (0.070)   (0.104)
      Number of observations      69                                  
      ----------------------------------------------------------------
      You can now export the table to your prefered system using collect export
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Andrew Musau I have tried margins, dydx(*) post. Still when I visit the file it shows the coefficient from the probit model.
        Thank you so much I will try this Maarten Buis.

        Comment


        • #5
          You don't show the actual commands and Stata output, but you will need to reference the active results

          Code:
          margins, dydx(*) post
          esttab . using myfile.rtf, replace
          or store the estimates and refer to them

          Code:
          margins, dydx(*) post
          est sto m1
          esttab m1 using myfile.rtf, replace

          Comment

          Working...
          X