Announcement

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

  • Exporting marginal effects (first differences and contrasts) to word

    Dear all,
    I need your help on how I would be able to export marginal effects (both first differences and second differences) of interactions from Stata to word. I fit a logit model:
    svy: logit outcomvar i.v106_new i.v025 i.adolescent_age_F i.media_new i.husband_edu_new i.v190 i.region_f i.religion_f i.women_occupation i.husband_occupation i.wantedness_child i.birthor i.v106_new#i.v025 i.v106_new#i.adolescent_age_F i.v106_new#i.media_new i.v106_new#i.husband_edu_new i.v025#i.media_new i.v025#i.husband_edu_new i.v025#i.adolescent_age_F i.adolescent_age_F#i. husband_edu_new i.media_new#i.husband_edu_new i.v025#i.wantedness_child i.media_new#i.wantedness_child i.adolescent_age_F#i.wantedness_child i.v025#i.v106_new#i.media_new i.women_occupation i.husband_occupation i.wantedness_child i.birthor

    Then I do this

    margins v106_new#v025
    then this:
    margins v025, dydx (v106_new)
    Finally this:
    margins v025, dydx (v106_new) pwcompare (effects)
    Now I want to do these codes for all interacting variables (not just for the interaction between v025 and v106_new, but for all the interaction in my model) and export the result to word in tables. I want to export the
    dydx () of both first differences ( margins v025, dydx (v106_new) and second differences/ contrasts) (margins v025, dydx (v106_new) pwcompare (effects) for all interactions at once.

    Your help is much appreciated.
    Regards,

  • #2
    This is just a general approach using estout from SSC. No reproducible example, so this is not tested.

    Code:
    ssc install estout, replace
    svy: logit outcomvar ...
    est sto results
    margins v106_new#v025, post
    est sto m1
    est restore results
    margins v025, dydx (v106_new) post
    est sto m2
    est restore results
    margins v025, dydx (v106_new) pwcompare (effects) post
    est sto m3
    esttab m1 m2 m3 using myfile.rtf, replace

    Comment


    • #3
      Thank you. The code exports the results of the first two lines (margins v106_new#v025, post and margins v025, dydx (v106_new) post).
      I cannot still export outputs from the 3rd code:
      margins v025, dydx (v106_new) pwcompare (effects) post.

      I really appreciate any help to do this. Also, I want to automate the export to word of all the interactions in my model.

      Comment


      • #4
        margins v025, dydx (v106_new) pwcompare (effects) post.
        This works for me:

        Code:
        webuse nhanes2, clear
        logistic highbp sex##agegrp##c.bmi
        eststo est3: margins agegrp, pwcompare(group) post
        esttab est3
        Res.:

        Code:
        . eststo est3: margins agegrp, pwcompare(group) post
        
        Pairwise comparisons of predictive margins              Number of obs = 10,351
        Model VCE: OIM
        
        Expression: Pr(highbp), predict()
        
        -------------------------------------------------
                     |            Delta-method Unadjusted
                     |     Margin   std. err.      groups
        -------------+-----------------------------------
              agegrp |
              20-29  |   .2030932   .0087166
              30-39  |   .2829091    .010318
              40-49  |   .3769536   .0128744
              50-59  |   .5153439   .0136201
              60-69  |   .5641065    .009136
                70+  |   .6535679   .0151371
        -------------------------------------------------
        Note: Margins sharing a letter in the group label
              are not significantly different at the 5%
              level.
        
        . 
        . esttab est3
        
        ----------------------------
                              (1)   
                                    
        ----------------------------
        1.agegrp            0.203***
                          (23.30)   
        
        2.agegrp            0.283***
                          (27.42)   
        
        3.agegrp            0.377***
                          (29.28)   
        
        4.agegrp            0.515***
                          (37.84)   
        
        5.agegrp            0.564***
                          (61.75)   
        
        6.agegrp            0.654***
                          (43.18)   
        ----------------------------
        N                   10351   
        ----------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001
        
        .

        Also, I want to automate the export to word of all the interactions in my model.
        Do you mean the coefficients? You stored them as results in the code #1, so

        Code:
        esttab results m1 m2 m3 using myfile.rtf, replace

        Comment


        • #5
          Thank you. m1 and m2 are exported. But results of m3, the contrast, is not. I want to export the results stored in m2 and m3, for all interactions.
          I kindly wait for your help to this problem. It saves me a lot of time because I have more than 10 variables in the interactions and I want to export their first and second differences automatically at one go.
          Regards,

          Comment


          • #6
            Use my data example in #2 and point out what results you want. Or present your data example using the dataex command. Beyond what I have shown, I cannot follow what you want.

            Comment


            • #7
              Dear Dr Andrew thank you so much.

              Let me explain what I want exactly.

              I tried the code you advised me to do:

              Code:
               
               esttab m1 m2 m3 using myfile.rtf, replace
              However, the result stored in m3 is not exported. Only results in m1 and m2 are exported.

              But my aim is to export m3, not in m1 and m2. Then, I want to do the same (export their second differences) for all other interactions in my model (#1).


              Any effort to assist me is highly appreciated.

              Regards,


              Comment

              Working...
              X