Announcement

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

  • Creating Margin Plot from Moderation Model

    Dear all,

    I use Stata16 and need your kind assistance with generating marginal effect from a moderation model. Here is my model:

    reg lnnpl lnpc inf xr je cinfo jecinfo y2-y7, ro ...............................[1]

    reg lnnpl lnpc inf xr c.je##c.cinfo y2-y7, ro ...............................[2]
    //both specifications gave IDENTICAL results.

    where, lnnpl = dependent variable (continuous variable)
    je = key explanatory variable (continuous variable)
    cinfo = moderation variable (ranges from 0 to 8)
    lnpc inf xr = control variables

    OBJECTIVE: Compute and plot the marginal effect of JE on LNNPL.

    I executed Equation [1] and thereafter tried to execute this syntax:
    margins cinfo, dydx(je)

    I received the following error message:
    factor cinfo not found in list of covariates
    r(322);

    Initially, I thought this will be easy after reading the Stata help files and watching Prof. Chuck Huber's YouTube tutorials, but it has been a roller-coaster of errors. I really need your help. Here is my dataset:

    HTML Code:
    c_id    country    year    lnnpl    cinfo    je    jecinfo    lnpc    inf    xr    y1    y2    y3    y4    y5    y6    y7
    1    Israel    2013    1.051114    7    41    287    10.49983    1.5713922    3.6107583    1    0    0    0    0    0    0
    1    Israel    2014    .7659684    7    43.3    303.1    10.53686    .48503094    3.577925    0    1    0    0    0    0    0
    1    Israel    2015    .6123633    7    43.3    303.1    10.48505    -.63249001    3.8868333    0    0    1    0    0    0    0
    1    Israel    2016    .4731912    7    43.3    303.1    10.52733    -.54438861    3.8405667    0    0    0    1    0    0    0
    1    Israel    2017    .2551538    7    43.3    303.1    10.61009    .24421053    3.5995555    0    0    0    0    1    0    0
    1    Israel    2018    .2047327    7    43.3    303.1    10.63873    .81485215    3.5905581    0    0    0    0    0    1    0
    1    Israel    2019    .3278704    8    43.3    346.4    10.68376    .84159653    3.5645273    0    0    0    0    0    0    1
    2    Kuwait    2013    1.292079    6    25    150    10.80747    2.6822968    .28358944    1    0    0    0    0    0    0
    2    Kuwait    2014    1.061399    6    25    150    10.69336    2.9089267    .28456714    0    1    0    0    0    0    0
    2    Kuwait    2015    .8636156    6    33.6    201.6    10.30459    3.2717017    .30085203    0    0    1    0    0    0    0
    2    Kuwait    2016    .7997411    6    33.6    201.6    10.22749    3.1983978    .30213744    0    0    0    1    0    0    0
    2    Kuwait    2017    .6675166    6    33.6    201.6    10.3009    2.171833    .30334976    0    0    0    0    1    0    0
    2    Kuwait    2018    .4845843    6    33.6    201.6    10.43395    .54313315    .30195649    0    0    0    0    0    1    0
    2    Kuwait    2019        8    33.6    268.8    10.37449    1.091848    .30361116    0    0    0    0    0    0    1
    3    Malta    2013    2.191424    0    36.5    0    10.07901    1.1802844        1    0    0    0    0    0    0
    3    Malta    2014    2.17813    0    36.5    0    10.16619    .31030647        0    1    0    0    0    0    0
    3    Malta    2015    1.959806    0    36.5    0    10.08591    1.1005483        0    0    1    0    0    0    0
    3    Malta    2016    1.666705    4    36.5    146    10.13194    .64270277        0    0    0    1    0    0    0
    3    Malta    2017    1.403631    4    36.5    146    10.21241    1.3643545        0    0    0    0    1    0    0
    3    Malta    2018    1.210538    5    36.5    182.5    10.31339    1.1578236        0    0    0    0    0    1    0
    3    Malta    2019    1.165716    5    36.5    182.5    10.2893    1.64206        0    0    0    0    0    0    1
    4    Saudi Arabia    2013    .2676111    8    47.5    380    10.1204    3.5325247    3.75    1    0    0    0    0    0    0
    4    Saudi Arabia    2014    .077274    8    47.5    380    10.10495    2.2362903    3.75    0    1    0    0    0    0    0
    4    Saudi Arabia    2015    .2126785    8    47.5    380    9.934402    1.2060732    3.75    0    0    1    0    0    0    0
    4    Saudi Arabia    2016    .3245146    8    47.5    380    9.897434    2.0688404    3.75    0    0    0    1    0    0    0
    4    Saudi Arabia    2017    .4784981    8    47.5    380    9.942888    -.83819458    3.75    0    0    0    0    1    0    0
    4    Saudi Arabia    2018    .6690173    8    47.5    380    10.05788    2.4581416    3.75    0    0    0    0    0    1    0
    4    Saudi Arabia    2019    .6197107    8    47.5    380    10.04931    -2.0933333    3.75    0    0    0    0    0    0    1
    5    United Arab Emirates    2013    1.895465    6    30.4    182.4    10.6552    1.1011184    3.6725    1    0    0    0    0    0    0
    5    United Arab Emirates    2014    1.729302    7    30.4    212.8    10.68629    2.3462687    3.6725    0    1    0    0    0    0    0
    5    United Arab Emirates    2015    1.61484    7    30.4    212.8    10.56265    4.0699661    3.6725    0    0    1    0    0    0    0
    5    United Arab Emirates    2016    1.623702    7    30.4    212.8    10.54907    1.6174881    3.6725    0    0    0    1    0    0    0
    5    United Arab Emirates    2017    1.666817    8    31    248    10.61263    1.9668256    3.6725    0    0    0    0    1    0    0
    5    United Arab Emirates    2018    1.724629    8    31    248    10.68829    3.0686338    3.6725    0    0    0    0    0    1    0
    5    United Arab Emirates    2019    1.86524    8    31    248    10.67136    -1.9310811    3.6725    0    0    0    0    0    0    1
    Please help me, thank you.
    Ngozi

  • #2
    The variable "cinfo" is categorical and you are declaring it as continuous. You need:

    Code:
    reg lnnpl lnpc inf xr c.je##i.cinfo y2-y7, ro

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      The variable "cinfo" is categorical and you are declaring it as continuous. You need:

      Code:
      reg lnnpl lnpc inf xr c.je##i.cinfo y2-y7, ro
      Thanks so much, Prof. Musau...it worked. Here are my results and the plot:
      HTML Code:
       margins cinfo, dydx(je)
      
      Average marginal effects                        Number of obs     =         27
      Model VCE    : Robust
      
      Expression   : Linear prediction, predict()
      dy/dx w.r.t. : je
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      je           |
             cinfo |
                6  |  -.1082685   .0349742    -3.10   0.009    -.1844707   -.0320663
                7  |  -.0959284   .0119826    -8.01   0.000    -.1220364   -.0698205
                8  |  -.1382433   .0130702   -10.58   0.000    -.1667209   -.1097657
      ------------------------------------------------------------------------------
      Interpretation: Will I be correct to say that:
      The marginal effect of JE on lnNPL is negative at 6 to 8 values of CINFO?

      Kindly guide, Sir
      Ngozi
      Attached Files

      Comment


      • #4
        [QUOTE=Ngozi ADELEYE;n1654145]


        Hi Dr. Musau,
        I tried replicating the syntax using 2 continuous variables, as in:

        reg lnnpl lnpc inf xr c.je##c.lnpc y2-y7, ro
        margins lnpc, dydx(je)
        marginsplot

        I got this error:
        margins lnpc, dydx(je)
        lnpc: factor variables may not contain noninteger values
        r(452);

        Please any ideas of the correct way to specify when interacting 2 continuous variables?
        Thanks for the help, Sir
        Ngozi

        Comment


        • #5
          Originally posted by Ngozi ADELEYE View Post


          Interpretation: Will I be correct to say that:
          The marginal effect of JE on lnNPL is negative at 6 to 8 values of CINFO?
          Yes, the average marginal effects of je on lnnpl are negative for the specified values of cinfo. An equivalent syntax would be:

          Code:
          margins, dydx(je) at(cinfo=(6/8))

          reg lnnpl lnpc inf xr c.je##c.lnpc y2-y7, ro
          margins lnpc, dydx(je)
          marginsplot

          I got this error:
          margins lnpc, dydx(je)
          lnpc: factor variables may not contain noninteger values
          r(452);

          Please any ideas of the correct way to specify when interacting 2 continuous variables?

          You need to provide a range of values for "lnpc". Assuming these are 1 to 9 if the variable is in logs, something like:

          Code:
          reg lnnpl inf xr c.je##c.lnpc y2-y7, ro
          margins, dydx(je) at(lnpc=(1/9))

          Comment


          • #6

            You need to provide a range of values for "lnpc". Assuming these are 1 to 9 if the variable is in logs, something like:

            Code:
            reg lnnpl inf xr c.je##c.lnpc y2-y7, ro
            margins, dydx(je) at(lnpc=(1/9))
            [/QUOTE]

            You are just amazing, Dr. Musau...it worked!!!

            This is what I did:

            Code:
            reg lnnpl inf xr c.je##c.lnpc y2-y7, ro
            margins, dydx(je) at(lnpc=(1/11))
            marginsplot
            Here are the outputs:
            HTML Code:
             margins, dydx(je) at(lnpc=(1/11))
            
            Average marginal effects                        Number of obs     =         27
            Model VCE    : Robust
            
            Expression   : Linear prediction, predict()
            dy/dx w.r.t. : je
            
            1._at        : lnpc            =           1
            
            2._at        : lnpc            =           2
            
            3._at        : lnpc            =           3
            
            4._at        : lnpc            =           4
            
            5._at        : lnpc            =           5
            
            6._at        : lnpc            =           6
            
            7._at        : lnpc            =           7
            
            8._at        : lnpc            =           8
            
            9._at        : lnpc            =           9
            
            10._at       : lnpc            =          10
            
            11._at       : lnpc            =          11
            
            ------------------------------------------------------------------------------
                         |            Delta-method
                         |      dy/dx   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
            je           |
                     _at |
                      1  |  -.5420269   .2310468    -2.35   0.033    -1.034491   -.0495624
                      2  |  -.4970822    .206968    -2.40   0.030    -.9382241   -.0559403
                      3  |  -.4521375   .1828924    -2.47   0.026    -.8419634   -.0623116
                      4  |  -.4071928   .1588212    -2.56   0.022    -.7457122   -.0686734
                      5  |  -.3622481   .1347569    -2.69   0.017    -.6494757   -.0750205
                      6  |  -.3173034    .110704    -2.87   0.012    -.5532634   -.0813434
                      7  |  -.2723587   .0866719    -3.14   0.007    -.4570955   -.0876219
                      8  |   -.227414   .0626846    -3.63   0.002     -.361023    -.093805
                      9  |  -.1824693   .0388252    -4.70   0.000    -.2652232   -.0997155
                     10  |  -.1375246   .0156884    -8.77   0.000    -.1709636   -.1040857
                     11  |  -.0925799   .0120645    -7.67   0.000    -.1182949    -.066865
            ------------------------------------------------------------------------------

            Comment

            Working...
            X