Announcement

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

  • Interaction between dummy variables - doubt on different commands

    Dear members,

    I am running a probit model where I have an interaction between two dummies.

    I am not sure about the tool to use to proceed with the interaction. If I have two dummy variables and want to look at the interaction I may use the following command

    Code:
    probit variableA variableB#variableC, vce(robust)
    but I am not sure if the following instead is the correct one

    Code:
    probit variableA i.variableB##i.variableC, vce(robust)
    I tried to use both and I obtain the same coefficients when variableB takes value 1 and variableC takes value 0, and viceversa. Conversely, the coefficient associated to the hypothesis of variableB and variable C taking both variable 1 differs in the two specifications, despite being significant in both cases.

    I do thank everyone for the attention.

    Marco




  • #2
    Marco,

    this is a bit strange. Results should be the same.

    I tried to replicate your example using a different dataset:


    use http://www.stata-press.com/data/r13/fvex

    tab group, gen(gr)

    regress y sex#gr1 group age

    regress y i.sex#i.group age

    The two results are showed in the pictures below:

    Click image for larger version

Name:	1.PNG
Views:	1
Size:	43.7 KB
ID:	1399481
    Click image for larger version

Name:	2.PNG
Views:	1
Size:	43.9 KB
ID:	1399482

    Comment


    • #3
      Marco:
      results are in part similar, that is when the two codes overlap:

      Code:
      . use http://www.stata-press.com/data/r13/fvex
      (Artificial factor variables' data)
      
      . probit outcome i.group#i.sex age
      
      Iteration 0:   log likelihood = -1366.0718 
      Iteration 1:   log likelihood = -1070.8001 
      Iteration 2:   log likelihood = -1052.9784 
      Iteration 3:   log likelihood = -1052.7807 
      Iteration 4:   log likelihood = -1052.7804 
      Iteration 5:   log likelihood = -1052.7804 
      
      Probit regression                               Number of obs     =      3,000
                                                      LR chi2(6)        =     626.58
                                                      Prob > chi2       =     0.0000
      Log likelihood = -1052.7804                     Pseudo R2         =     0.2293
      
      ------------------------------------------------------------------------------
           outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
         group#sex |
         1#female  |  -.0868675   .1015371    -0.86   0.392    -.2858767    .1121416
           2#male  |  -.8912614   .1272146    -7.01   0.000    -1.140597   -.6419253
         2#female  |  -.1451219   .1193181    -1.22   0.224    -.3789811    .0887373
           3#male  |  -.9273895   .1544238    -6.01   0.000    -1.230055   -.6247244
         3#female  |  -.6924022   .3465154    -2.00   0.046     -1.37156   -.0132444
                   |
               age |   .0503344   .0035134    14.33   0.000     .0434482    .0572205
             _cons |  -2.828269    .192214   -14.71   0.000    -3.205002   -2.451537
      ------------------------------------------------------------------------------
      
      . probit outcome i.group##i.sex age
      
      Iteration 0:   log likelihood = -1366.0718 
      Iteration 1:   log likelihood = -1070.8001 
      Iteration 2:   log likelihood = -1052.9784 
      Iteration 3:   log likelihood = -1052.7807 
      Iteration 4:   log likelihood = -1052.7804 
      Iteration 5:   log likelihood = -1052.7804 
      
      Probit regression                               Number of obs     =      3,000
                                                      LR chi2(6)        =     626.58
                                                      Prob > chi2       =     0.0000
      Log likelihood = -1052.7804                     Pseudo R2         =     0.2293
      
      ------------------------------------------------------------------------------
           outcome |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
             group |
                2  |  -.8912614   .1272146    -7.01   0.000    -1.140597   -.6419253
                3  |  -.9273895   .1544238    -6.01   0.000    -1.230055   -.6247244
                   |
               sex |
           female  |  -.0868675   .1015371    -0.86   0.392    -.2858767    .1121416
                   |
         group#sex |
         2#female  |    .833007   .1529765     5.45   0.000     .5331786    1.132835
         3#female  |   .3218548   .3664307     0.88   0.380     -.396336    1.040046
                   |
               age |   .0503344   .0035134    14.33   0.000     .0434482    .0572205
             _cons |  -2.828269    .192214   -14.71   0.000    -3.205002   -2.451537
      ------------------------------------------------------------------------------
      
      .
      That said, I would endorse your second code, as it correctly takes both interaction and conditional main effect of the two interacted preditors.
      In fact, including interaction only is rarely advisable in regression model.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Dear dmaimone, dear Carlo,

        I do thank you very much for your prompt and precise indications.

        Many many thanks.

        Regards,

        Marco

        Comment


        • #5
          Dear Carlo,

          I have a further question if I may.

          I am running a probit model with an interaction as follows:

          Code:
          probit variableA i.variableB##i.variableC, vce(robust)
          I would like to compute the marginal effects after the probit, but if I try the following command:

          Code:
          margins dydx dydx(i.variableB##i.variableC)
          I received the following error message:

          Code:
          invalid dydx() option;
          levels of interactions not allowed
          r(198);
          I would be very thankful if someone could help me in this respect.

          Is the only solution to create a brand new variable as a result of the two interaction?

          Many many thanks.




          Comment


          • #6
            Marco:
            try:
            Code:
            . margins variableB##variableC
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Dear Carlo,

              Thank you very much for your kind reply.

              The solution you proposed works perfectly.

              Out of curiosity. Why the
              Code:
              dydx
              does not work and why we not need to put the "i." in front of the categorical variables to get these
              Code:
              margins
              ?

              Many thanks Carlo.

              Regards

              Marco

              Comment


              • #8
                Marco:
                I've learnt it myself, too from -help margins-!
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment


                • #9
                  Dear Carlo,

                  Thank you very much for your kind indication.

                  Many many thanks!

                  Regards

                  Marco

                  Comment

                  Working...
                  X