Announcement

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

  • High-dimensional FE & Marginsplot

    Hello All,


    I am trying to find the impact of firms and other macro-economic variables on exports.

    I am interested in the relationship between firms and exports across different regions (OECD / non-OECD).

    To test this relationship, I use the following command:

    Code:
    reghdfe Exports Firms RD Reg FDI i.OECD#(c.Firms),absorb (ccode year) cluster (ccode)
    
    . reghdfe Exports Firms RD Reg FDI i.OECD#(c.Firms),absorb (ccode year) cluster (
    > ccode)
    (dropped 11 singleton observations)
    (MWFE estimator converged in 5 iterations)
    
    HDFE Linear regression                            Number of obs   =        289
    Absorbing 2 HDFE groups                           F(   5,     81) =       7.19
    Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                      R-squared       =     0.9969
                                                      Adj R-squared   =     0.9955
                                                      Within R-sq.    =     0.0441
    Number of clusters (ccode)   =         82         Root MSE        =  6.435e+09
    
                                     (Std. err. adjusted for 82 clusters in ccode)
    ------------------------------------------------------------------------------
                 |               Robust
         Exports | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           Firms |  -151498.9   33226.54    -4.56   0.000    -217609.3   -85388.46
              RD |   8.18e+09   5.16e+09     1.58   0.117    -2.09e+09    1.85e+10
             Reg |  -2.90e+09   4.56e+09    -0.64   0.526    -1.20e+10    6.17e+09
             FDI |   -2489519    6286609    -0.40   0.693    -1.50e+07    1.00e+07
                 |
    OECD#c.Firms |
              1  |   127215.7   43671.96     2.91   0.005      40322.2    214109.2
                 |
           _cons |   2.96e+10   5.75e+09     5.14   0.000     1.81e+10    4.10e+10
    ------------------------------------------------------------------------------
    
    Absorbed degrees of freedom:
    -----------------------------------------------------+
     Absorbed FE | Categories  - Redundant  = Num. Coefs |
    -------------+---------------------------------------|
           ccode |        82          82           0    *|
            year |         4           1           3     |
    -----------------------------------------------------+
    * = FE nested within cluster; treated as redundant for DoF computation
    The model shows there is a statistical difference between OECD and non-OECD regions, with firms leading to a decrease in exports for OECD and an increase in firms for non-OECD.

    so I proceed with a marginsplot to visualize the relationship.

    Code:
    reg Exports Firms RD Reg FDI OECD c.OECD#c.Firms
    
          Source |       SS           df       MS      Number of obs   =       300
    -------------+----------------------------------   F(6, 293)       =     14.43
           Model |  6.0689e+23         6  1.0115e+23   Prob > F        =    0.0000
        Residual |  2.0532e+24       293  7.0077e+21   R-squared       =    0.2281
    -------------+----------------------------------   Adj R-squared   =    0.2123
           Total |  2.6601e+24       299  8.8968e+21   Root MSE        =    8.4e+10
    
    --------------------------------------------------------------------------------
           Exports | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    ---------------+----------------------------------------------------------------
             Firms |   72683.64   60353.12     1.20   0.229    -46096.93    191464.2
                RD |   3.14e+10   6.75e+09     4.65   0.000     1.81e+10    4.46e+10
               Reg |   1.17e+10   8.28e+09     1.41   0.158    -4.58e+09    2.80e+10
               FDI |   2.10e+08   2.66e+08     0.79   0.431    -3.13e+08    7.33e+08
              OECD |   3.98e+10   1.50e+10     2.66   0.008     1.04e+10    6.93e+10
                   |
    c.OECD#c.Firms |   374095.9   97669.49     3.83   0.000     181873.2    566318.6
                   |
             _cons |  -4.86e+10   1.48e+10    -3.28   0.001    -7.78e+10   -1.94e+10
    --------------------------------------------------------------------------------
    
    
    margins, at (Firms=(0(10000)200000) OECD==(0 1))
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |  -5.99e+09   9.93e+09    -0.60   0.547    -2.55e+10    1.36e+10
              2  |   3.38e+10   8.71e+09     3.89   0.000     1.67e+10    5.10e+10
              3  |  -5.27e+09   9.73e+09    -0.54   0.589    -2.44e+10    1.39e+10
              4  |   3.83e+10   8.37e+09     4.58   0.000     2.18e+10    5.48e+10
              5  |  -4.54e+09   9.56e+09    -0.47   0.635    -2.34e+10    1.43e+10
              6  |   4.28e+10   8.09e+09     5.29   0.000     2.69e+10    5.87e+10
              7  |  -3.81e+09   9.43e+09    -0.40   0.686    -2.24e+10    1.47e+10
              8  |   4.72e+10   7.88e+09     6.00   0.000     3.17e+10    6.27e+10
              9  |  -3.09e+09   9.33e+09    -0.33   0.741    -2.15e+10    1.53e+10
             10  |   5.17e+10   7.73e+09     6.69   0.000     3.65e+10    6.69e+10
             11  |  -2.36e+09   9.28e+09    -0.25   0.799    -2.06e+10    1.59e+10
             12  |   5.62e+10   7.67e+09     7.33   0.000     4.11e+10    7.13e+10
             13  |  -1.63e+09   9.26e+09    -0.18   0.860    -1.99e+10    1.66e+10
             14  |   6.06e+10   7.68e+09     7.90   0.000     4.55e+10    7.58e+10
             15  |  -9.06e+08   9.28e+09    -0.10   0.922    -1.92e+10    1.74e+10
             16  |   6.51e+10   7.77e+09     8.38   0.000     4.98e+10    8.04e+10
             17  |  -1.79e+08   9.34e+09    -0.02   0.985    -1.86e+10    1.82e+10
             18  |   6.96e+10   7.93e+09     8.77   0.000     5.40e+10    8.52e+10
             19  |   5.48e+08   9.44e+09     0.06   0.954    -1.80e+10    1.91e+10
             20  |   7.40e+10   8.17e+09     9.07   0.000     5.80e+10    9.01e+10
             21  |   1.27e+09   9.57e+09     0.13   0.894    -1.76e+10    2.01e+10
             22  |   7.85e+10   8.46e+09     9.28   0.000     6.19e+10    9.52e+10
             23  |   2.00e+09   9.74e+09     0.21   0.837    -1.72e+10    2.12e+10
             24  |   8.30e+10   8.82e+09     9.41   0.000     6.56e+10    1.00e+11
             25  |   2.73e+09   9.95e+09     0.27   0.784    -1.69e+10    2.23e+10
             26  |   8.75e+10   9.22e+09     9.48   0.000     6.93e+10    1.06e+11
             27  |   3.46e+09   1.02e+10     0.34   0.735    -1.66e+10    2.35e+10
             28  |   9.19e+10   9.67e+09     9.50   0.000     7.29e+10    1.11e+11
             29  |   4.18e+09   1.05e+10     0.40   0.689    -1.64e+10    2.48e+10
             30  |   9.64e+10   1.02e+10     9.48   0.000     7.64e+10    1.16e+11
             31  |   4.91e+09   1.07e+10     0.46   0.648    -1.62e+10    2.61e+10
             32  |   1.01e+11   1.07e+10     9.44   0.000     7.98e+10    1.22e+11
             33  |   5.64e+09   1.11e+10     0.51   0.611    -1.61e+10    2.74e+10
             34  |   1.05e+11   1.12e+10     9.37   0.000     8.32e+10    1.27e+11
             35  |   6.36e+09   1.14e+10     0.56   0.577    -1.61e+10    2.88e+10
             36  |   1.10e+11   1.18e+10     9.29   0.000     8.65e+10    1.33e+11
             37  |   7.09e+09   1.18e+10     0.60   0.547    -1.61e+10    3.03e+10
             38  |   1.14e+11   1.24e+10     9.21   0.000     8.98e+10    1.39e+11
             39  |   7.82e+09   1.22e+10     0.64   0.521    -1.61e+10    3.17e+10
             40  |   1.19e+11   1.30e+10     9.11   0.000     9.31e+10    1.44e+11
             41  |   8.54e+09   1.25e+10     0.68   0.497    -1.62e+10    3.32e+10
             42  |   1.23e+11   1.37e+10     9.02   0.000     9.63e+10    1.50e+11
    ------------------------------------------------------------------------------
    
    
    marginsplot
    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	253.9 KB
ID:	1764974



    Would the margins plot be interpreted as:
    - The effect of the level of development (OECD) on exports
    - Exports increase at different speeds for OECD and non OECD nations
    - Non-OECD nations will export significantly more, as firms increase




    Isn’t there a conflict between the results of the model and the marginsplot?

    Are both procedures correct for this type of model?

    Data is attached.


    Thanks in advance
    Attached Files

  • #2
    why not run margins after reghdfe? you can see that the coefficients are entirely different when you exclude the FE (as are the SE).

    Comment


    • #3
      Thanks for your response.

      I labeled the binary variable and ran the margins after reghdfe below.

      Isn't it in conflict with the regression results?

      Code:
      . reghdfe Exports Firms FDI Reg RD i.OECD#c.Firms, cluster (ccode) absorb (ccode year)
      (dropped 11 singleton observations)
      (MWFE estimator converged in 5 iterations)
      
      HDFE Linear regression                            Number of obs   =        289
      Absorbing 2 HDFE groups                           F(   5,     81) =       7.19
      Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                        R-squared       =     0.9969
                                                        Adj R-squared   =     0.9955
                                                        Within R-sq.    =     0.0441
      Number of clusters (ccode)   =         82         Root MSE        =  6.435e+09
      
                                       (Std. err. adjusted for 82 clusters in ccode)
      ------------------------------------------------------------------------------
                   |               Robust
           Exports | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
             Firms |  -151498.9   33226.54    -4.56   0.000    -217609.3   -85388.46
               FDI |   -2489519    6286609    -0.40   0.693    -1.50e+07    1.00e+07
               Reg |  -2.90e+09   4.56e+09    -0.64   0.526    -1.20e+10    6.17e+09
                RD |   8.18e+09   5.16e+09     1.58   0.117    -2.09e+09    1.85e+10
                   |
      OECD#c.Firms |
          NonOECD  |   127215.7   43671.96     2.91   0.005      40322.2    214109.2
                   |
             _cons |   2.96e+10   5.75e+09     5.14   0.000     1.81e+10    4.10e+10
      ------------------------------------------------------------------------------
      
      Absorbed degrees of freedom:
      -----------------------------------------------------+
       Absorbed FE | Categories  - Redundant  = Num. Coefs |
      -------------+---------------------------------------|
             ccode |        82          82           0    *|
              year |         4           1           3     |
      -----------------------------------------------------+
      * = FE nested within cluster; treated as redundant for DoF computation
      
      
      . reghdfe Exports Firms FDI Reg RD i.OECD#c.Firms, cluster (ccode) absorb (ccode year)
      (dropped 11 singleton observations)
      (MWFE estimator converged in 5 iterations)
      
      HDFE Linear regression                            Number of obs   =        289
      Absorbing 2 HDFE groups                           F(   5,     81) =       7.19
      Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                        R-squared       =     0.9969
                                                        Adj R-squared   =     0.9955
                                                        Within R-sq.    =     0.0441
      Number of clusters (ccode)   =         82         Root MSE        =  6.435e+09
      
                                       (Std. err. adjusted for 82 clusters in ccode)
      ------------------------------------------------------------------------------
                   |               Robust
           Exports | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
             Firms |  -151498.9   33226.54    -4.56   0.000    -217609.3   -85388.46
               FDI |   -2489519    6286609    -0.40   0.693    -1.50e+07    1.00e+07
               Reg |  -2.90e+09   4.56e+09    -0.64   0.526    -1.20e+10    6.17e+09
                RD |   8.18e+09   5.16e+09     1.58   0.117    -2.09e+09    1.85e+10
                   |
      OECD#c.Firms |
          NonOECD  |   127215.7   43671.96     2.91   0.005      40322.2    214109.2
                   |
             _cons |   2.96e+10   5.75e+09     5.14   0.000     1.81e+10    4.10e+10
      ------------------------------------------------------------------------------
      
      Absorbed degrees of freedom:
      -----------------------------------------------------+
       Absorbed FE | Categories  - Redundant  = Num. Coefs |
      -------------+---------------------------------------|
             ccode |        82          82           0    *|
              year |         4           1           3     |
      -----------------------------------------------------+
      * = FE nested within cluster; treated as redundant for DoF computation
      
      . margins, at (Firms=(0(10000)200000) OECD==(0 1))
      Code:
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |     Margin   std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
               _at |
                1  |   3.71e+10   1.39e+09    26.72   0.000     3.44e+10    3.98e+10
                2  |   3.71e+10   1.39e+09    26.72   0.000     3.44e+10    3.98e+10
                3  |   3.56e+10   1.15e+09    30.91   0.000     3.34e+10    3.79e+10
                4  |   3.69e+10   1.18e+09    31.27   0.000     3.46e+10    3.92e+10
                5  |   3.41e+10   9.71e+08    35.09   0.000     3.22e+10    3.60e+10
                6  |   3.66e+10   1.03e+09    35.58   0.000     3.46e+10    3.87e+10
                7  |   3.26e+10   8.84e+08    36.85   0.000     3.08e+10    3.43e+10
                8  |   3.64e+10   9.69e+08    37.56   0.000     3.45e+10    3.83e+10
                9  |   3.11e+10   9.17e+08    33.88   0.000     2.93e+10    3.29e+10
               10  |   3.62e+10   1.01e+09    35.68   0.000     3.42e+10    3.81e+10
               11  |   2.95e+10   1.06e+09    27.92   0.000     2.75e+10    3.16e+10
               12  |   3.59e+10   1.15e+09    31.22   0.000     3.37e+10    3.82e+10
               13  |   2.80e+10   1.27e+09    22.02   0.000     2.55e+10    3.05e+10
               14  |   3.57e+10   1.35e+09    26.38   0.000     3.30e+10    3.83e+10
               15  |   2.65e+10   1.53e+09    17.33   0.000     2.35e+10    2.95e+10
               16  |   3.54e+10   1.59e+09    22.21   0.000     3.23e+10    3.85e+10
               17  |   2.50e+10   1.81e+09    13.80   0.000     2.15e+10    2.86e+10
               18  |   3.52e+10   1.86e+09    18.90   0.000     3.15e+10    3.88e+10
               19  |   2.35e+10   2.11e+09    11.14   0.000     1.94e+10    2.76e+10
               20  |   3.49e+10   2.14e+09    16.29   0.000     3.07e+10    3.91e+10
               21  |   2.20e+10   2.41e+09     9.10   0.000     1.72e+10    2.67e+10
               22  |   3.47e+10   2.44e+09    14.24   0.000     2.99e+10    3.95e+10
               23  |   2.05e+10   2.73e+09     7.50   0.000     1.51e+10    2.58e+10
               24  |   3.45e+10   2.74e+09    12.59   0.000     2.91e+10    3.98e+10
               25  |   1.89e+10   3.04e+09     6.23   0.000     1.30e+10    2.49e+10
               26  |   3.42e+10   3.04e+09    11.25   0.000     2.82e+10    4.02e+10
               27  |   1.74e+10   3.36e+09     5.18   0.000     1.08e+10    2.40e+10
               28  |   3.40e+10   3.35e+09    10.14   0.000     2.74e+10    4.05e+10
               29  |   1.59e+10   3.68e+09     4.32   0.000     8.69e+09    2.31e+10
               30  |   3.37e+10   3.66e+09     9.21   0.000     2.65e+10    4.09e+10
               31  |   1.44e+10   4.01e+09     3.59   0.000     6.54e+09    2.23e+10
               32  |   3.35e+10   3.97e+09     8.43   0.000     2.57e+10    4.13e+10
               33  |   1.29e+10   4.33e+09     2.97   0.003     4.39e+09    2.14e+10
               34  |   3.32e+10   4.29e+09     7.75   0.000     2.48e+10    4.16e+10
               35  |   1.14e+10   4.66e+09     2.44   0.015     2.24e+09    2.05e+10
               36  |   3.30e+10   4.60e+09     7.17   0.000     2.40e+10    4.20e+10
               37  |   9.85e+09   4.98e+09     1.98   0.048     8.31e+07    1.96e+10
               38  |   3.28e+10   4.92e+09     6.66   0.000     2.31e+10    4.24e+10
               39  |   8.34e+09   5.31e+09     1.57   0.117    -2.07e+09    1.87e+10
               40  |   3.25e+10   5.24e+09     6.21   0.000     2.22e+10    4.28e+10
               41  |   6.82e+09   5.64e+09     1.21   0.226    -4.23e+09    1.79e+10
               42  |   3.23e+10   5.55e+09     5.81   0.000     2.14e+10    4.32e+10
      ------------------------------------------------------------------------------
      
      . marginsplot
      Click image for larger version

Name:	Reghdfe.png
Views:	1
Size:	219.8 KB
ID:	1765166

      Last edited by Nae Khar; 06 Oct 2024, 14:39.

      Comment


      • #4
        Hi Nae,

        One thing that pops out to me is your reghdfe code, and specifically your interaction. You have only a single #, which tells Stata that you only want the interaction and not the main effects. The code should be one of the follwing to get both main effects and interactions:
        Code:
        reghdfe Exports Firms FDI Reg RD i.OECD##c.Firms, cluster (ccode) absorb (ccode year)
        *or
        reghdfe Exports Firms FDI Reg RD i.OECD c.Firms i.OECD#c.Firms, cluster (ccode) absorb (ccode year)
        It also seems weird to me that you treat Firms as continuous (c.Firms) vs. factors (i.Firms). This means that you are allowing the effect of Firms to be linear, such that higher values of firms have more "strength" on the continuum than lower values of firms. Is that what you want?
        Last edited by Erik Ruzek; 07 Oct 2024, 10:06. Reason: Grammatical correction

        Comment


        • #5
          Depending on the years in the data, an OECD dummy will be time invariant and thus eaten by ccode. The margins graph is correct. You've got a negative coefficient on firms, and the slope is less negative for non-OECD firms (interaction is positive).

          Comment


          • #6
            Thanks for your suggestion Erik.

            The main effects will be omitted when running a reghdfe.

            Code:
            . reghdfe Exports Firms FDI Reg RD i.OECD##c.Firms, cluster (ccode) absorb (ccode year)
            (dropped 11 singleton observations)
            (MWFE estimator converged in 5 iterations)
            note: 1bn.OECD is probably collinear with the fixed effects (all partialled-out values are close to zero
            > ; tol = 1.0e-09)
            note: 0b.OECD omitted because of collinearity
            
            HDFE Linear regression                            Number of obs   =        289
            Absorbing 2 HDFE groups                           F(   5,     81) =       7.19
            Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                              R-squared       =     0.9969
                                                              Adj R-squared   =     0.9955
                                                              Within R-sq.    =     0.0441
            Number of clusters (ccode)   =         82         Root MSE        =  6.435e+09
            
                                             (Std. err. adjusted for 82 clusters in ccode)
            ------------------------------------------------------------------------------
                         |               Robust
                 Exports | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                   Firms |  -151498.9   33226.54    -4.56   0.000    -217609.3   -85388.46
                     FDI |   -2489519    6286609    -0.40   0.693    -1.50e+07    1.00e+07
                     Reg |  -2.90e+09   4.56e+09    -0.64   0.526    -1.20e+10    6.17e+09
                      RD |   8.18e+09   5.16e+09     1.58   0.117    -2.09e+09    1.85e+10
                         |
                    OECD |
                NonOECD  |          0  (omitted)
                   Firms |          0  (omitted)
                         |
            OECD#c.Firms |
                NonOECD  |   127215.7   43671.96     2.91   0.005      40322.2    214109.2
                         |
                   _cons |   2.96e+10   5.75e+09     5.14   0.000     1.81e+10    4.10e+10
            ------------------------------------------------------------------------------
            
            Absorbed degrees of freedom:
            -----------------------------------------------------+
             Absorbed FE | Categories  - Redundant  = Num. Coefs |
            -------------+---------------------------------------|
                   ccode |        82          82           0    *|
                    year |         4           1           3     |
            -----------------------------------------------------+
            * = FE nested within cluster; treated as redundant for DoF computation

            Firms is a continuous variable. The model does not run when i. instead of c. is used in the command.

            Code:
            . reghdfe Exports Firms FDI Reg RD i.OECD##i.Firms, cluster (ccode) absorb (ccode year)
            (dropped 11 singleton observations)
            (MWFE estimator converged in 5 iterations)
            note: 1bn.OECD is probably collinear with the fixed effects (all partialled-out values are close to zero
            > ; tol = 1.0e-09)
            note: 831.Firms omitted because of collinearity
            note: 2547.Firms omitted because of collinearity
            note: 2576.Firms omitted because of collinearity
            ...
            unable to allocate matrix;
                You have attempted to create a matrix with too many rows or columns or attempted to fit a model
                with too many variables.
            
                You are using Stata/BE which supports matrices with up to 800 rows or columns.  See limits for how
                many more rows and columns Stata/SE and Stata/MP can support.
            
                If you are using factor variables and included an interaction that has lots of missing cells, try
                set emptycells drop to reduce the required matrix size; see help set emptycells.
            
                If you are using factor variables, you might have accidentally treated a continuous variable as a
                categorical, resulting in lots of categories.  Use the c. operator on such variables.
            r(915);
            I want to examine the impact of firms on exports for OECD vs. non-OECD regions and visualize the relationship.

            Comment


            • #7
              George,

              Thanks for your input.

              Its my understanding that the coefficient of Firms is not the marginal effect and not interpretable.

              I believe the interaction effect would be interpreted as Non-OECD economies will see 127,215 more in exports for each additional firm, compared to OECD economies. How can the I visualize this relationship through the margins graph?

              The margins graph shows a negative slope for nonOECD.

              Comment


              • #8
                Incorrect interpretation. The effect in the OECD is -151498.9 and in the non-OECD is (-151498.9 + 127215.7).

                Comment


                • #9
                  Is it normal to treat a variable that is clearly a factor (each firm is unique) as a continuous variable in these models? I cannot think of any modeling situation where I would treat a variable like this (schools, countries, etc.) as continuous.

                  Comment


                  • #10
                    It seems you are saying that the number of firms determines the outcome. If so, then yes. If you want to say something else, then perhaps not. I suspect the number of firms is correlated with something that matters--it's probably not firms per se. Larger economies (larger GDP, maybe) probably have more firms.

                    The coefficient on firms is interpretable. Is the relationship in OECD countries. The interaction + the coefficient on Firms is the slope for non-OECD countries. Both slope downward, with OECD firms having a stronger negative slope.

                    The graph in #3 is correct.

                    Comment


                    • #11
                      Many thanks for the clarification.

                      What I find to be puzzling is the interpretation that firms would lead to a decrease in exports across countries, and even more so in the OECD.

                      In a plain regression, the results show firms to have a positive impact on exports. Once time and country fixed effects are applied, the sign reverses.

                      Last edited by Nae Khar; 09 Oct 2024, 13:25.

                      Comment


                      • #12
                        Erik,

                        I have seen it used as a continuous variable in the literature with economic development, innovation, business climate, infrastructure, regulatory frameworks, etc.

                        https://www.worldbank.org/en/program...umber-of-firms

                        https://www.worldbank.org/en/program...why-it-matters
                        Last edited by Nae Khar; 09 Oct 2024, 13:23.

                        Comment


                        • #13
                          Spend some time to learn about the difference of the "within" and "between" estimator, and then decide which one you want to use.

                          Comment

                          Working...
                          X