Announcement

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

  • interaction term graph

    hi
    I want to draw a graph according to the value of the moderating variable in regression analysis.

    - moderate variable is dummy, and independent also dummy
    - t1~t4 is technology level(t1=1, othrewise=0; t2=1, otherwise=1; t3=1, otherwise=0; t4=1, otherwise=0)
    - en is dummy variable and it is moderate variable


    *code is here
    reg y en t1 t2 t3 t4 c.t1#c.en c.t2#c.en c.t3#c.en c.t4#c.en if soreg_en=0
    estimates store no
    reg y en t1 t2 t3 t4 c.t1#c.en c.t2#c.en c.t3#c.en c.t4#c.en if soreg_en=1
    estimates store yes
    coefplot no yes, drop(_cons) xline(0)

    but it is not working. and i am not sure it is correct. please help me

  • #2
    Daimin, wellcome to the forum. The reason you are not getting reply is because you have not followed the forum posting rules. Have a look at the FAQ section before posting. Specially how to use -dataex- for providing data sample and how to use code delimiters to provide stata codes/results. Getting back to your question, since I have no idea of your data, I am guessing that you have single level data and by looking at your codes I don't feel you are doing it correctly. You should use the -margins- command to produce the interaction plot and your regression command should have the 'tXen' interaction term where 't' is the variable taking on values 1~4. You don't need several dummies for 't'. I provided a sample of fictitious data below to show how your data should be set up followed by codes of a regression model with interaction term and interaction plot:

    Code:
    clear
    
    //Generate some fictitous data
    
    set obs 100
    g y = rnormal(20, 5)
    g int t = (4-1+1)*runiform()+1
    g en = runiform()>.5
    
    //Data sample: Fictitous data
    
    li y t en in 1/10, noobs clean
    
               y   t   en  
        30.12794   1    1  
        25.21316   2    0  
        21.48856   2    0  
        11.38934   4    0  
          16.354   3    0  
        24.30913   1    1  
        18.80323   3    1  
        22.58274   2    0  
        10.93992   4    1  
        14.92438   3    0
    
    // Regression model:
    
     reg y i.t##i.en
    
          Source |       SS           df       MS      Number of obs   =       100
    -------------+----------------------------------   F(7, 92)        =      1.59
           Model |  247.391535         7  35.3416479   Prob > F        =    0.1496
        Residual |  2051.18155        92  22.2954516   R-squared       =    0.1076
    -------------+----------------------------------   Adj R-squared   =    0.0397
           Total |  2298.57308        99  23.2179099   Root MSE        =    4.7218
    
    ------------------------------------------------------------------------------
               y | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               t |
              2  |   2.521532   1.927669     1.31   0.194    -1.306985     6.35005
              3  |   1.727287   1.828748     0.94   0.347    -1.904764    5.359337
              4  |    .254079   1.927669     0.13   0.895    -3.574438    4.082596
                 |
            1.en |   4.146112   1.890235     2.19   0.031     .3919417    7.900282
                 |
            t#en |
            2 1  |  -5.096853   2.630077    -1.94   0.056    -10.32041    .1267076
            3 1  |  -3.585629   2.745291    -1.31   0.195    -9.038015    1.866756
            4 1  |  -5.675484   2.699796    -2.10   0.038    -11.03751    -.313456
                 |
           _cons |   17.85751   1.363068    13.10   0.000     15.15034    20.56468
    ------------------------------------------------------------------------------
    
    //Means for interaction terms;
    
     margins t#en,
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            t#en |
            1 0  |   17.85751   1.363068    13.10   0.000     15.15034    20.56468
            1 1  |   22.00362   1.309593    16.80   0.000     19.40266    24.60459
            2 0  |   20.37904   1.363068    14.95   0.000     17.67187    23.08621
            2 1  |    19.4283   1.219165    15.94   0.000     17.00693    21.84967
            3 0  |    19.5848   1.219165    16.06   0.000     17.16343    22.00616
            3 1  |   20.14528   1.573935    12.80   0.000     17.01931    23.27125
            4 0  |   18.11159   1.363068    13.29   0.000     15.40442    20.81876
            4 1  |   16.58222   1.363068    12.17   0.000     13.87505    19.28939
    ------------------------------------------------------------------------------
    
    //Generate plot:
    
    marginsplot
    Roman

    Comment


    • #3
      Thank you so much.
      A friend said that in order to draw a margin's graph of a categorical variable, you have to write a command in the same way as above.
      The analysis results are the same, but I needed confidence in the graph results.

      I want to ask one more question.
      Two lines in the graph overlap (en=0;en=1) and are not well identified. I want to separate these two lines, so I'm looking for a way. What kind of command should I write?

      Comment


      • #4
        You can look at mplotoffset from SSC or follow the following thread: https://www.statalist.org/forums/for...et-for-clarity

        Comment


        • #5
          Cool! I drew the picture I wanted. Thank you.

          Comment

          Working...
          X