Announcement

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

  • Interactioneffect with additive indices

    Hello,

    for my master thesis I want to test interaction effects between different personality traits. I think I know the basic code how to do them (
    Code:
    reg DV IV1##IV2
    ).

    DV = populist attitude
    IV = Big Five Personality traits (additive indices (scale 1 to 10) eg.
    Code:
    egen extraversion=rowmean(talkative sociable notreserved)
    )

    My problem is this: I want to test interactions between two additive indices. If I try to do the interaction, stata tells me “factor variables may not contain noninteger values". Since my additive indices contain noninteger values, I don't know what to do to avoid the problem. I tried adding c. in front of IV1 and IV2, but I'm not sure if this is the right thing to do. If I ad i. the same error appears.

    I did a lot of research, but cannot solve the problem so far. I did try to find out which type of variable my additive indices are, but if I type describe (this is what most people suggested online to find out the type of variable) it just says storage type = float. Or is the type “factor variable" because stata says so in the error message?
    I thought that the problem may be that i don't add the right operator (i. or c.). I also tried (based on my research) to change the storage type from “float" to “byte", but that didn't work out either.

    My questions are:
    - is it possible to do interaction effects with additive indices?
    - how do I know which type of variable I have (continous, factor, categorical, string) and which operator to use (i. or c.)?

    I would be really greatful if anyone has tipps for me on how to do it or maybe even knows what I'm doing wrong.
    Thank you all in advance!
    Vera


  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    When you hit this kind of problem, you should look at the subject index provided in the documentation. It includes under factor variables:
    [U] 11.4.3 Factor variables, [U] 13.9 Indicator
    values for levels of factor variables,
    [..., [U] 25 Working with categorical data and factor variables

    So you should read these sections of the Users Guide.

    Stata recognizes three kinds of factor variables - indicator and categorical variables (which are essentially converted into dummies) and continuous variables. The default is to assume you have an indicator. To tell Stata you have a continuous variable you use c. so your interaction becomes c.IV1##c.IV2 .
    reg DV c.IV1##c.IV2 should run without a problem.

    After running the regression, you'll want to use the margins and marginsplot commands to explore the results.

    Comment


    • #3
      Thank you for your answer. I read the chapters that you suggested, but that didn't help me much, I can't really understand what it means... If I use c. in front of the IV in the interaction, it works, but how can I know that it is also correct? It doesn't really seem correct to me. In the following lines I insert a dataex sample and my Stata code plus outcome:


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(verträglichkeit offenheit extraversion gewissenhaftigkeit neurotizismus populismus)
             .9  .6333333  .7666667 .6538461  .53333336  3.5
              .         .         .        .          .    3
              .         .         .        .          .    .
              .         .         .        .          .  3.5
              .         .         .        .          .    .
              .         .         .        .          .    .
      .53333336  .6333333  .4333333 .6923077         .4    4
             .6        .6  .4333333        1         .7    5
              1  .6333333        .8 .9230769   .2333333 1.75
       .6333333  .6666666  .8666667 .9615385         .3 4.75
              1  .9333333  .7666667 .9615385  .56666666  3.5
       .8333333        .8        .5 .6923077         .7    3
       .8333333  .7666667  .6333333 .8461539         .5    .
              .         .         .        .          .    .
             .6 .53333336 .53333336 .5769231  .53333336    2
             .6  .8333333  .4666666 .7692308         .1 3.75
             .8        .7  .8333333 .9230769   .3333333    2
             .6        .8  .7333333 .7307692  .56666666 1.75
       .8333333  .3666667  .6333333 .9230769  .56666666    .
       .9333333 .56666666 .56666666 .9230769   .2333333  2.5
             .5  .4333333  .8333333 .8076923   .6666666 4.75
       .8333333        .4        .5 .6153846         .4    4
       .7666667  .3333333  .4666666 .3846154  .16666666  2.5
       .8333333  .4666666 .56666666        1         .6  3.5
              .         .         .        .          .    .
       .8666667  .6333333 .56666666 .7692308         .5 3.25
             .6  .3333333        .9        1         .6    .
              .         .         .        .          .  3.5
             .9        .9 .56666666 .6538461         .2    .
              .         .         .        .          . 4.25
       .6333333        .4  .4666666 .7307692   .7666667 3.75
              .         .         .        .          .    .
             .9  .6333333 .56666666 .8076923   .4333333 4.25
       .3666667  .7666667  .6666666 .5769231   .4666666    2
             .7 .53333336 .56666666 .6153846   .3666667    4
       .6333333  .7333333  .6333333 .6538461   .3666667  3.5
              .         .         .        .          .    .
              .         .         .        .          .    .
              .         .         .        .          .    .
       .6333333  .6666666 .56666666 .6153846         .4 2.75
              .         .         .        .          .    .
             .9  .7666667        .7 .9615385 .033333335    4
             .7  .8666667        .6 .7692308   .3666667 2.25
              .         .         .        .          .    .
              .         .         .        .          . 2.25
              .         .         .        .          .    .
       .3333333        .7  .7666667 .7307692         .5    3
              .         .         .        .          .    .
              .         .         .        .          .    4
       .8666667        .5  .4666666 .7307692        .55    2
             .6  .7666667  .8666667 .5769231   .3333333  3.5
       .8333333        .8        .9 .4230769   .3666667 4.25
              .         .         .        .          .    2
       .7666667        .7        .5 .7307692   .4333333    2
             .8        .7  .6333333 .8461539   .4666666    2
              .         .         .        .          . 4.75
              .         .         .        .          . 2.25
       .4666666  .9333333        .5 .8461539         .2 3.25
              .         .         .        .          . 2.75
              1  .9333333  .3333333 .7692308         .2    3
       .6666666  .4666666  .6333333 .4615385   .3333333  3.5
              .         .         .        .          .    .
       .7333333        .7  .7666667 .9230769   .7333333    4
              .         .         .        .          .    .
             .6        .6        .8 .6538461   .3333333 4.75
       .8666667  .4666666  .7333333 .8846154         .4    4
       .7333333  .6666666  .4666666 .8846154         .2 3.75
       .9333333        .7  .9666667 .8461539  .06666667  2.5
             .9  .6666666  .7666667 .8461539         .6    .
       .8333333        .7        .8 .8461539   .7333333    .
       .3333333         0  .3333333 .2307692   .3333333    5
       .8666667 .56666666        .7 .8846154   .7333333    .
             .5  .7666667        .8 .9230769         .6  3.5
              .         .         .        .          .    .
       .8666667        .6        .5 .9615385   .4333333  2.5
       .8666667        .7        .8 .6153846   .4333333 3.75
              .         .         .        .          .    .
       .8666667        .6  .2333333       .5         .4 3.25
       .8333333        .5        .5 .7307692   .4333333 3.25
       .7333333        .4        .7 .8076923         .3 1.75
      .53333336  .7333333        .6       .5         .5    3
             .9  .7666667 .56666666 .8076923  .26666668  1.5
              .         .         .        .          .    .
       .6333333  .7333333  .6666666 .8076923   .4666666    3
              .         .         .        .          .    .
              .         .         .        .          .    .
              .         .         .        .          .    .
              .         .         .        .          .    .
              .         .         .        .          .    3
              1        .6  .4333333 .7115384   .6333333 3.25
              .         .         .        .          .    .
             .9  .7666667  .7666667 .8846154  .16666666    .
              .         .         .        .          .    .
      .53333336 .56666666        .8 .8846154   .8666667 2.25
             .6  .9333333 .56666666 .8846154         .4 4.75
       .9666667  .4666666 .13333334 .9615385         .8 3.25
      .53333336 .26666668 .56666666       .5         .4 3.75
       .8666667  .6333333        .6 .7307692   .3333333 3.25
              .         .         .        .          .    .
       .8666667  .8666667  .7666667 .5769231         .3    2
      end
      Infos regarding the variables:

      IV: scale 0 to 1, additive indices
      DV: scale 1 to 5, additive indices

      An expample how I recode the IV (Personality factors):

      Code:
      gen talkative=W3_f15770b // gesprächig -> E
      label var talkative "Gesprächig" 
      tab talkative
      gen sociable=W3_f15770h // gesellig -> V
      label var sociable "Gesellig"
      tab sociable
      gen notreserved=(10-W3_f15771d) // nicht reserviert -> E
      label var notreserved "Nicht reserviert"
      tab notreserved
      egen extraversion=rowmean(talkative sociable notreserved)
      the I change the sclae to 0 to 1 (here for all 5 IV):
      Code:
      foreach var in neurotizismus offenheit verträglichkeit extraversion ///
      gewissenhaftigkeit {
              qui sum `var'
              replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
      
          }
      Then I recode the DV as follows (labels are in german, sorry!):

      Code:
      gen pop1=W2_f15350a // Variable generieren
      replace pop1=. if W2_f15350a==9 // Missing generieren
      label var pop1 "Volk sollte wichtige politischen Entscheide treffen" // 
      * umbenennen
      tab pop1
      * Die Schweiz würde profitieren, wenn die Meinung des Volkes und nicht der 
      * Eliten stärker berücksichtigt würde.
      gen pop2=W2_f15350b // Variable generieren
      replace pop2=. if W2_f15350b==9 // Missing generieren
      label var pop2 "Meinung des Volkes stärker berücksichtigen" // umbenennen
      tab pop2
      * Politikerinnen und Politiker vertreten vor allem ihre eigenen Interessen und 
      * nicht jene des Volkes.
      gen pop3=W2_f15350c // Variable generieren
      replace pop3=. if W2_f15350c==9 // Missing generieren
      label var pop3 "PolitikerInnen vertreten eigene Interessen" // umbenennen
      tab pop3
      * Politikerinnen und Politiker interessieren sich nicht wirklich dafür, was 
      * Leute wie ich denken.
      gen pop4=W2_f15350d // Variable generieren
      replace pop4=. if W2_f15350d==9 // Missing generieren
      label var pop4 "PolitikerInnen kein Interesse, was Leute denken" // umbenennen
      tab pop4
      
      ** Additiver Index der Populismus-Variablen
      egen populismus=rowmean(pop1 pop2 pop3 pop4) 
      tab populismus
      then this is the code for my interaction (so far, I know its not correct):
      Code:
      reg populismus c.offenheit##c.gewissenhaftigkeit neurotizismus verträglichkeit ///
      extraversion alter geschlecht bildung ideologie sprachregion
      eststo modell12
      esttab modell12
      margins, at (c.offenheit=(1,2,3,4,5) c.gewissenhaftigkeit=(1,2,3,4,5)) //
      marginsplot
      this is the outcome from Stata for the interaction:

      Code:
       reg populismus c.offenheit##c.gewissenhaftigkeit neurotizismus verträglichkeit ///
      > extraversion alter geschlecht bildung ideologie sprachregion
      
            Source |       SS           df       MS      Number of obs   =     5,913
      -------------+----------------------------------   F(11, 5901)     =     49.26
             Model |  405.231334        11  36.8392121   Prob > F        =    0.0000
          Residual |  4413.44049     5,901  .747913997   R-squared       =    0.0841
      -------------+----------------------------------   Adj R-squared   =    0.0824
             Total |  4818.67183     5,912  .815066277   Root MSE        =    .86482
      
      --------------------------------------------------------------------------------------------------
                            populismus |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      ---------------------------------+----------------------------------------------------------------
                             offenheit |  -.3835854   .2729927    -1.41   0.160    -.9187511    .1515803
                    gewissenhaftigkeit |  -.0915518   .2349006    -0.39   0.697     -.552043    .3689395
                                       |
      c.offenheit#c.gewissenhaftigkeit |   .7751958   .3494187     2.22   0.027     .0902073    1.460184
                                       |
                         neurotizismus |   .1510151   .0634505     2.38   0.017     .0266289    .2754014
                       verträglichkeit |  -.3187082   .0783659    -4.07   0.000    -.4723339   -.1650824
                          extraversion |   .0285278   .0703139     0.41   0.685    -.1093131    .1663688
                                 alter |   .0012854   .0006918     1.86   0.063    -.0000709    .0026416
                            geschlecht |  -.1839496   .0237798    -7.74   0.000    -.2305667   -.1373325
                               bildung |  -.2914769   .0206598   -14.11   0.000    -.3319775   -.2509762
                             ideologie |     .05461   .0047169    11.58   0.000     .0453631    .0638569
                          sprachregion |   .0732182   .0263573     2.78   0.005     .0215484    .1248881
                                 _cons |   3.403393    .196018    17.36   0.000     3.019126     3.78766
      --------------------------------------------------------------------------------------------------
      
      . eststo modell12
      
      . esttab modell12
      
      ----------------------------
                            (1)   
                     populismus   
      ----------------------------
      offenheit          -0.384   
                        (-1.41)   
      
      gewissenha~t      -0.0916   
                        (-0.39)   
      
      c.offenhei~t        0.775*  
                         (2.22)   
      
      neurotizis~s        0.151*  
                         (2.38)   
      
      verträglic~t       -0.319***
                        (-4.07)   
      
      extraversion       0.0285   
                         (0.41)   
      
      alter             0.00129   
                         (1.86)   
      
      geschlecht         -0.184***
                        (-7.74)   
      
      bildung            -0.291***
                       (-14.11)   
      
      ideologie          0.0546***
                        (11.58)   
      
      sprachregion       0.0732** 
                         (2.78)   
      
      _cons               3.403***
                        (17.36)   
      ----------------------------
      N                    5913   
      ----------------------------
      t statistics in parentheses
      * p<0.05, ** p<0.01, *** p<0.001
      
      . margins, at (c.offenheit=(1,2,3,4,5) c.gewissenhaftigkeit=(1,2,3,4,5)) //
      
      Predictive margins                              Number of obs     =      5,913
      Model VCE    : OLS
      
      Expression   : Linear prediction, predict()
      
      1._at        : offenheit       =           1
                     gewissenha~t    =           1
      
      2._at        : offenheit       =           1
                     gewissenha~t    =           2
      
      3._at        : offenheit       =           1
                     gewissenha~t    =           3
      
      4._at        : offenheit       =           1
                     gewissenha~t    =           4
      
      5._at        : offenheit       =           1
                     gewissenha~t    =           5
      
      6._at        : offenheit       =           2
                     gewissenha~t    =           1
      
      7._at        : offenheit       =           2
                     gewissenha~t    =           2
      
      8._at        : offenheit       =           2
                     gewissenha~t    =           3
      
      9._at        : offenheit       =           2
                     gewissenha~t    =           4
      
      10._at       : offenheit       =           2
                     gewissenha~t    =           5
      
      11._at       : offenheit       =           3
                     gewissenha~t    =           1
      
      12._at       : offenheit       =           3
                     gewissenha~t    =           2
      
      13._at       : offenheit       =           3
                     gewissenha~t    =           3
      
      14._at       : offenheit       =           3
                     gewissenha~t    =           4
      
      15._at       : offenheit       =           3
                     gewissenha~t    =           5
      
      16._at       : offenheit       =           4
                     gewissenha~t    =           1
      
      17._at       : offenheit       =           4
                     gewissenha~t    =           2
      
      18._at       : offenheit       =           4
                     gewissenha~t    =           3
      
      19._at       : offenheit       =           4
                     gewissenha~t    =           4
      
      20._at       : offenheit       =           4
                     gewissenha~t    =           5
      
      21._at       : offenheit       =           5
                     gewissenha~t    =           1
      
      22._at       : offenheit       =           5
                     gewissenha~t    =           2
      
      23._at       : offenheit       =           5
                     gewissenha~t    =           3
      
      24._at       : offenheit       =           5
                     gewissenha~t    =           4
      
      25._at       : offenheit       =           5
                     gewissenha~t    =           5
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               _at |
                1  |   3.459715   .0424177    81.56   0.000     3.376561    3.542869
                2  |   4.143359   .1819407    22.77   0.000     3.786689    4.500029
                3  |   4.827003   .3277752    14.73   0.000     4.184444    5.469563
                4  |   5.510647   .4741326    11.62   0.000     4.581174    6.440121
                5  |   6.194291   .6206432     9.98   0.000     4.977603    7.410979
                6  |   3.851325   .1452241    26.52   0.000     3.566633    4.136018
                7  |   5.310165   .6024214     8.81   0.000     4.129199    6.491132
                8  |   6.769005   1.081116     6.26   0.000     4.649622    8.888388
                9  |   8.227845   1.561663     5.27   0.000     5.166413    11.28928
               10  |   9.686685   2.042756     4.74   0.000     5.682136    13.69123
               11  |   4.242936   .2515051    16.87   0.000     3.749894    4.735978
               12  |   6.476971   1.038168     6.24   0.000     4.441783     8.51216
               13  |   8.711007   1.861674     4.68   0.000     5.061444    12.36057
               14  |   10.94504   2.688377     4.07   0.000      5.67484    16.21524
               15  |   13.17908   3.516022     3.75   0.000     6.286389    20.07177
               16  |   4.634546    .358181    12.94   0.000      3.93238    5.336712
               17  |   7.643778   1.475718     5.18   0.000     4.750829    10.53673
               18  |   10.65301   2.645466     4.03   0.000     5.466927    15.83909
               19  |   13.66224   3.819756     3.58   0.000     6.174121    21.15036
               20  |   16.67147   4.995385     3.34   0.001     6.878688    26.46425
               21  |   5.026157     .46498    10.81   0.000     4.114626    5.937688
               22  |   8.810584   1.913836     4.60   0.000     5.058764     12.5624
               23  |   12.59501   3.430276     3.67   0.000     5.870414    19.31961
               24  |   16.37944   4.952604     3.31   0.001     6.670521    26.08835
               25  |   20.16386   6.476669     3.11   0.002     7.467223    32.86051
      ------------------------------------------------------------------------------
      
      . marginsplot
      
        Variables that uniquely identify margins: offenheit gewissenhaftigkeit
      I don't know if it is correct to use c., but its the only way the interaction effect works.
      I would appreciate help regarding the coding, and if c. is the right way to do the interaction.

      I'm sorry the post is very long...

      Thank you very much!
      Regards, Vera

      Comment


      • #4
        A long post isn't a problem when the length is due to helpful information, as here.

        The variables you are using would in many cases be treated as continuous variables the way you have done it. Each one is clearly at least an ordinal measure, if not interval or ratio. Moreover, the alternative is to treat them as discrete. But each has so many levels that the resulting interaction would have so many terms that it would be completely unwieldy and the results impossible to understand. So treating them as continuous is the only real option here.

        The question is whether the linearity assumptions that are implicit in doing that are valid. For that, I would explore the results graphically. Plot the estimated and observed values of populismus and see if the fit of the model looks reasonable. Look, in particular, for systematic deviations that suggest a curvilinear relationship. (Also look for points with high leverage.) If the appearance of curvilinearity is there, then you may need to transform one or more of the variables to get a more realistic model. -estat ovtest- after -regress- is also helpful in detecting model specification problems. But if the observed vs estimated plot looks like a diagonal line with a lot of noise around it, then I think you can consider this model usable.

        Code:
        // AFTER THE REGRESS COMMAND
        predict predicted, xb
        graph twoway scatter populismus predicted || line populismus populismus, sort

        Comment


        • #5
          Thank you for your answer! Very helpful! I did what you suggested and the graph looks like you discribed, diagonal line and lots of noise around it, so I think I can treat the IVs as continous variables.

          Best regards,
          Vera

          Comment

          Working...
          X