Announcement

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

  • Help with Simple slopes

    Hi !
    I’m hoping someone can help me! I’m running a regression with an interaction with 2 continuous predictor variables Ps and pc one continuous dv, flow and one covariant level of exp with 3 cats. I want to compare 4 subtypes made up of high/low Ps and high/low pc and there effect on flow. High would be +1sd and low would be -1 Sd. I think I need to create simple slopes for each subtype and then run contrasts between them! Does anyone know how to do this in stata! Any help is much appreciated!
    Last edited by Gee Gii; 03 Sep 2023, 05:29.

  • #2
    Can you show us the regression model in Stata? Please be sure to include the i. prefix in front of categorical and c. prefix in front of continuous variables?

    In general, Stata's margins command is great for this. I'd suggest that you read the margins PDF documentation for more examples than you can possibly imagine.

    Comment


    • #3
      As Erik Ruzek notes, -margins- (with dydx) and -marginsplot- will be helpful. You can relevant examples here: Cheers,
      Bruce
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        Thanks so much for the reply! I ran this margins command and basically, I want to know if it is possible to compare these 4 groups, specifically compare 3 v 1, 3 v 2, 3 v 4.
        ​​​​​​​
        . margins, at(ecp=(33.53841 52.40084) psp=(20.555251 29.847189)) vsquish
        Predictive margins Number of obs = 164
        Model VCE: OLS
        Expression: Linear prediction, predict()
        1._at: psp = 20.55525
        ecp = 33.53841
        2._at: psp = 20.55525
        ecp = 52.40084
        3._at: psp = 29.84719
        ecp = 33.53841
        4._at: psp = 29.84719
        ecp = 52.40084
        ------------------------------------------------------------------------------
        | Delta-method
        | Margin std. err. t P>|t| [95% conf. interval]
        -------------+----------------------------------------------------------------
        _at |
        1 | 123.1813 1.838294 67.01 0.000 119.5505 126.8121
        2 | 105.2 4.06512 25.88 0.000 97.17097 113.2289
        3 | 131.3891 3.363699 39.06 0.000 124.7455 138.0328
        4 | 130.2848 1.853819 70.28 0.000 126.6234 133.9463

        Comment


        • #5
          and this is the regression output.
          regress flowtotal i.levelofexp c.pspcen##c.ecpcen, baselevels
          Source | SS df MS Number of obs = 164
          Model | 17121.4756 5 3424.29511 Prob > F = 0.0000
          Residual | 37511.2744 158 237.413129 R-squared = 0.3134
          -------------+---------------------------------- Adj R-squared = 0.2917
          Total | 54632.75 163 335.170245 Root MSE = 15.408
          ---------------------------------------------------------------------------------------------
          flowtotal | Coefficient Std. err. t P>|t| [95% conf. interval]
          ----------------------------+----------------------------------------------------------------
          levelofexp |
          0 | 0 (base)
          1 | 11.28272 2.902751 3.89 0.000 5.54952 17.01592
          2 | 16.1383 3.006963 5.37 0.000 10.19927 22.07732
          |
          pspcen | 1.791473 .3564857 5.03 0.000 1.08738 2.495565
          ecpcen | -.5059386 .1745452 -2.90 0.004 -.8506814 -.1611958
          |
          c.pspcen#c.ecpce | .0962927 .0254272 3.79 0.000 .0460717 .1465137
          |
          _cons | 114.075 2.118144 53.86 0.000 109.8915 118.2586
          ---------------------------------------------------------------------------------------------

          Comment


          • #6
            Hello Gee Gii. Please post your output again, but this time, highlight it and then click on the # key in the menu bar. This will enclose it in code (i.e., text) delimiters making if much easier to read. Thanks.
            --
            Bruce Weaver
            Email: [email protected]
            Version: Stata/MP 18.5 (Windows)

            Comment


            • #7
              Here is an example. The key is that you want to use the contrast option in margins. I suggest reading the PDF documentation on margins, contrast.

              Code:
              use https://www.stata-press.com/data/r16/nlsw88
              
              
              poisson wage i.union c.hours##c.ttl_exp, vce(robust)
              
              note: you are responsible for interpretation of noncount dep. variable
              
              Iteration 0:   log pseudolikelihood = -5086.0385  
              Iteration 1:   log pseudolikelihood = -5086.0382  
              
              Poisson regression                              Number of obs     =      1,877
                                                              Wald chi2(4)      =     456.39
                                                              Prob > chi2       =     0.0000
              Log pseudolikelihood = -5086.0382               Pseudo R2         =     0.0617
              
              -----------------------------------------------------------------------------------
                                |               Robust
                           wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              ------------------+----------------------------------------------------------------
                          union |
                         union  |   .1574339   .0262123     6.01   0.000     .1060587    .2088091
                          hours |   .0045291   .0033695     1.34   0.179     -.002075    .0111331
                        ttl_exp |   .0477448   .0110073     4.34   0.000      .026171    .0693187
                                |
              c.hours#c.ttl_exp |  -.0001319   .0002807    -0.47   0.638    -.0006821    .0004183
                                |
                          _cons |   1.243886   .1257394     9.89   0.000     .9974411    1.490331
              -----------------------------------------------------------------------------------
              Now the margins call, after first getting the mean and standard deviation of the variables of interest.

              Code:
              tabstat hours ttl_exp, s(mean sd) c(s)
              
                  variable |      mean        sd
              -------------+--------------------
                     hours |  37.21811  10.50914
                   ttl_exp |  12.53498  4.610208
              ----------------------------------
              
              margins, at(hours = (26.71 47.73) ttl_exp = (7.93 17.13)) contrast(atcontrast(ib3.r._at)) 
              Contrasts of predictive margins                 Number of obs     =      1,877
              Model VCE    : Robust
              
              Expression   : Predicted number of events, predict()
              
              1._at        : hours           =       26.71
                             ttl_exp         =        7.93
              
              2._at        : hours           =       26.71
                             ttl_exp         =       17.13
              
              3._at        : hours           =       47.73
                             ttl_exp         =        7.93
              
              4._at        : hours           =       47.73
                             ttl_exp         =       17.13
              
              ------------------------------------------------
                           |         df        chi2     P>chi2
              -------------+----------------------------------
                       _at |
                 (1 vs 3)  |          1        3.98     0.0460
                 (2 vs 3)  |          1       45.47     0.0000
                 (4 vs 3)  |          1      129.34     0.0000
                    Joint  |          3      350.48     0.0000
              ------------------------------------------------
              
              --------------------------------------------------------------
                           |            Delta-method
                           |   Contrast   Std. Err.     [95% Conf. Interval]
              -------------+------------------------------------------------
                       _at |
                 (1 vs 3)  |  -.4400131   .2205108     -.8722064   -.0078198
                 (2 vs 3)  |     2.4682   .3660223       1.75081    3.185591
                 (4 vs 3)  |    2.89337   .2544092      2.394737    3.392003
              --------------------------------------------------------------

              Comment


              • #8
                Ahhh amazing! Legends! this is perfect! I cannot thank you two enough. Erik Ruzek Bruce Weaver

                Comment

                Working...
                X