Announcement

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

  • Pairwise comparisons of average marginal effects

    Dear all,

    I am using survey data collecting information on consumer conditions, such as consumer knowledge, trust in consumer organisations etc.
    I am currently running some analyses to determine differences in these "consumer conditions" across various socio-demographic groups for which information is available in the survey.

    The consumer knowledge indicator for instance equals to the total of correct answers a consumer gave on several answers in the survey.

    In a first descriptive analysis I use the following "pwmean commands" to obtain the means for the survey-weigthed consumer knowledge indicator (knowledge_tot=knowledge_tot*w1) per socio-demographic group.
    I define the code as follows (I add the option "groups" to obtain codes that group them with other means that are not significantly different)
    pwmean knowledge_tot_w, over(age) effects groups
    pwmean knowledge_tot_w, over(gender) effects groups
    pwmean knowledge_tot_w, over(education) effects groups

    In a second analysis I run a Poisson model (weighted for the survey data) with the consumer knowledge indicator as dependent variable and the socio-demographic groups as explanatory variables.
    The code I run is as such:
    xi: poisson knowledge_tot i.age i.gender i.education i.occupation i.internet_use i.living i.phone i.language i.financial i.numerical_skills i.region [iweight=w1] if sample==1, vce(robust)

    I calculate average marginal effects as such:
    margins , dydx(*)

    I would like to know whether the average marginal effect of the first age group is statistically different from the one of the second age group, etc. In a sense I am searching to get similar Stata tables as produced by pwmean (see above), but then for the average marginal effects.
    Is this possible? I found out that pwcompare may help me out but I don't get the syntax working.

    Many thanks for your help.

    Best regards,
    Vincent


  • #2
    To make the problem a little bit less abstract, I add the table of average marginal effects below.
    I want to know whether the average marginal effect of _Iage_2 (i.e. 0.215397) is statistically different from the other average marginal effects of the age indicators in the model
    (i.e. _Iage_3, _Iage_4, _Iage_5 and _Iage_6).

    I want to do the same for the other significant variables in the model (e.g. comparing the average marginal effects of _Iinternet__2, _Iinternet__3 and _Iinternet__4).

    Can this be done with the command "pwcompare" or is there a more efficient way to do it?


    Many thanks.

    Best,
    Vincent


    Code:
    . margins, dydx (* )
    
    Average marginal effects                          Number of obs   =      24967
    Model VCE    : Robust
    
    Expression   : Predicted number of events, predict()
    dy/dx w.r.t. : _Iage_2 _Iage_3 _Iage_4 _Iage_5 _Iage_6 _Igender_1 _Ieducation_1 _Ieducation_2 _Ieducation_3 _Ioccupatio_1 _Ioccupatio_2
                   _Ioccupatio_3 _Ioccupatio_5 _Ioccupatio_6 _Ioccupatio_7 _Iinternet__2 _Iinternet__3 _Iinternet__4 _Iliving_2 _Iliving_3 _Iphone_1
                   _Iphone_2 _Ilanguage_2 _Ilanguage_3 _Ilanguage_4 _Ifinancial_1 _Inumerical_1 _Inumerical_2 _Iregion_1 _Iregion_3 _Iregion_4
    
    -------------------------------------------------------------------------------
                  |            Delta-method
                  |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
          _Iage_2 |   .2153971   .0389846     5.53   0.000     .1389886    .2918055
          _Iage_3 |   .3120657   .0388798     8.03   0.000     .2358626    .3882688
          _Iage_4 |    .348996   .0383786     9.09   0.000     .2737754    .4242166
          _Iage_5 |    .373133   .0392649     9.50   0.000     .2961753    .4500908
          _Iage_6 |   .3356493   .0433607     7.74   0.000     .2506639    .4206347
       _Igender_1 |  -.1033431   .0132092    -7.82   0.000    -.1292327   -.0774536
    _Ieducation_1 |   .1248216   .0595757     2.10   0.036     .0080553    .2415878
    _Ieducation_2 |   .0812356   .0563561     1.44   0.149    -.0292203    .1916916
    _Ieducation_3 |   .0922641   .0563854     1.64   0.102    -.0182492    .2027775
    _Ioccupatio_1 |   .0815343   .0347461     2.35   0.019     .0134332    .1496354
    _Ioccupatio_2 |   .0464378   .0306751     1.51   0.130    -.0136843    .1065599
    _Ioccupatio_3 |   .0051644   .0374761     0.14   0.890    -.0682875    .0786163
    _Ioccupatio_5 |   .0676167   .0376191     1.80   0.072    -.0061154    .1413487
    _Ioccupatio_6 |    .068347   .0648261     1.05   0.292    -.0587098    .1954037
    _Ioccupatio_7 |   .0424489   .0352139     1.21   0.228     -.026569    .1114668
    _Iinternet__2 |  -.0894214   .0208784    -4.28   0.000    -.1303423   -.0485005
    _Iinternet__3 |  -.0842017   .0355149    -2.37   0.018    -.1538096   -.0145939
    _Iinternet__4 |  -.1489715   .0188736    -7.89   0.000    -.1859631     -.11198
       _Iliving_2 |  -.0033493   .0155256    -0.22   0.829    -.0337789    .0270802
       _Iliving_3 |  -.0004975   .0164884    -0.03   0.976    -.0328143    .0318192
        _Iphone_1 |    .063669    .016744     3.80   0.000     .0308515    .0964866
        _Iphone_2 |  -.0335981   .0291922    -1.15   0.250    -.0908137    .0236175
     _Ilanguage_2 |    .033027   .0158431     2.08   0.037     .0019752    .0640788
     _Ilanguage_3 |    .065678   .0189585     3.46   0.001       .02852    .1028361
     _Ilanguage_4 |   .1220069    .024065     5.07   0.000     .0748403    .1691735
    _Ifinancial_1 |  -.0645161    .014355    -4.49   0.000    -.0926513   -.0363809
    _Inumerical_1 |   .0282836   .0213877     1.32   0.186    -.0136356    .0702028
    _Inumerical_2 |   .0117576   .0214174     0.55   0.583    -.0302198    .0537349
       _Iregion_1 |   .0375794    .025945     1.45   0.147    -.0132718    .0884307
       _Iregion_3 |   .0040779   .0185895     0.22   0.826    -.0323569    .0405126
       _Iregion_4 |  -.0219858   .0197365    -1.11   0.265    -.0606687    .0166971
    -------------------------------------------------------------------------------
    Last edited by Vincent Van Roy; 04 Mar 2015, 06:55.

    Comment


    • #3
      Does -lincom- get you any closer? I don't know whether such a test is giving you the information you want, but it will run (the -coefleg- option will give you the canonical form of the reference to the coefficients, but lincom also allows shorthands as described in [R] lincom) :

      Code:
      margins, dydx (*) post coefleg
      lincom 2.age-3.age
      One could create a loop to inspect all combinations.
      Stata/MP 14.1 (64-bit x86-64)
      Revision 19 May 2016
      Win 8.1

      Comment


      • #4
        Thanks Carole, I tried what you suggest and it seems that it gives what I want. Unfortunately I have quiet a lot of models and combinations to test, which requires a lot of coding.
        I am still looking for something more efficient.

        Something similar as the output of following code of pwcompare with letters indicating which marginal effects are significantly different or not. (but then not over age but looking at the average marginal effects as is done in your suggested lincom command):

        Code:
        . margins, dydx ( age* ) over(age) pwcompare(group)
        
        Pairwise comparisons of average marginal effects
        Model VCE    : Robust
        
        Expression   : Predicted number of events, predict()
        dy/dx w.r.t. : age_25_34 age_35_44 age_45_54 age_55_64    age_65_more
        over         : age
        
        
        Delta-method Unadjusted
        Margin   Std. Err.      Groups
        
        age_25_34    
        age
        1     .1871067   .0288759
        2     .2292359   .0397672           A
        3     .2426708   .0404171            B
        4     .2437345   .0405792            B
        5     .2442805   .0406544            B
        6     .2271132   .0377877           A
        
        age_35_44    
        age
        1     .2670239   .0278831
        2     .3271474   .0382532           A
        3     .3463206   .0419605            B
        4     .3478387   .0404892            B
        5     .3486179   .0405542            B
        6     .3241181   .0376828           A
        
        age_45_54    
        age
        1     .2970147   .0272539
        2     .3638909   .0379631           A
        3     .3852176   .0400169            B
        4     .3869061   .0415775            B
        5     .3877729   .0402029            B
        6     .3605214    .037356           A
        
        age_55_64    
        age
        1     .3183846   .0278565
        2     .3900724   .0388743           A
        3     .4129335   .0409672            B
        4     .4147436   .0410624            B
        5     .4156727   .0425217            B
        6     .3864605   .0382598           A
        
        age_65_more  
        age
        1     .2898955   .0318271
        2     .3551688   .0428561           A
        3     .3759842   .0452157            B
        4     .3776323   .0453262            B
        5     .3784783   .0454141            B
        6       .35188   .0432129           A
        
        Note: Margins sharing a letter in the group label
        are not significantly different at the 5%
        level.

        Could anybody give me some hint?
        Thanks a lot
        Vincent

        Comment


        • #5
          When margins was introduced in Stata 11, factor variables
          notation also replaced the xi prefix. Using the xi prefix
          with commands that support factor variables notation makes
          margins very difficult to use properly.

          Here is the syntax for fitting Vincent's model using factor variables notation.

          Code:
          poisson knowledge_tot i.age i.gender i.education i.occupation i.internet_use i.living i.phone i.language i.financial i.numerical_skills i.region [iweight=w1] if sample==1, vce(robust)
          For categorical predictors, margins can calculate marginal
          effects in one of three ways.

          The original syntax calls for the dydx() option, which contrasts the
          marginal predictions at each level of the factor with that of a base
          comparison level.

          Code:
          margins, dydx(age)
          Contrast operators were introduced to margins in Stata 12. The
          equivalent contrast syntax for the dydx() option is

          Code:
          margins r.age
          Here the r. denotes the reference category contrast operator.
          The margins output with contrast operators is more expressive
          than with the dydx() option.
          There are other built-in contrast operators, see help for
          margins contrast.

          As Vincent pointed out earlier, we can also perform pairwise comparisons
          of the marginal predictions.

          Code:
          margins age, pwcompare(group)
          See help for margins pwcompare.

          Comment


          • #6
            Many thanks, Jeff. Your code seems to work well and does exactly what I want. So, it seems that the margins command was simply not working for me when using the prefix "xi:" in front of the regression model.
            Last edited by Vincent Van Roy; 06 Mar 2015, 03:57.

            Comment

            Working...
            X