Announcement

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

  • [Help..] - Average marginal effect and triple-interaction term !

    Hello everyone,

    I am writing to ask for your help on one of my projects. I have data on employment and value-added in several manufacturing industries in several countries. In fact, I have 17 industry sub-sectors (textiles, food and beverages, basic metals, etc.) for nine countries over a period of more than twenty years (1990-2014). For the sake of my analysis, I'm looking at the period 2002-2014 to see if it corresponds to a period of deindustrialization or industrialization in my industries (employment and value-added).

    After estimating a very general regression to study the trend of industrialization or de-industrialization over my period of interest (thanks to a dummy taking 1 for the years of interest to me), I wanted to take the descriptive analysis a step further by first investigating heterogeneity within my countries. This is why I added an interaction term between my period of interest captured by a dummy (GP) and a dummy for each of the countries in my model. In this way, I was able to capture the heterogeneity by then calculating the marginal effect per country and plotting the estimate (for example) on a graph through the coeffplot command.

    At this stage, all was working. My last step was now to try to capture the heterogeneity, over the period, between my countries and my sectors thanks to a triple interaction term. Given the number of sectors in my data (19), I grouped them into three dummy groups: a group of commodity-intensive industries (CI), labor-intensive industries (LI), and knowledge-intensive industries (KI). In other words, I have created three dummies, the first one taking "1" for sectors belonging to my first group and so on... Once I've made this, I ran a regression loop for my first commodity-intensive group where I included my triple interaction between my period (1), my dummy for each country (2), and my dummy for my first industry group (3). My idea was therefore to calculate the marginal effect in order to be able to represent the industrialization or de-industrialization trend of my country with respect to my commodity-intensive industries.

    So I launched this code:

    Code:
    eststo clear
    levelsof Country_ABV, local(Country_local)
    foreach x of local Country_local {
    gen `x'= 0
        replace `x'=1 if Country_ABV == "`x'"
        eststo Model1_`x': reg Share_Employment_Sectors_WP $Controls i.GP##`x'##Group1_CI i.Country i.Sectors, cluster(Country)
        margins, dydx(i.GP Group1_CI) over(`x')
        eststo M_Model1_`x': margins if `x'==1, dydx(i.GP Group1_CI) post
        drop `x'
    }
    My problem is that it seems that Stata is not able to compute the margins for my dummy that assess my group number one, i.e. the dummy that takes "1" for the commodity-intensive industries. Am I doing something wrong (in my code or am I misunderstanding something about the triple-interaction term) ? Is it completely impossible for me to compute the margins then?

    Code:
    
    Linear regression                               Number of obs     =      3,556
                                                    F(7, 8)           =          .
                                                    Prob > F          =          .
                                                    R-squared         =     0.6406
                                                    Root MSE          =     .00275
    
                                                         (Std. err. adjusted for 9 clusters in Country)
    ---------------------------------------------------------------------------------------------------
                                      |               Robust
          Share_Employment_Sectors_WP | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    ----------------------------------+----------------------------------------------------------------
                           LogPopSize |  -.0560195   .0097019    -5.77   0.000     -.078392    -.033647
                         LogPopSize_2 |   .0015563   .0003114     5.00   0.001     .0008381    .0022745
                            Log_GDPPC |   .0420228    .008513     4.94   0.001     .0223917    .0616539
                          Log_GDPPC_2 |  -.0023456   .0004804    -4.88   0.001    -.0034535   -.0012378
                                 1.GP |   .0002734   .0004878     0.56   0.590    -.0008515    .0013984
                                1.URY |   -.008507   .0024309    -3.50   0.008    -.0141126   -.0029015
                                      |
                               GP#URY |
                                 1 1  |   -.001076   .0003665    -2.94   0.019    -.0019212   -.0002309
                                      |
                          1.Group1_CI |  -.0000186   .0004979    -0.04   0.971    -.0011667    .0011296
                                      |
                         GP#Group1_CI |
                                 1 1  |   .0002944   .0002851     1.03   0.332     -.000363    .0009518
                                      |
                        URY#Group1_CI |
                                 1 1  |   .0018881   .0003053     6.18   0.000      .001184    .0025921
                                      |
                     GP#URY#Group1_CI |
                               1 1 1  |   .0011365   .0002772     4.10   0.003     .0004974    .0017756
                                      |
                              Country |
                              Brazil  |   .0038352   .0062795     0.61   0.558    -.0106454    .0183158
                               Chile  |   .0018552   .0006698     2.77   0.024     .0003105    .0033998
                            Colombia  |   .0034393   .0026464     1.30   0.230    -.0026633    .0095418
                          Costa Rica  |  -.0049458   .0021438    -2.31   0.050    -.0098894   -2.16e-06
                             Ecuador  |  -.0005481   .0005711    -0.96   0.365    -.0018651    .0007689
                              Mexico  |    .003599   .0046459     0.77   0.461    -.0071145    .0143125
                                Peru  |   .0048443   .0018613     2.60   0.031     .0005522    .0091365
                             Uruguay  |          0  (omitted)
                                      |
                              Sectors |
     Chemicals and chemical products  |   .0017007   .0004658     3.65   0.006     .0006265     .002775
    Coke,refined petroleum product..  |  -.0010946   .0004265    -2.57   0.033    -.0020782   -.0001111
    Electrical machinery and appar..  |   .0003235   .0005114     0.63   0.545    -.0008558    .0015028
           Fabricated metal products  |   .0014142   .0003606     3.92   0.004     .0005828    .0022457
                  Food and beverages  |   .0135147   .0026814     5.04   0.001     .0073312    .0196981
     Furniture; manufacturing n.e.c.  |   .0013932   .0007604     1.83   0.104    -.0003601    .0031466
    Leather, leather products and ..  |    .000844   .0005114     1.65   0.137    -.0003353    .0020234
      Machinery and equipment n.e.c.  |   .0007128   .0003188     2.24   0.056    -.0000224     .001448
    Motor vehicles, trailers, semi..  |   .0006206   .0005287     1.17   0.274    -.0005985    .0018398
       Non-metallic mineral products  |   .0007444   .0003736     1.99   0.081     -.000117    .0016058
            Paper and paper products  |  -.0003375   .0003631    -0.93   0.380    -.0011749    .0004999
             Printing and publishing  |   .0006195   .0004412     1.40   0.198     -.000398     .001637
        Rubber and plastics products  |   .0014244   .0005439     2.62   0.031     .0001702    .0026786
                            Textiles  |    .002277   .0007656     2.97   0.018     .0005116    .0040424
                Wearing apparel, fur  |   .0046928    .001946     2.41   0.042     .0002053    .0091803
     Wood products (excl. furniture)  |          0  (omitted)
                                      |
                                _cons |   .3126299   .0863151     3.62   0.007      .113587    .5116728
    ---------------------------------------------------------------------------------------------------
    
    Average marginal effects                                 Number of obs = 3,556
    Model VCE: Robust
    
    Expression: Linear prediction, predict()
    dy/dx wrt:  1.GP 1.Group1_CI
    Over:       URY
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    0.GP         |  (base outcome)
    -------------+----------------------------------------------------------------
    1.GP         |
             URY |
              0  |   .0003784   .0004113     0.92   0.384      -.00057    .0013268
              1  |  -.0002841   .0001616    -1.76   0.117    -.0006569    .0000886
    -------------+----------------------------------------------------------------
    0.Group1_CI  |  (base outcome)
    -------------+----------------------------------------------------------------
    1.Group1_CI  |
             URY |
              0  |          .  (not estimable)
              1  |          .  (not estimable)
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    
    Average marginal effects                                   Number of obs = 414
    Model VCE: Robust
    
    Expression: Linear prediction, predict()
    dy/dx wrt:  1.GP 1.Group1_CI
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            1.GP |  -.0002841   .0001616    -1.76   0.117    -.0006569    .0000886
     1.Group1_CI |          .  (not estimable)
    ------------------------------------------------------------------------------
    Note: dy/dx for factor levels is the discrete change from the base level.
    
    .
    end of do-file

    Thank you in advance for taking the time to read me! I would be very grateful if you could help me because I have to admit that I am buttering on this problem and don't know how to solve it or get around it...
    Last edited by Yanis Bekhti; 18 Apr 2023, 07:56.

  • #2
    The short answer is that there isn't such a thing as a marginal effect of an interaction, so Stata cannot compute one. Intuitively, if I have a dummy for country interacted with a time dummy, I can calculate the marginal effect for that country holding time constant, or for that time period holding country constant, but for the interaction, there's nothing to hold constant- by definition my interaction term is composed of the two dummies, so I can't vary it while holding their values constant.

    See discussion here, which also links to some slides by Richard Williams which I've found very helpful for using margins.

    Comment


    • #3
      On the one hand, I understand what you are saying (seems logical), but, on the other hand, I still find it hard to believe that I cannot calculate the marginal effect as I was able to calculate it in my second model.

      In my second model, my dependent variable is either the share of employment or the share of value added for each industry. I then regress these values on a branch of control variables and especially on my interaction between my period of interest - a dummy taking "1" for the years between 2002 and 2014 - and my dummy for each country to capture the effect of that country against the total sample. If it's not possible to compute the marginal effect of an interaction, why is it working in this case?

      Here is my code if you want to have a check :

      Code:
      eststo clear 
      levelsof Country_ABV, local(Country_local)
      foreach x of local Country_local {
      gen `x'= 0
          replace `x'=1 if Country_ABV == "`x'"
          eststo Model2_Emp_`x': reg Share_Employment_Sectors_WP $Controls i.GP##i.`x' i.Country i.Sectors, cluster(Country)
          estadd local FE_Country "Yes"
          estadd local FE_Sectors "Yes"
          margins, dydx(i.GP) over(`x')
          eststo M_Model2_Emp_`x': margins if `x'==1, dydx(i.GP) post
          drop `x'
      }
      Then, it gave me the following output with the marginal effect:

      Code:
      Linear regression                               Number of obs     =      3,556
                                                      F(7, 8)           =          .
                                                      Prob > F          =          .
                                                      R-squared         =     0.6328
                                                      Root MSE          =     .00278
      
                                                           (Std. err. adjusted for 9 clusters in Country)
      ---------------------------------------------------------------------------------------------------
                                        |               Robust
            Share_Employment_Sectors_WP | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      ----------------------------------+----------------------------------------------------------------
                             LogPopSize |  -.0560533   .0097029    -5.78   0.000    -.0784283   -.0336784
                           LogPopSize_2 |   .0015587   .0003109     5.01   0.001     .0008417    .0022756
                              Log_GDPPC |   .0421651   .0084903     4.97   0.001     .0225864    .0617437
                            Log_GDPPC_2 |  -.0023544    .000479    -4.92   0.001     -.003459   -.0012498
                                   1.GP |   .0003779   .0004136     0.91   0.388    -.0005759    .0013317
                                  1.URY |  -.0077728   .0023905    -3.25   0.012    -.0132853   -.0022602
                                        |
                                 GP#URY |
                                   1 1  |  -.0006771      .0003    -2.26   0.054     -.001369    .0000147
                                        |
                                Country |
                                Brazil  |   .0036957   .0062606     0.59   0.571    -.0107412    .0181327
                                 Chile  |   .0018453   .0006774     2.72   0.026     .0002831    .0034074
                              Colombia  |   .0033695     .00264     1.28   0.238    -.0027184    .0094574
                            Costa Rica  |  -.0049164   .0021471    -2.29   0.051    -.0098675    .0000347
                               Ecuador  |   -.000565   .0005681    -0.99   0.349     -.001875     .000745
                                Mexico  |    .003494   .0046352     0.75   0.473    -.0071948    .0141827
                                  Peru  |    .004796   .0018587     2.58   0.033     .0005098    .0090822
                               Uruguay  |          0  (omitted)
                                        |
                                Sectors |
       Chemicals and chemical products  |   .0021183   .0004517     4.69   0.002     .0010767      .00316
      Coke,refined petroleum product..  |  -.0006553   .0003295    -1.99   0.082    -.0014151    .0001044
      Electrical machinery and appar..  |   .0003287   .0005095     0.65   0.537    -.0008461    .0015036
             Fabricated metal products  |   .0014118    .000361     3.91   0.004     .0005794    .0022442
                    Food and beverages  |    .013931   .0029109     4.79   0.001     .0072184    .0206436
       Furniture; manufacturing n.e.c.  |   .0013908   .0007593     1.83   0.104    -.0003601    .0031417
      Leather, leather products and ..  |   .0008149   .0004879     1.67   0.133    -.0003101    .0019399
        Machinery and equipment n.e.c.  |   .0007138   .0003182     2.24   0.055      -.00002    .0014476
      Motor vehicles, trailers, semi..  |   .0006265    .000526     1.19   0.268    -.0005865    .0018395
         Non-metallic mineral products  |   .0011607    .000309     3.76   0.006     .0004482    .0018732
              Paper and paper products  |   .0000913   .0002633     0.35   0.738     -.000516    .0006986
               Printing and publishing  |   .0006159   .0004397     1.40   0.199    -.0003981      .00163
          Rubber and plastics products  |   .0014257   .0005433     2.62   0.030     .0001729    .0026785
                              Textiles  |   .0022783   .0007639     2.98   0.018     .0005167    .0040399
                  Wearing apparel, fur  |   .0046875   .0019447     2.41   0.042      .000203     .009172
       Wood products (excl. furniture)  |    .000418   .0004269     0.98   0.356    -.0005663    .0014024
                                        |
                                  _cons |   .3118493   .0861146     3.62   0.007     .1132686      .51043
      ---------------------------------------------------------------------------------------------------
      
      added macro:
               e(FE_Country) : "Yes"
      
      added macro:
               e(FE_Sectors) : "Yes"
      
      Average marginal effects                                 Number of obs = 3,556
      Model VCE: Robust
      
      Expression: Linear prediction, predict()
      dy/dx wrt:  1.GP
      Over:       URY
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
      0.GP         |  (base outcome)
      -------------+----------------------------------------------------------------
      1.GP         |
               URY |
                0  |   .0003779   .0004136     0.91   0.388    -.0005759    .0013317
                1  |  -.0002993   .0001595    -1.88   0.097     -.000667    .0000685
      ------------------------------------------------------------------------------
      Note: dy/dx for factor levels is the discrete change from the base level.
      
      Average marginal effects                                   Number of obs = 414
      Model VCE: Robust
      
      Expression: Linear prediction, predict()
      dy/dx wrt:  1.GP
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
              1.GP |  -.0002993   .0001595    -1.88   0.097     -.000667    .0000685
      ------------------------------------------------------------------------------
      Note: dy/dx for factor levels is the discrete change from the base level.
      By the way, this has allowed me to assess the heterogeneity between my countries as can be seen in my picture below. So, basically, I would like to complete this output, but by estimating it for my sectors to see if the trend in industrialization or deindustrialization differs according to my distinct groups of industries. Could you perhaps explain why my second model worked but not the third one I planned to try?

      Click image for larger version

Name:	Model 2 - Employment Heterogeneity.png
Views:	1
Size:	41.2 KB
ID:	1710326

      Comment


      • #4
        You did not calculate a marginal effect for your interaction term in the second model. You calculated a marginal effect for i.GP. i.GP is a component of your interaction term, but it is not the interaction term itself.

        To reiterate the excellent advice you got in #2, there is no such thing as the marginal effect of an interaction term. Don't waste your time trying to calculate one. Your time would be better spent chasing unicorns.

        That said, in #1, you are not trying to calculate the marginal effect of the interaction term either. You attempted to get marginal effects of GP and Group1_CI. And, in fact, you were successful with respect to GP, and failed only in Group1_CI. In #3 you removed Group1_CI from the model and everything went more smoothly. The problem is that you are over-parameterizing your model in #1. You have a series of sector indicators (i.Sectors) and then you include an indicator for a subset of the sectors (Group1_CI). Those are colinear. You can see that also because, in addition to the base category of Sectors, an additional sector, wood products, got dropped. That shouldn't happen in a well-formed model.

        In general, you cannot include indicator ("dummy") variable groups for a whole group (sectors) and also for a subset thereof and get valid estimates of marginal effects involving those variables. They will necessarily be colinear. You broke your model by including Group1_CI. The reason this makes the effect of Group1_CI non-estimable is that there is no way to disentangle it from the separate effects of the various sectors themselves.

        You need to eliminate the colinearity from the model. Removing the Group1_CI variable is one way of doing that, probably the best way.

        And the problem actually turns out to have nothing to do with interactions.
        Last edited by Clyde Schechter; 18 Apr 2023, 10:56.

        Comment


        • #5
          Thank you very much for your reply and for the time you took to help me. I will try to improve the model even if it means adjusting my expectations.

          Comment

          Working...
          X