Announcement

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

  • Marginal Effects with Factor Variables

    I want to calculate the marginal effects of my control variables. I use factor variables for categorical variables and for interactions, but I have different results when I use the factor variables compared to not using using the factor variables. I do not understand what am I doing wrong, please find attached the two different set of results.

    Code:
    . glm A c1r c1l c1c B C D E F G H I J K L M N O i.country, fa(b) link(logit) vce(robust)
    note: vote1 has noninteger values
    
    Iteration 0:   log pseudolikelihood =  -42.94693  
    Iteration 1:   log pseudolikelihood =  -42.86314  
    Iteration 2:   log pseudolikelihood = -42.862902  
    Iteration 3:   log pseudolikelihood = -42.862902  
    
    Generalized linear models                         No. of obs      =        109
    Optimization     : ML                             Residual df     =         66
                                                      Scale parameter =          1
    Deviance         =  2.554759242                   (1/df) Deviance =   .0387085
    Pearson          =  2.449876389                   (1/df) Pearson  =   .0371193
    
    Variance function: V(u) = u*(1-u/1)               [Binomial]
    Link function    : g(u) = ln(u/(1-u))             [Logit]
    
                                                      AIC             =   1.575466
    Log pseudolikelihood = -42.86290183               BIC             =  -307.0742
    
    -------------------------------------------------------------------------------------
                        |               Robust
                  A |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    --------------------+----------------------------------------------------------------
                    c1r |  -8.777873   6.446331    -1.36   0.173    -21.41245    3.856704
                    c1l |  -5.230066   9.232645    -0.57   0.571    -23.32572    12.86559
                    c1c |   14.04833   12.72731     1.10   0.270    -10.89674     38.9934
          B |   .5111221   1.002131     0.51   0.610    -1.453019    2.475264
              C |  -.2158331   .1219806    -1.77   0.077    -.4549108    .0232445
           D |  -1.015791   .6120185    -1.66   0.097    -2.215326    .1837427
           E |   -1.34568   .6942753    -1.94   0.053    -2.706434    .0150751
               F |   1.913601   1.263446     1.51   0.130    -.5627074    4.389909
               G |    3.03058   1.415898     2.14   0.032     .2554705     5.80569
               H |  -1.232532    .465843    -2.65   0.008    -2.145567   -.3194963
             I |   9.664852   5.081045     1.90   0.057    -.2938134    19.62352
             J |  -6.138072   5.524545    -1.11   0.267    -16.96598    4.689838
       K |   6.307305   2.485234     2.54   0.011     1.436336    11.17827
    L |   .2637226   .1204656     2.19   0.029     .0276144    .4998309
       M |   .0157357   .0524758     0.30   0.764     -.087115    .1185864
    N |   -5.59704   1.892737    -2.96   0.003    -9.306737   -1.887342
      O |   1.622794   1.562146     1.04   0.299    -1.438957    4.684544
                        |
                country |
                     2  |  -.3174748   .2825339    -1.12   0.261    -.8712311    .2362816
                     3  |   .9050205   .5325704     1.70   0.089    -.1387983    1.948839
                     5  |   .6366366   .3458818     1.84   0.066    -.0412793    1.314553
                     6  |  -.8061525   .3245252    -2.48   0.013     -1.44221   -.1700948
                     7  |   .9979821   .5256645     1.90   0.058    -.0323014    2.028266
                     8  |  -.3019033   .2208869    -1.37   0.172    -.7348336    .1310271
                     9  |   1.793135   1.120034     1.60   0.109    -.4020915    3.988362
                    10  |   2.935015   1.670142     1.76   0.079    -.3384039    6.208433
                    11  |   1.032755   .2682285     3.85   0.000     .5070367    1.558473
                    12  |   .6142258   .4606796     1.33   0.182    -.2886895    1.517141
                    13  |   .6579136   .2909312     2.26   0.024     .0876989    1.228128
                    14  |   2.322749    1.06672     2.18   0.029      .232017    4.413481
                    15  |   .3860536   .4793302     0.81   0.421    -.5534164    1.325524
                    16  |   .3461292   .6025894     0.57   0.566    -.8349244    1.527183
                    17  |  -.4832077   .7065197    -0.68   0.494    -1.867961    .9015454
                    18  |   1.483425   .3839561     3.86   0.000     .7308851    2.235965
                    19  |   .0972213   .3887099     0.25   0.803     -.664636    .8590787
                    20  |   .8722559   .5144817     1.70   0.090    -.1361096    1.880621
                    21  |    .846566   .3115486     2.72   0.007     .2359419     1.45719
                    22  |   1.283534   .5730708     2.24   0.025     .1603358    2.406732
                    23  |   1.252627    .498347     2.51   0.012     .2758851    2.229369
                    24  |   .4272264   .3648452     1.17   0.242    -.2878572     1.14231
                    25  |     2.1732   .8145399     2.67   0.008     .5767307    3.769668
                    26  |  -.5704112   .3033152    -1.88   0.060    -1.164898    .0240757
                    27  |   1.839924   1.113983     1.65   0.099    -.3434435    4.023291
                        |
                  _cons |  -3.763331    1.28113    -2.94   0.003      -6.2743   -1.252362
    -------------------------------------------------------------------------------------
    
    .

    Code:
     
     glm A c.c1#D c.c1#E c.c1#creelection1 B i.C i.D i.E c.averagegovtexp#D c.averagegovtexp#E c.a
    > veragegovtexp#creelection1 c.I c.J c.K c.L c.M c.N c.O i.country, fa(b) link(logit) vce(robus
    > t)
    
    note: 1.E#c.c1 omitted because of collinearity
    note: 1.creelection1#c.c1 omitted because of collinearity
    note: 1.E#c.averagegovtexp omitted because of collinearity
    note: 1.creelection1#c.averagegovtexp omitted because of collinearity
    note: A has noninteger values
    
    Iteration 0:   log pseudolikelihood = -42.941667  
    Iteration 1:   log pseudolikelihood = -42.859938  
    Iteration 2:   log pseudolikelihood =   -42.8597  
    Iteration 3:   log pseudolikelihood =   -42.8597  
    
    Generalized linear models                         No. of obs      =        109
    Optimization     : ML                             Residual df     =         64
                                                      Scale parameter =          1
    Deviance         =  2.548356364                   (1/df) Deviance =   .0398181
    Pearson          =  2.444726741                   (1/df) Pearson  =   .0381989
    
    Variance function: V(u) = u*(1-u/1)               [Binomial]
    Link function    : g(u) = ln(u/(1-u))             [Logit]
    
                                                      AIC             =   1.612105
    Log pseudolikelihood = -42.85970039               BIC             =  -297.6979
    
    -------------------------------------------------------------------------------------
                        |               Robust
                  A |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    --------------------+----------------------------------------------------------------
      rreelection1#c.c1 |
                     0  |   8.470525   19.76285     0.43   0.668    -30.26394      47.205
                     1  |  -1.580529   23.87824    -0.07   0.947    -48.38102    45.21996
                        |
      lreelection1#c.c1 |
                     0  |   6.771615   12.02922     0.56   0.573    -16.80523    30.34846
                     1  |          0  (omitted)
                        |
      creelection1#c.c1 |
                     0  |  -13.67147   15.70461    -0.87   0.384    -44.45194    17.10901
                     1  |          0  (omitted)
                        |
          B |   .5041213   1.014915     0.50   0.619    -1.485075    2.493317
            1.C |  -.2165275   .1214293    -1.78   0.075    -.4545245    .0214696
         1.D |  -1.076306    .632389    -1.70   0.089    -2.315766    .1631532
         1.E |  -1.412453   .6621664    -2.13   0.033    -2.710276   -.1146312
                        |
           D#|
       c.averagegovtexp |
                     0  |   1.571097   2.247716     0.70   0.485    -2.834346     5.97654
                     1  |   3.604304   2.404048     1.50   0.134    -1.107542    8.316151
                        |
           E#|
       c.averagegovtexp |
                     0  |  -3.163227   1.347199    -2.35   0.019    -5.803689   -.5227646
                     1  |          0  (omitted)
                        |
           creelection1#|
       c.averagegovtexp |
                     0  |    1.20869    .519934     2.32   0.020     .1896384    2.227742
                     1  |          0  (omitted)
                        |
             I |   9.703945   4.878562     1.99   0.047     .1421387    19.26575
             J |  -6.184813   5.818585    -1.06   0.288    -17.58903    5.219403
       K |     6.0959   2.741294     2.22   0.026     .7230625    11.46874
    L |   .2592149   .1332625     1.95   0.052    -.0019748    .5204045
       M |    .024784    .063311     0.39   0.695    -.0993032    .1488713
    N |  -5.528738   1.958356    -2.82   0.005    -9.367046    -1.69043
      O |   1.596015   1.553947     1.03   0.304    -1.449666    4.641695
                        |
                country |
                     2  |  -.3206109   .2972785    -1.08   0.281     -.903266    .2620443
                     3  |   .7806132   .6643167     1.18   0.240    -.5214236     2.08265
                     5  |   .5959516   .4866569     1.22   0.221    -.3578784    1.549781
                     6  |  -.7933917   .3294559    -2.41   0.016    -1.439113   -.1476701
                     7  |   .9247078   .6654651     1.39   0.165    -.3795798    2.228995
                     8  |  -.3031683   .2269195    -1.34   0.182    -.7479223    .1415857
                     9  |   1.808557   1.184715     1.53   0.127    -.5134411    4.130555
                    10  |   2.941216   1.806134     1.63   0.103    -.5987413    6.481174
                    11  |   1.011056   .3283157     3.08   0.002     .3675687    1.654543
                    12  |   .5916792   .5207664     1.14   0.256    -.4290042    1.612363
                    13  |    .611112   .3838553     1.59   0.111    -.1412306    1.363454
                    14  |   2.317612   1.153793     2.01   0.045     .0562189    4.579004
                    15  |   .2948902   .6324098     0.47   0.641    -.9446103    1.534391
                    16  |   .2832857   .7178377     0.39   0.693     -1.12365    1.690222
                    17  |  -.4926725   .7168042    -0.69   0.492    -1.897583    .9122379
                    18  |   1.447373   .4602922     3.14   0.002     .5452173    2.349529
                    19  |   .0948476    .443375     0.21   0.831    -.7741515    .9638466
                    20  |   .8335054   .5799551     1.44   0.151    -.3031856    1.970196
                    21  |   .8195496   .3933186     2.08   0.037     .0486594     1.59044
                    22  |   1.217881   .7061443     1.72   0.085    -.1661364    2.601898
                    23  |   1.207571   .6129117     1.97   0.049     .0062862    2.408856
                    24  |   .4207905   .4571189     0.92   0.357     -.475146    1.316727
                    25  |   2.149276   .9624491     2.23   0.026     .2629099    4.035641
                    26  |  -.5625191    .294506    -1.91   0.056     -1.13974     .014702
                    27  |   1.804801   1.245022     1.45   0.147    -.6353973    4.244999
                        |
                  _cons |  -3.550846   1.789157    -1.98   0.047     -7.05753   -.0441618
    -------------------------------------------------------------------------------------
    
    . 
    end of do-file

  • #2
    Drishta:
    you actually ran two different -glm- models.
    Hence, you got different results, as expected.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      When you use factor variable notation you include some interactions that are not in the original command. Perhaps you computed the interactions yourself but if so we don't see your coding. You may not have computed the interactions correctly or you may have left something out.

      I also wonder if you have copied correctly. The output is garbled even though you use Code tags. You get a note that vote1 has noninteger values but I don't see vote1 in either model. Are you sure you are showing us what you meant to show us?
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Drishta:
        creating interactions by hand has consequences on the number of parameters and residual degrees of freedom at least, as you can see from the following toy-example (much simpler than yours):
        Code:
        . use "http://www.stata-press.com/data/r15/auto.dta"
        (1978 Automobile Data)
        
        . gen foreign_rep78=foreign*rep78
        (5 missing values generated)
        
        . glm price i.foreign##i.rep78, family(gaussian) link(identity)
        note: 1.foreign#1.rep78 identifies no observations in the sample
        note: 1.foreign#2.rep78 identifies no observations in the sample
        note: 1.foreign#5.rep78 omitted because of collinearity
        
        Iteration 0:   log likelihood = -646.28963 
        
        Generalized linear models                         No. of obs      =         69
        Optimization     : ML                             Residual df     =         61
                                                          Scale parameter =    9051022
        Deviance         =  552112351.8                   (1/df) Deviance =    9051022
        Pearson          =  552112351.8                   (1/df) Pearson  =    9051022
        
        Variance function: V(u) = 1                       [Gaussian]
        Link function    : g(u) = u                       [Identity]
        
                                                          AIC             =   18.96492
        Log likelihood   = -646.2896275                   BIC             =   5.52e+08
        
        -------------------------------------------------------------------------------
                      |                 OIM
                price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        --------------+----------------------------------------------------------------
              foreign |
             Foreign  |   2088.167   2351.846     0.89   0.375    -2521.367      6697.7
                      |
                rep78 |
                   2  |   1403.125   2378.422     0.59   0.555    -3258.495    6064.745
                   3  |   2042.574   2204.707     0.93   0.354    -2278.573    6363.721
                   4  |   1317.056   2351.846     0.56   0.575    -3292.478    5926.589
                   5  |       -360   3008.492    -0.12   0.905    -6256.535    5536.535
                      |
        foreign#rep78 |
           Foreign#1  |          0  (empty)
           Foreign#2  |          0  (empty)
           Foreign#3  |  -3866.574   2980.505    -1.30   0.195    -9708.257    1975.109
           Foreign#4  |  -1708.278   2746.365    -0.62   0.534    -7091.053    3674.498
           Foreign#5  |          0  (omitted)
                      |
                _cons |     4564.5   2127.325     2.15   0.032     395.0199     8733.98
        -------------------------------------------------------------------------------
        
        . glm price foreign_rep78, family(gaussian) link(identity)
        
        Iteration 0:   log likelihood = -647.79835 
        
        Generalized linear models                         No. of obs      =         69
        Optimization     : ML                             Residual df     =         67
                                                          Scale parameter =    8608845
        Deviance         =  576792584.9                   (1/df) Deviance =    8608845
        Pearson          =  576792584.9                   (1/df) Pearson  =    8608845
        
        Variance function: V(u) = 1                       [Gaussian]
        Link function    : g(u) = u                       [Identity]
        
                                                          AIC             =   18.83473
        Log likelihood   = -647.7983528                   BIC             =   5.77e+08
        
        -------------------------------------------------------------------------------
                      |                 OIM
                price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        --------------+----------------------------------------------------------------
        foreign_rep78 |  -3.962235   175.7823    -0.02   0.982    -348.4892    340.5647
                _cons |   6151.212   421.1125    14.61   0.000     5325.846    6976.577
        -------------------------------------------------------------------------------
        
        .
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          If I am counting correctly there are 44 coefficients in the first model and 46 in the second. So, two parameters are left out of the first model. Without seeing how you computed things I can't tell you what they are.

          Incidentally, this is another reason I prefer factor variable notation as opposed to coding things myself. I think mistakes are probably less likely if you use factor variable notation.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            Carlo, in your first example you treat rep78 as categorical and in the second you treat it as continuous. That may be Drishta's problem, or it may be that he tried to generate the variables correctly but missed a few of them. It would be possible to compute the interactions correctly yourself but I think you are more likely to make errors if try to do that.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            Stata Version: 17.0 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Richard is correct and I was not that clear in my previous reply.
              The aim was exactly to show that creating interactions by hand often comes with troubles with the risk of comparing apples with oranges (as my example showed).
              I do not know what the reason of Dishta's problem is, but using -fvvarlist- notation save you time and concerns.
              Kind regards,
              Carlo
              (Stata 18.0 SE)

              Comment


              • #8
                Why will you have to compute anything? P values are in the output.
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                Stata Version: 17.0 MP (2 processor)

                EMAIL: [email protected]
                WWW: https://www3.nd.edu/~rwilliam

                Comment

                Working...
                X