Announcement

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

  • Help with margins command

    Hello everyone. I would appreciate some help with the margins command. I am running a model like this
    Code:
    xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP i.months, fe robust
    and it later becomes like this
    Code:
    xtreg Loan_ratio Loan_ratio_lagged c.EL_ratio_lagged##NIRP##c.RD_ratio_lagged##high_E L_ratio i.months, fe robust
    . The aim is to examine how retail deposits and excess liquidity affect loan ratio after the implementation of negative interest rates.

    where Loan_ratio is the dependent continuous variable
    RD_ratio_lagged and EL_ratio_lagged are both continuous variable
    NIRP is a dummy that is 0 before 02/2015 and afterwards becomes 1 that indicates the periods of positive and negative interest rates
    high_EL_ratio is a dummy for categorizing banks into two groups

    I know that if i want to measure the effect of my independent variables i have to use margins since they are part of the interaction terms.

    Firstly, i am not sure if there is a correct margins command, because i know there are various ways to use it. What i come across the most is
    margins var, dydx(var)
    . However i get some problems when i use this setup.

    Code:
    . xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP i.months, fe robust
    note: 239.months omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =      1,120
    Group variable: bankid                          Number of groups  =         34
    
    R-squared:                                      Obs per group:
    Within  = 0.7712                                         min =         12
    Between = 0.9923                                         avg =       32.9
    Overall = 0.9765                                         max =         35
    
    F(33,33)          =          .
    corr(u_i, Xb) = 0.8156                          Prob > F          =          .
    
    (Std. err. adjusted for 34 clusters in bankid)
    
    Robust
    Loan_ratio  Coefficient  std. err.      t    P>t     [95% conf. interval]
    
    Loan_ratio_lagged    .8627486   .0334491    25.79   0.000     .7946958    .9308014
    RD_ratio_lagged   -.0560122   .0219111    -2.56   0.015    -.1005907   -.0114337
    1.NIRP    .0103484    .006633     1.56   0.128    -.0031466    .0238434
    
    NIRP#c.RD_ratio_lagged
    1     -.003761   .0054517    -0.69   0.495    -.0148525    .0073306
    Code:
     margins NIRP, dydx(RD_ratio_lagged)
    
    Average marginal effects Number of obs = 1,120
    Model VCE: Robust
    
    Expression: Linear prediction, predict()
    dy/dx wrt: RD_ratio_lagged
    
    ---------------------------------------------------------------------------------
    | Delta-method
    | dy/dx std. err. z P>|z| [95% conf. interval]
    ----------------+----------------------------------------------------------------
    RD_ratio_lagged |
    NIRP |
    0 | . (not estimable)
    1 | . (not estimable)
    ---------------------------------------------------------------------------------

    and if i switch the variables i get

    Code:
     margins RD_ratio_lagged, dydx(NIRP)
    RD_ratio_lagged: factor variables may not contain noninteger values
    r(452);
    
    end of do-file
    
    r(452);

    However, when i ran
    margins, dydx(*)
    i got these results:
    Code:
    . margins, dydx(*)
    
    Average marginal effects Number of obs = 1,120
    Model VCE: Robust
    
    Expression: Linear prediction, predict()
    dy/dx wrt: Loan_ratio_lagged RD_ratio_lagged 1.NIRP 206.months 207.months 208.months 209.months 210.months
    211.months 212.months 213.months 214.months 215.months 216.months 217.months 218.months 219.months
    220.months 221.months 222.months 223.months 224.months 225.months 226.months 227.months 228.months
    229.months 230.months 231.months 232.months 233.months 234.months 235.months 236.months 237.months
    238.months 239.months
    
    -----------------------------------------------------------------------------------
    | Delta-method
    | dy/dx std. err. z P>|z| [95% conf. interval]
    ------------------+----------------------------------------------------------------
    Loan_ratio_lagged | .8627486 .0334491 25.79 0.000 .7971895 .9283077
    RD_ratio_lagged | -.058111 .0225589 -2.58 0.010 -.1023257 -.0138963
    1.NIRP | . (not estimable)


    Any insights about how i should go on would be really helpful
    Last edited by Vasilis Papas; 01 Dec 2023, 10:15.

  • #2
    Stata has already forewarned you of a problem with your model early in the output from your regression:
    Code:
    note: 239.months omitted because of collinearity.
    What is the 239.months variable colinear with? My best guess is that it is colinear with NIRP, or, more precisely, NIRP and the suite of month indicators (dummy variables) are colinear. In fact, you have yourself stipulated that colinearity with
    NIRP is a dummy that is 0 before 02/2015 and afterwards becomes 1 that indicates the periods of positive and negative interest rates
    In other words, you have set up NIRP to be an indicator for a subset of the months. So it is necessarily colinear with the suite of month variables. Consequently, the model leaves the NIRP and month effects all unidentifiable. Now, to produce some kind of result, Stata drops one of the month variables (it chose 239.months). But, because this is just an arbitrary way to break the colinearity, this means that the coefficients produced for NIRP and the month indicators are all garbage. Well, they're not entirely garbage. You can, for example, use -predict- after this regression and get valid results. That's because any way of breaking the colinearity (choosing a different month to omit, or omitting NIRP) will produce the same predicted values--they're just different ways to parameterize the same model. But the coefficients of NIRP and the month variables cannot be interpreted as effects of anything, because if Stata had chosen to break the colinearity in some other way, you would get different coefficients for all of these variables. So anything that has to rely on the value of any, but not all, of these coefficients is necessarily still unidentified. Bottom line: you cannot estimate a marginal effect of NIRP from this model. To do so, you will have to eliminate the i.month terms from the model. This is linear algebra and there is no way around it.

    I will leave it to others who are more experienced with this kind of data to comment on the suitability of including the lagged dependent variable as an independent variable in the model and what the alternatives might be better for dealing with autocorrelation.

    Comment


    • #3
      Thank you mr. Clyde for your reply. I think i understand your points but i will go through your answer just to be sure i understand it well.

      I use i.months for time fixed effects in my model. I thought that Stata omitting one of the months (or dummies in general) is the standard process in fixed effects in order to avoid collinearity so that there is always -1 dummy, even if i didnt use NIRP. But if i understood right NIRP and the months variable catch the same effects so they are bound to suffer from collinearity. So i have a few questions.

      Are time fixed effects important or can i remover them completely if i want to use margins in order to capture the effect of NIRP and RD_ratio_lagged since i use NIRP dummy? And what if i keep the variable as months instead of i.months?

      Also, if i want to stick with the regression i have used, would it be possible to provide me with a quick example of -predict- for this case?

      Comment


      • #4
        I use i.months for time fixed effects in my model. I thought that Stata omitting one of the months (or dummies in general) is the standard process in fixed effects in order to avoid collinearity so that there is always -1 dummy, even if i didnt use NIRP. But if i understood right NIRP and the months variable catch the same effects so they are bound to suffer from collinearity.
        Yes, omitting one of the months, or of indicators in general, is standard. But here Stata omitted 239.months in addition to omitting the base category. You didn't show the output for the months variables in your post. But if you go back and look at your output and count up the months, you will see that two are missing. And that is where things go awry. In a situation with no additional colinearity, Stata will omit the base category from a categorical variable, but it does not give you any message--basically it assumes you know that you will have a base category omitted. The fact that Stata chose to give you this warning message tells you that it is doing something more than just omitting the base category.

        Are time fixed effects important or can i remover them completely if i want to use margins in order to capture the effect of NIRP and RD_ratio_lagged since i use NIRP dummy?
        That's actually a substantive question, not a statistical one; in some contexts they are important, and in others not so much. I gather you are working in finance or economics--I'm an epidemiologist, so I can't answer this question.

        And what if i keep the variable as months instead of i.months?

        That would avoid the colinearity, but it would be constraining the model so that instead of monthly shocks, you have a constant month-on-month increase (or maybe it's a decrease) in Loan_ratio. Even though I'm an epidemiologist, I feel comfortable at least strongly doubting that that's realistic for economic/financial data.

        Also, if i want to stick with the regression i have used, would it be possible to provide me with a quick example of -predict- for this case?
        The -predict- command will give you the model-predicted outcome (or some component thereof) for each observation in your data set. Depending on exactly what you want to predict you have to specify an option. Rather than me outlining it here, I think it's better for me to just refer you to the on-line documentation that is part of your Stata installation. Run -help xtreg postestimation-. A short way down the page that opens up in the Viewer you will find link (in blue) for predict. Click on that, and then you read about it in the page that opens up.

        Comment


        • #5
          Thank you very much for the comments! You have been of great help once more!

          Comment


          • #6
            Actually Clyde Schechter i just came up with another question as i was trying to figure out how to use margins. After the regression
            Code:
            xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP i.months, fe robust
            , if i use
            Code:
            margins, dydx(RD_ratio_lagged)
            i get this result:

            Code:
            . margins, dydx(RD_ratio_lagged)
            
            Average marginal effects                                 Number of obs = 1,120
            Model VCE: Robust
            
            Expression: Linear prediction, predict()
            dy/dx wrt:  RD_ratio_lagged
            
            ---------------------------------------------------------------------------------
                            |            Delta-method
                            |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
            ----------------+----------------------------------------------------------------
            RD_ratio_lagged |   -.058111   .0225589    -2.58   0.010    -.1023257   -.0138963
            ---------------------------------------------------------------------------------
            Is this still usable or because of all the aforementioned problems this is not possible to interpret correctly too?

            Comment


            • #7
              Yes, this is usable because none of the variables mentioned in the -margins- command are part of the colinearity. If Stata chose to break the colinearity in some other way, other than perhaps minor rounding errors, it would get the same result for this.

              Comment


              • #8
                I see. Thank you for this clarification. Thank you again for all your help!

                Comment


                • #9
                  Dear Clyde Schechter sorry to bother you again about this. I read in another post this reply:

                  Originally posted by Carlo Lazzaro View Post
                  Rick:
                  I would not be concerned that much about loosing one year more than the one ruled out by Stata to avoid the dummy trap.
                  The main issue is methodological: is -i.year- expected to play a relevant role in your regression model in the light of the "dominant" theory in your research field?
                  In any case, I would test if -i.year- makes sense in your model via -testparm-.
                  and the test game me these results:

                  Code:
                  . testparm i.months
                  
                   ( 1)  206.months = 0
                   ( 2)  207.months = 0
                   ( 3)  208.months = 0
                   ( 4)  209.months = 0
                   ( 5)  210.months = 0
                   ( 6)  211.months = 0
                   ( 7)  212.months = 0
                   ( 8)  213.months = 0
                   ( 9)  214.months = 0
                   (10)  215.months = 0
                   (11)  216.months = 0
                   (12)  217.months = 0
                   (13)  218.months = 0
                   (14)  219.months = 0
                   (15)  220.months = 0
                   (16)  221.months = 0
                   (17)  222.months = 0
                   (18)  223.months = 0
                   (19)  224.months = 0
                   (20)  225.months = 0
                   (21)  226.months = 0
                   (22)  227.months = 0
                   (23)  228.months = 0
                   (24)  229.months = 0
                   (25)  230.months = 0
                   (26)  231.months = 0
                   (27)  232.months = 0
                   (28)  233.months = 0
                   (29)  234.months = 0
                   (30)  235.months = 0
                   (31)  236.months = 0
                   (32)  237.months = 0
                   (33)  238.months = 0
                  
                         F( 33,    33) =  556.37
                              Prob > F =    0.0000
                  But what i would like to know is whether the coefficient of the interaction term
                  Code:
                  NIRP#c.RD_ratio_lagged
                  in my model
                  Code:
                   xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP i.months, fe robust
                  will also be problematic due to the collinearity. And i suppose if this coefficient is problematic then calculating the marginal effect for RD_ratio_lagged will also be incorrect.

                  Comment


                  • #10
                    Vasilis:
                    that test you ran tells you that you should keep -i.time- as a predictor in your regerssion equation (as it is always recommended for -xtreg,fe-).
                    Unfortunately, your main issue seems to be different.
                    Last edited by Carlo Lazzaro; 02 Dec 2023, 02:53.
                    Kind regards,
                    Carlo
                    (Stata 19.0)

                    Comment


                    • #11
                      The i.NIRP#c.RD_ratio_lagged term will, in this setting, usually not be affected by the colinearity and it should be OK to use for the purposes of understanding RD_ratio_lagged effects. There could be unusual conditions in your data which cause it to be colinear, but in that case -margins, dydx(RD_ratio_lagged)- would tell you that it is not estimable. You have already indicated that -margins, dydx(RD_ratio_lagged)- gave you an estimate, so it follows that the i.NIRP#c.RD_ratio_lagged term is not affected by the colinearity problem.

                      Concerning what to do about the i.month terms, I do not subscribe to the practice of selecting models based on significance tests. I prefer to look at how the models' predictions fit the data. Also, if your research goals require estimating effects of NIRP, then regardless of what any test says, it cannot be accomplished in a fixed-effects model that includes i.months. So if you do need to estimate effects of NIRP, then it simply cannot be done in a model that also includes i.months. It follows that i.months has to go, or you have to change your research goals so that you no longer try to estimate effects of NIRP.

                      Comment


                      • #12
                        I have decided to remove the time-fixed effects in order to be able to estimate the effect of NIRP, since it is an important variable for my model. However i have some difficulties with estimating the average marginal effects of my variables. I know that since i make use of interaction terms i should use the margins command. For my base model i have
                        Code:
                        xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP , fe robust
                        and in order to get the total effect of my variables i use
                        Code:
                        margins, dydx(*)
                        .

                        Code:
                         xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP , fe robust
                        
                        Fixed-effects (within) regression               Number of obs     =      1,120
                        Group variable: bankid                          Number of groups  =         34
                        
                        R-squared:                                      Obs per group:
                             Within  = 0.7645                                         min =         12
                             Between = 0.9919                                         avg =       32.9
                             Overall = 0.9756                                         max =         35
                        
                                                                        F(4,33)           =    1235.96
                        corr(u_i, Xb) = 0.8070                          Prob > F          =     0.0000
                        
                                                                  (Std. err. adjusted for 34 clusters in bankid)
                        ----------------------------------------------------------------------------------------
                                               |               Robust
                                    Loan_ratio | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                        -----------------------+----------------------------------------------------------------
                             Loan_ratio_lagged |   .8635968   .0338643    25.50   0.000     .7946994    .9324942
                               RD_ratio_lagged |  -.0573802   .0223754    -2.56   0.015    -.1029034    -.011857
                                        1.NIRP |   .0049616    .002544     1.95   0.060    -.0002142    .0101375
                                               |
                        NIRP#c.RD_ratio_lagged |
                                            1  |  -.0044585   .0053319    -0.84   0.409    -.0153063    .0063894
                                               |
                                         _cons |   .1120077   .0313028     3.58   0.001     .0483218    .1756937
                        -----------------------+----------------------------------------------------------------
                                       sigma_u |  .03600765
                                       sigma_e |  .02803765
                                           rho |  .62254544   (fraction of variance due to u_i)
                        ----------------------------------------------------------------------------------------
                        
                        
                        . do "C:\Users\GAREN~1\AppData\Local\Temp\STD4930_000000.tmp"
                        
                        . margins, dydx(*)
                        
                        Average marginal effects                                 Number of obs = 1,120
                        Model VCE: Robust
                        
                        Expression: Linear prediction, predict()
                        dy/dx wrt:  Loan_ratio_lagged RD_ratio_lagged 1.NIRP
                        
                        -----------------------------------------------------------------------------------
                                          |            Delta-method
                                          |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
                        ------------------+----------------------------------------------------------------
                        Loan_ratio_lagged |   .8635968   .0338643    25.50   0.000      .797224    .9299695
                          RD_ratio_lagged |  -.0598682   .0229302    -2.61   0.009    -.1048105   -.0149259
                                   1.NIRP |   .0026764   .0017904     1.49   0.135    -.0008327    .0061855
                        -----------------------------------------------------------------------------------
                        Note: dy/dx for factor levels is the discrete change from the base level.
                        If i interpret the margins results correctly, then RD_ratio_lagged leads to a -.0598682 decrease in Loan ratio when NIRP is 1. And NIRP leads to a .0026764 increase in Loan ratio conditional on Loan_ratio_lagged. Is that correct?

                        Also for the full model
                        Code:
                        xtreg Loan_ratio Loan_ratio_lagged c.EL_ratio_lagged##NIRP##c.RD_ratio_lagged##high_RD_ratio , fe robust
                        should i use
                        Code:
                        margins, dydx(RD_ratio_lagged EL_ratio_lagged high_RD_ratio NIRP)
                        in order to calculate the total effect of each variable? And if yes what would be the correct interpretation of these values?
                        Code:
                        . margins, dydx(RD_ratio_lagged EL_ratio_lagged high_RD_ratio NIRP)
                        
                        Average marginal effects                                 Number of obs = 1,120
                        Model VCE: Robust
                        
                        Expression: Linear prediction, predict()
                        dy/dx wrt:  EL_ratio_lagged 1.NIRP RD_ratio_lagged 1.high_RD_ratio
                        
                        ---------------------------------------------------------------------------------
                                        |            Delta-method
                                        |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
                        ----------------+----------------------------------------------------------------
                        EL_ratio_lagged |   .0414194   .0513013     0.81   0.419    -.0591293    .1419681
                                 1.NIRP |   .0025268   .0022411     1.13   0.260    -.0018656    .0069193
                        RD_ratio_lagged |  -.0618814    .022576    -2.74   0.006    -.1061296   -.0176332
                        1.high_RD_ratio |  -.0006566   .0119242    -0.06   0.956    -.0240277    .0227145
                        ---------------------------------------------------------------------------------
                        Note: dy/dx for factor levels is the discrete change from the base level.

                        Comment


                        • #13
                          If i interpret the margins results correctly, then RD_ratio_lagged leads to a -.0598682 decrease in Loan ratio when NIRP is 1. And NIRP leads to a .0026764 increase in Loan ratio conditional on Loan_ratio_lagged. Is that correct?
                          Not quite. RD_ratio_lagged is associated with a -.0598682 change in Loan ratio when NIRP is 0, not 1. And the marginal effect of NIRP is indeed conditional on Loan_ratio_lagged: its .0049616 - .0044585*RD_ratio_lagged.

                          Also for the full model Code:

                          xtreg Loan_ratio Loan_ratio_lagged c.EL_ratio_lagged##NIRP##c.RD_ratio_lagged##high_R D_ratio , fe robust
                          should i use Code:

                          margins, dydx(RD_ratio_lagged EL_ratio_lagged high_RD_ratio NIRP)
                          in order to calculate the total effect of each variable?
                          The term "total effect" is unclear. There are effects conditional on particular values of the variables with which these variables interact, and there are average marginal effects. There is nothing in statistics called "total effect" in this context. I'm going to assume you mean average marginal effect, and, yes, that -margins- command is what you would use to get that.

                          The interpretation is like this. Consider the result you got for EL_ratio_lagged. It means that the rate of change in Loan_ratio per unit change in EL_ratio_lagged, calculated separately for each observation in the data set (since it will differ from one observation to the next according to the values of RD_ratio lagged and NIRP) and high_RD_ratio) and then averaged over the entire data set is .0414194. From that, you could infer, for example, that if you picked an observation at random from your data set and calculated the marginal effect of EL_ratio conditional on the value of RD_ratio_lagged, NIRP, and high_RD_ratio in that observation, then on average that marginal effect would be .0414194.

                          Comment


                          • #14
                            I am sorry for bothering you again with my silly questions, i hope this will be the last one. One thing i dont get about
                            RD_ratio_lagged is associated with a -.0598682 change in Loan ratio when NIRP is 0, not 1
                            . If i understand correctly
                            Code:
                            margins, dydx(RD_ratio_lagged
                            is the first derivative with respect to RD_ratio_lagged so it would be: -.0573802 -.0044585*NIRP and if NIRP is 0 then the AME should be equal to -.0573802 but it is -.0598682. Am i missing something?

                            Also, i might repeat my self with this one, but is the way i use margins the best one in order to calculate the effects of my variables?

                            And two last questions. I was told by one of my professors that i should focus on the effect of NIRP. Is my current usage of -margins- enough to calculate the effect of NIRP? And in the last model, high_R D_ratio is dummy to separate my banks into two groups. If i want the average marginal effect for each group should i go with
                            Code:
                            margins, over(high_RD_ratio) dydx(RD_ratio_lagged EL_ratio_lagged NIRP)

                            Comment


                            • #15
                              If i understand correctly Code:

                              margins, dydx(RD_ratio_lagged
                              is the first derivative with respect to RD_ratio_lagged so it would be: -.0573802 -.0044585*NIRP and if NIRP is 0 then the AME should be equal to -.0573802...
                              This is correct.
                              ...but it is -.0598682.
                              No, it is not that. And I read from the wrong table in implying it was. This number, -.0598682 comes from the -margins- table, so, in light of your specific -margins- command, it is an average marginal effect, not a conditional one. I'm sorry for the confusion.

                              Also, i might repeat my self with this one, but is the way i use margins the best one in order to calculate the effects of my variables?
                              What do you mean by "best?" Certainly it is faster and less error-prone than calculating the effects by hand. But I think what you are getting at is a different matter: given that one can calculate conditional marginal effects at any combination of other variables, or average marginal effects (or marginal effects that are average with respect to some variables and conditional on others, for that matter) you may be asking which kind of marginal effects you should be calculating. That depends specifically on your research goals. What type of conclusion are you trying to draw from the values of your marginal effects?

                              I was told by one of my professors that i should focus on the effect of NIRP. Is my current usage of -margins- enough to calculate the effect of NIRP?
                              There is no such thing as "the" effect of NIRP in an interaction model. There are infinitely many effects of NIRP, a different one for each value of RD_ratio_lagged, and there is also an average marginal effect of NIRP. (And in the final model there are even more different marginal effects conditional on yet other variables.) The command you have used, -margins, dydx(NIRP)- gives you the average marginal effect.

                              And in the last model, high_R D_ratio is dummy to separate my banks into two groups. If i want the average marginal effect for each group should i go with Code:

                              margins, over(high_RD_ratio) dydx(RD_ratio_lagged EL_ratio_lagged NIRP)
                              Maybe, it depends. Here's another way in which there is a multiplicity of marginal effects. There are two different ways to do this split into high_RD_ratio and low_RD_ratio. One is the way you did it. The other is -margins high_RD_ratio, dydx(RD_ratio_lagged EL_ratio_lagged NIRP)-. These are two different things. When you use the -over()- option, Stata calculates one marginal effect (for each of RD_ratio_lagged, EL_ratio_lagged, NIRP) using only the data with high_RD_ratio = 0 and another using only the data with high_RD_ratio = 1. If you use the -margins high_RD_ratio, dydx(...- approach, Stata uses the entire data set for both of those marginal effects--distinguishing them by doing the calculation with high_RD_ratio set to 0 (resp. 1) in every observation of the entire data set. The essence of the difference between them is that with -over()- you do not take into account any difference in the distributions of other variables between the high_RD_ratio = 0 subset and the high_RD_ratio = 1 subset, whereas with -margins high_RD_ratio, dydx(...- you do. So the results obtained using -over()- are incompletely adjusted for the distributions of other variables, whereas the -margins high_RD_ratio, dydx(...- results are fully adjusted for the distributions of other variables. In most situations, the -margins high_RD_ratio, dydx(...- is what is wanted, but for some specific purposes, the -over()- approach is the right answer. It all depends on what the question is.

                              Added: Interaction models are complicated, and if you are relatively new to them, all of this can be very confusing. I think it helps to do some graphs to get a better feel for how it all works. Forget about the last model that has a four-way interaction. Just look at the simple model that has the c.RD_ratio_lagged##i.NIRP interaction term. Pick out some representative values of RD_ratio_lagged (they don't have to actually occur exactly in the data set, but they should be realistic). I have no idea what an RD_ratio is, hence no idea what those values might be. For the purposes of illustration, I'll assume that the interesting values are 0.1 0.5 1.0 2.0 and 5.0--but you should choose ones that are realistic. Run the following commands:
                              [code]
                              xtreg Loan_ratio Loan_ratio_lagged c.RD_ratio_lagged##i.NIRP , fe robust

                              margins, dydx(NIRP) at(RD_ratio_lagged = (0.1 0.5 1.0 2.0 5.0))
                              marginsplot, name(me_of_nirp_vs_rd_ratio_lagged, replace)

                              margins NIRP, at(RD_ratio_lagged = (0.1 0.5 1.0 2.0 5.0))
                              marginsplot, name(outcome_vs_rd_ratio_lagged, replace)
                              [code]
                              and study both graphs. The second one shows you the modeled values of your outcome variable as a function of RD_ratio_lagged, as two curves (actually, straight lines)--one for NIRP = 0 and the other for NIRP = 1. The first one then shows you the marginal effect of NIRP (which is the same as the vertical distance between the two curves on the second graph) as a function of RD_ratio_lagged.

                              Once you have grasped them visually, explain to yourself how the slopes of the two lines in the second graph relate to the -margins- output and to the -xtreg- output. Then run -margins, dydx(NIRP)-, which calculates the average marginal effect of NIRP. See how that value fits with the values of the marginal effect of nirp in the first graph.

                              Finally, because interaction models give rise to many different kinds of marginal effects, you should pretty much banish the phrase "the marginal effect" or "the effect" from your discourse. Whenever you are tempted to say that, stop yourself and think about which marginal effect you are referring to: one that is conditional on certain values, or is an overall average, or is conditional on some values and averaged over others. And then, say, specifically, which one you mean. The avoidance of confusion by using precise language in this context will save you hours of reworking incorrect calculations.
                              Last edited by Clyde Schechter; 02 Dec 2023, 19:13.

                              Comment

                              Working...
                              X