Announcement

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

  • Estimating treatment effects for each interacting variable level and testing for equal treatment effects across these levels in one command

    Dear Statalisters,

    Like the title says, I am trying to (1) estimate treatment effects at each level of a variable I interact with the treatment variable, and (2) test whether these treatment effects are equal across these levels, in one command. This is in the context of a binary outcome, so by treatment effect I mean the effect of the treatment on the probability of success. For example, if I'm interacting a treatment variable (three levels) with education (three levels), I'd like to estimate the treatment effects conditional on each education level and test for equal treatment effects across education levels.

    I can do it in two commands (see below for a bare-bone example), but I'm wondering if there is a way to do it in one through margins, contrast.
    Code:
    logit intent_b group##educ
    margins educ, dydx(group) post
    contrast educ, atequations
    Output:
    Code:
    . logit intent_b group##educ
    
    Iteration 0:  Log likelihood = -5386.1972  
    Iteration 1:  Log likelihood = -5326.3177  
    Iteration 2:  Log likelihood = -5326.2313  
    Iteration 3:  Log likelihood = -5326.2313  
    
    Logistic regression                                     Number of obs =  8,103
                                                            LR chi2(8)    = 119.93
                                                            Prob > chi2   = 0.0000
    Log likelihood = -5326.2313                             Pseudo R2     = 0.0111
    
    --------------------------------------------------------------------------------------------------------------------
                                              intent_b | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    ---------------------------------------------------+----------------------------------------------------------------
                                                 group |
                                          Treatment 1  |  -.0227693   .1043158    -0.22   0.827    -.2272246     .181686
                                          Treatment 2  |   .0744928   .1027005     0.73   0.468    -.1267966    .2757821
                                                       |
                                                  educ |
                Short-cycle tertiary or some tertiary  |  -.3777486    .102155    -3.70   0.000    -.5779687   -.1775285
                                             Tertiary  |   .2209682   .0974774     2.27   0.023     .0299161    .4120204
                                                       |
                                            group#educ |
    Treatment 1#Short-cycle tertiary or some tertiary  |   .0695456   .1437746     0.48   0.629    -.2122475    .3513386
                                 Treatment 1#Tertiary  |   .0646161    .139141     0.46   0.642    -.2080953    .3373274
    Treatment 2#Short-cycle tertiary or some tertiary  |  -.0529544   .1437266    -0.37   0.713    -.3346533    .2287445
                                 Treatment 2#Tertiary  |  -.0677267   .1376612    -0.49   0.623    -.3375376    .2020842
                                                       |
                                                 _cons |  -.4554755   .0723716    -6.29   0.000    -.5973213   -.3136298
    --------------------------------------------------------------------------------------------------------------------
    
    . margins educ, dydx(group) post
    
    Conditional marginal effects                             Number of obs = 8,103
    Model VCE: OIM
    
    Expression: Pr(intent_b), predict()
    dy/dx wrt:  2.group 3.group
    
    --------------------------------------------------------------------------------------------------------
                                           |            Delta-method
                                           |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
    ---------------------------------------+----------------------------------------------------------------
    1.group                                |  (base outcome)
    ---------------------------------------+----------------------------------------------------------------
    2.group                                |
                                      educ |
                 Upper secondary or below  |   -.005393    .024705    -0.22   0.827    -.0538139    .0430279
    Short-cycle tertiary or some tertiary  |   .0099681   .0210726     0.47   0.636    -.0313334    .0512696
                                 Tertiary  |   .0103429   .0227564     0.45   0.649    -.0342588    .0549446
    ---------------------------------------+----------------------------------------------------------------
    3.group                                |
                                      educ |
                 Upper secondary or below  |   .0178302   .0245789     0.73   0.468    -.0303436    .0660039
    Short-cycle tertiary or some tertiary  |   .0045676   .0213205     0.21   0.830    -.0372199    .0463551
                                 Tertiary  |   .0016691   .0226137     0.07   0.941    -.0426529    .0459912
    --------------------------------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    
    . contrast educ, atequations
    
    Contrasts of conditional marginal effects                Number of obs = 8,103
    Model VCE: OIM
    
    Expression: Pr(intent_b), predict()
    dy/dx wrt:  2.group 3.group
    
    ------------------------------------------------
                 |         df        chi2     P>chi2
    -------------+----------------------------------
    1b.group     |
            educ |  (omitted)
    -------------+----------------------------------
    2.group      |
            educ |          2        0.28     0.8675
    -------------+----------------------------------
    3.group      |
            educ |          2        0.26     0.8772
    ------------------------------------------------
    
    .
    Edit: if you're wondering the point of this example, the group variable doesn't correspond to any actual group assignment (participants were randomized into two groups but I wanted to make this work for a more general case for other reasons).
    Last edited by Maxime Bercholz; 25 Oct 2024, 09:25.

  • #2
    Something like what is below should display the predicted probability (after logistic if I recall the manual correctly) of each treatment at each level of education. You should use factor notation in your logistic regression so that it makes life easier for margins.

    Code:
    margins i.treatment,at(education=(1 2 3))
    below will give you the effects of each treatment, relative to the reference category, by level of education.
    Code:
    margins r.treatment,at(education=( 1 2 3))
    And for the adjacent comparisons.
    Code:
    margins r.treatment,at(education=( 1 2 3))

    Comment


    • #3
      adjacent should be


      Code:
      margins ar.treatment,at(education=( 1 2 3))

      Comment

      Working...
      X