Announcement

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

  • marginsplot using with pwcompare

    Dear all,
    I used the following command
    Code:
    probit High_Q_S  i.TCZ##ib1997.year_birth Xs
    margins year_birth, dydx(TCZ) noestimcheck post pwcompare(effects)
    To get the following table

    Code:
    Pairwise comparisons of average marginal effects
    Model VCE    : Robust
    
    Expression   : Pr(High_Q_S), predict()
    dy/dx w.r.t. : 1.TCZ
    
    -------------------------------------------------------------------------------
                  |   Contrast Delta-method    Unadjusted           Unadjusted
                  |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
    1.TCZ         |
       year_birth |
    1993 vs 1992  |   .0338556   .0947729     0.36   0.721    -.1518958    .2196071
    1994 vs 1992  |   .1447371   .0810518     1.79   0.074    -.0141216    .3035958
    1995 vs 1992  |  -.0182139   .0897682    -0.20   0.839    -.1941563    .1577286
    1996 vs 1992  |   .0640309   .0997219     0.64   0.521    -.1314205    .2594823
    1997 vs 1992  |   .0549888   .0832132     0.66   0.509    -.1081061    .2180838
    1998 vs 1992  |   .1352737   .0891437     1.52   0.129    -.0394448    .3099921
    1999 vs 1992  |   .0828824   .0994943     0.83   0.405    -.1121228    .2778875
    1994 vs 1993  |   .1108815   .0712267     1.56   0.120    -.0287203    .2504832
    1995 vs 1993  |  -.0520695   .0666381    -0.78   0.435    -.1826778    .0785388
    1996 vs 1993  |   .0301753   .0838794     0.36   0.719    -.1342254    .1945759
    1997 vs 1993  |   .0211332   .0694659     0.30   0.761    -.1150174    .1572838
    1998 vs 1993  |    .101418   .0703358     1.44   0.149    -.0364376    .2392737
    1999 vs 1993  |   .0490267   .0700038     0.70   0.484    -.0881781    .1862316
    1995 vs 1994  |   -.162951   .0699753    -2.33   0.020       -.3001   -.0258019
    1996 vs 1994  |  -.0807062    .089244    -0.90   0.366    -.2556211    .0942088
    1997 vs 1994  |  -.0897482   .0693053    -1.29   0.195    -.2255841    .0460876
    1998 vs 1994  |  -.0094634   .0740236    -0.13   0.898    -.1545471    .1356202
    1999 vs 1994  |  -.0618547   .0759032    -0.81   0.415    -.2106223    .0869128
    1996 vs 1995  |   .0822448   .0857709     0.96   0.338    -.0858632    .2503527
    1997 vs 1995  |   .0732027   .0665905     1.10   0.272    -.0573122    .2037177
    1998 vs 1995  |   .1534875   .0668704     2.30   0.022      .022424     .284551
    1999 vs 1995  |   .1010962   .0729121     1.39   0.166    -.0418088    .2440013
    1997 vs 1996  |   -.009042   .0748278    -0.12   0.904    -.1557019    .1376178
    1998 vs 1996  |   .0712428   .0732969     0.97   0.331    -.0724166    .2149021
    1999 vs 1996  |   .0188515   .0841226     0.22   0.823    -.1460258    .1837287
    1998 vs 1997  |   .0802848   .0728376     1.10   0.270    -.0624742    .2230438
    1999 vs 1997  |   .0278935   .0695323     0.40   0.688    -.1083874    .1641744
    1999 vs 1998  |  -.0523913   .0747191    -0.70   0.483     -.198838    .0940554
    -------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    I am only interested in the comparisons of each year with 1997.
    So I saved the results, keep only the marginal effects I am interested in as follows:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(_deriv _term _predict _at _atopt) float(_margin _se _statistic _pvalue _ci_lb _ci_ub) int _m1 byte _pw
    2 1 . . .  -.05498885  .08321324   .6608185 .50872874  -.1081061  .2180838 1992  5
    2 1 . . . -.021133216  .06946585   .3042245  .7609568 -.11501735  .1572838 1993 11
    2 1 . . .   .08974823  .06930527   -1.29497  .1953306 -.22558407  .0460876 1994 16
    2 1 . . . -.073202714  .06659049  1.0992969 .27163857 -.05731224 .20371766 1995 20
    2 1 . . .  .009042049  .07482783 -.12083805  .9038193  -.1557019  .1376178 1996 23
    2 1 . . .   .08028481 .072837554  1.1022447  .2703553 -.06247418  .2230438 1998 26
    2 1 . . .   .02789351  .06953234   .4011588  .6883032 -.10838737  .1641744 1999 27
    end
    label values _deriv _deriv
    label def _deriv 2 "1.TCZ", modify
    label values _term _terml
    label def _terml 1 "High quality high school", modify
    label values _pw _pwl
    label def _pwl 5 "1992 vs 1997", modify
    label def _pwl 11 "1993 vs 1997", modify
    label def _pwl 16 "1994 vs 1997", modify
    label def _pwl 20 "1995 vs 1997", modify
    label def _pwl 23 "1996 vs 1997", modify
    label def _pwl 26 "1998 vs 1997", modify
    label def _pwl 27 "1999 vs 1997", modify


    Then used;
    Code:
    marginsplot using marginsHigh, yline(0) level(95)
    I got the following

    high.gph

    While I want a graph where the reference is 1997 so the marginal effect for 1997 to be shown as 0 on the graph as in here :

    high2.gph

    I really appreciate any remarks. Thank you.

  • #2
    Instead of pairwise comparisons, you can request contrasts of the marginal means and specify a custom base for the year variable.

    Code:
    probit High_Q_S  i.TCZ##ib1997.year_birth Xs
    margins rb1997.year_birth#TCZ, noestimcheck
    marginsplot

    Comment


    • #3
      Thank you for your answer Jeff Pitblado (StataCorp).
      That's exactly what I was looking for!
      But can I also add the point 1997 vs 1997 which should appear as 0 on the graph, please?

      Comment


      • #4
        You will have to modify the data that marginsplot uses to produce the plot.
        It is possible, you just need to know about margins option saving() and how to modify the dataset.
        Here is an example based on a dataset used in the probit documentation.

        Code:
        webuse union
        
        probit union age grade not_smsa south##b73.year
        
        * save the -margins- results to a dataset that can be used by -marginsplot-
        margins rb73.year#south, saving(marg, replace)
        
        * default margins plot
        marginsplot, xlabel(, angle(90))
        
        * use -frame- to modify a copy of the -margins- results dataset,
        * use -preserve- and -restore- if you cannot use -frame-
        frame create marg
        frame marg {
            use marg
            label list
            label define _m1 73 "73 vs 73", modify
            expand 2 in 1
            replace _m1 = 73 in 1
            replace _margin = 0 in 1
            replace _se_margin = 0 in 1
            replace _statistic = 0 in 1
            replace _pvalue = . in 1
            replace _ci_lb = . in 1
            replace _ci_ub = . in 1
            save marg-mod, replace
        }
        
        * call marginsplot with your modified margins results (dataset)
        marginsplot using marg-mod, xlabel(, angle(90))
        The relevant documentation is available via help margins saving and help marginsplot using.
        Last edited by Jeff Pitblado (StataCorp); 01 Dec 2022, 14:47.

        Comment


        • #5
          Hi Jeff Pitblado (StataCorp), thank you so much, this is of great help for me!!

          Comment

          Working...
          X