Announcement

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

  • Plotting coefficients for fixed effects regression

    Hello forum!

    I have been researching for a while yet I have not found an answer to my question, so I am hoping someone could kindly help here

    I am trying to plot coefficients for a regression where I have year and country fixed effects, the regression command is:
    HTML Code:
    xtreg gov_eff c.mobile##i.income i.t, fe cluster(id)
    I tried using this:
    HTML Code:
    xtreg gov_eff c.mobile##i.income i.t if income==0, fe cluster(id)
    HTML Code:
     estimates store gov_eff_low
    HTML Code:
    xtreg gov_eff c.mobile##i.income i.t if income==1, fe cluster(id)
    HTML Code:
     estimates store gov_eff_high
    HTML Code:
    coefplot gov_eff_low gov_eff_high, drop(_cons)
    But it graphs all the i.t coefficients and the graph looks confusing overall.

    Is there a more straightforward way to graph a fixed effects model with an interaction?

    Thank you in advance for your help!


  • #2
    coefplot is from SSC (FAQ Advice #12).

    But it graphs all the i.t coefficients and the graph looks confusing overall.
    Code:
    coefplot gov_eff_low gov_eff_high, drop(_cons *.t)

    Comment


    • #3
      Thank you Andrew! I want to plot the coefficients and show how they differ between high and low income countries.

      For some reason I get different income-specific coefficients from running:
      Code:
      xtreg gov_eff c.mobile##i.income i.t, fe cluster(id)
      and running separate
      Code:
      xtreg gov_eff c.mobile##i.income i.t if income==0, fe cluster(id)
      and
      Code:
      xtreg gov_eff c.mobile##i.income i.t if income==1, fe cluster(id)
      I thought the "if" command would help to simply separate the effects and yield the same coefficients as the first regression, without having to add the Betas to assess the effect in high-income countries.

      Please let me know what you think I'm doing wrong here! I really appreciate your help.

      Comment


      • #4
        For a fixed effects interaction model estimated using xtreg, the interacting variable should define disjoint groups of the panel identifier to get the same coefficients (see #25 https://www.statalist.org/forums/for...bsamples/page2). So you need to interact the panel identifier as well. Consider "income" in your model to be "himvalue" in the example below.

        Code:
        webuse grunfeld, clear
        qui sum mvalue, d
        gen himvalue = mvalue>r(p50)
        xtset company time
        xtreg invest c.kstock i.time if himvalue, fe
        xtreg invest c.kstock i.time if !himvalue, fe
        xtreg invest i.himvalue#(c.kstock i.time i.company), fe
        Res.:

        Code:
        . xtreg invest c.kstock i.time if himvalue, fe
        
        Fixed-effects (within) regression               Number of obs     =        100
        Group variable: company                         Number of groups  =          6
        
        R-sq:                                           Obs per group:
             within  = 0.7773                                         min =          5
             between = 0.6678                                         avg =       16.7
             overall = 0.5982                                         max =         20
        
                                                        F(20,74)          =      12.91
        corr(u_i, Xb)  = 0.3086                         Prob > F          =     0.0000
        
        ------------------------------------------------------------------------------
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              kstock |   .4238765   .0402593    10.53   0.000     .3436581    .5040949
                     |
                time |
                  2  |    65.9517    62.5371     1.05   0.295    -58.65619    190.5596
                  3  |   75.54409   60.32026     1.25   0.214    -44.64664    195.7348
                  4  |   -42.1496   62.97104    -0.67   0.505    -167.6221    83.32294
                  5  |   -29.0902   60.72047    -0.48   0.633    -150.0784    91.89797
                  6  |   36.79447   60.67396     0.61   0.546    -84.10104      157.69
                  7  |   71.59407   60.82097     1.18   0.243    -49.59436    192.7825
                  8  |   35.62359   63.45525     0.56   0.576    -90.81375    162.0609
                  9  |   14.07441   61.10779     0.23   0.818    -107.6855    135.8343
                 10  |   17.75362   60.97603     0.29   0.772    -103.7438     139.251
                 11  |   28.79126   60.96334     0.47   0.638    -92.68084    150.2634
                 12  |   90.65411   61.13105     1.48   0.142    -31.15216    212.4604
                 13  |   8.274701   62.37855     0.13   0.895    -116.0173    132.5667
                 14  |  -8.283251   63.15916    -0.13   0.896    -134.1306    117.5641
                 15  |  -58.64566   63.87233    -0.92   0.362    -185.9141    68.62274
                 16  |  -38.26992   63.17071    -0.61   0.546    -164.1403    87.60047
                 17  |    20.9081   63.59714     0.33   0.743     -105.812    147.6282
                 18  |    21.9819   65.01859     0.34   0.736    -107.5705    151.5343
                 19  |   57.28943    67.2097     0.85   0.397    -76.62883    191.2077
                 20  |   5.700601   69.72564     0.08   0.935    -133.2308     144.632
                     |
               _cons |    99.6754   47.68797     2.09   0.040     4.655045    194.6957
        -------------+----------------------------------------------------------------
             sigma_u |  164.39617
             sigma_e |  81.399113
                 rho |  .80310732   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        F test that all u_i=0: F(5, 74) = 63.16                      Prob > F = 0.0000
        
        . 
        . xtreg invest c.kstock i.time if !himvalue, fe
        
        Fixed-effects (within) regression               Number of obs     =        100
        Group variable: company                         Number of groups  =          7
        
        R-sq:                                           Obs per group:
             within  = 0.6612                                         min =          2
             between = 0.3993                                         avg =       14.3
             overall = 0.5898                                         max =         20
        
                                                        F(20,73)          =       7.12
        corr(u_i, Xb)  = 0.2895                         Prob > F          =     0.0000
        
        ------------------------------------------------------------------------------
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              kstock |    .046519   .0150298     3.10   0.003     .0165645    .0764734
                     |
                time |
                  2  |   3.902567   5.189464     0.75   0.454     -6.44002    14.24515
                  3  |   10.43642   5.567417     1.87   0.065    -.6594288    21.53226
                  4  |   4.250117   5.266114     0.81   0.422    -6.245233    14.74547
                  5  |   .4952627   5.630053     0.09   0.930    -10.72542    11.71594
                  6  |   2.417116   5.666461     0.43   0.671    -8.876125    13.71036
                  7  |   10.75171   5.713438     1.88   0.064    -.6351585    22.13857
                  8  |   3.263309   5.442657     0.60   0.551     -7.58389    14.11051
                  9  |   6.772048   5.862602     1.16   0.252    -4.912101     18.4562
                 10  |   15.82362   5.930268     2.67   0.009     4.004617    27.64263
                 11  |   11.20588   6.019456     1.86   0.067     -.790882    23.20263
                 12  |   14.38429   6.064576     2.37   0.020     2.297603    26.47097
                 13  |   13.18348   6.195508     2.13   0.037     .8358522    25.53111
                 14  |   15.17493   6.316956     2.40   0.019     2.585258    27.76461
                 15  |   12.82532   6.447474     1.99   0.050      -.02448    25.67511
                 16  |   4.238418   6.971358     0.61   0.545    -9.655478    18.13231
                 17  |   18.82854   7.087479     2.66   0.010     4.703218    32.95387
                 18  |     23.791   7.267244     3.27   0.002     9.307408     38.2746
                 19  |    24.7706   7.478094     3.31   0.001     9.866776    39.67442
                 20  |   20.55126   7.671909     2.68   0.009     5.261163    35.84135
                     |
               _cons |   17.47424   3.936363     4.44   0.000     9.629083     25.3194
        -------------+----------------------------------------------------------------
             sigma_u |  15.174808
             sigma_e |  9.2033502
                 rho |  .73108575   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        F test that all u_i=0: F(6, 73) = 20.18                      Prob > F = 0.0000
        
        . 
        . xtreg invest i.himvalue#(c.kstock i.time i.company), fe
        note: 0b.himvalue#1b.company identifies no observations in the sample
        note: 0b.himvalue#2.company identifies no observations in the sample
        note: 0b.himvalue#3.company identifies no observations in the sample
        note: 0b.himvalue#5.company omitted because of collinearity
        note: 0b.himvalue#7.company omitted because of collinearity
        note: 0b.himvalue#8.company omitted because of collinearity
        note: 0b.himvalue#9.company omitted because of collinearity
        note: 0b.himvalue#10.company omitted because of collinearity
        note: 1.himvalue#1b.company omitted because of collinearity
        note: 1.himvalue#2.company omitted because of collinearity
        note: 1.himvalue#3.company omitted because of collinearity
        note: 1.himvalue#4.company omitted because of collinearity
        note: 1.himvalue#5.company identifies no observations in the sample
        note: 1.himvalue#6.company omitted because of collinearity
        note: 1.himvalue#7.company identifies no observations in the sample
        note: 1.himvalue#8.company omitted because of collinearity
        note: 1.himvalue#9.company identifies no observations in the sample
        note: 1.himvalue#10.company identifies no observations in the sample
        
        Fixed-effects (within) regression               Number of obs     =        200
        Group variable: company                         Number of groups  =         10
        
        R-sq:                                           Obs per group:
             within  = 0.7788                                         min =         20
             between = 0.7571                                         avg =       20.0
             overall = 0.6712                                         max =         20
        
                                                        F(43,147)         =      12.03
        corr(u_i, Xb)  = 0.4358                         Prob > F          =     0.0000
        
        -----------------------------------------------------------------------------------
                   invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        ------------------+----------------------------------------------------------------
        himvalue#c.kstock |
                       0  |    .046519   .0949089     0.49   0.625    -.1410431     .234081
                       1  |   .4238765   .0287438    14.75   0.000      .367072     .480681
                          |
            himvalue#time |
                    0  2  |   3.902567   32.76987     0.12   0.905    -60.85834    68.66348
                    0  3  |   10.43642   35.15653     0.30   0.767    -59.04108    79.91392
                    0  4  |   4.250117   33.25389     0.13   0.898    -61.46733    69.96756
                    0  5  |   .4952627   35.55205     0.01   0.989    -69.76389    70.75442
                    0  6  |   2.417116   35.78196     0.07   0.946    -68.29638    73.13062
                    0  7  |   10.75171    36.0786     0.30   0.766    -60.54803    82.05145
                    0  8  |   3.263309    34.3687     0.09   0.924    -64.65726    71.18388
                    0  9  |   6.772048   37.02053     0.18   0.855    -66.38915    79.93324
                    0 10  |   15.82362   37.44782     0.42   0.673      -58.182    89.82925
                    0 11  |   11.20588   38.01101     0.29   0.769    -63.91275     86.3245
                    0 12  |   14.38429   38.29593     0.38   0.708    -61.29741    90.06598
                    0 13  |   13.18348   39.12273     0.34   0.737    -64.13216    90.49912
                    0 14  |   15.17493   39.88963     0.38   0.704    -63.65629    94.00616
                    0 15  |   12.82532   40.71381     0.32   0.753    -67.63468    93.28531
                    0 16  |   4.238418   44.02198     0.10   0.923    -82.75928    91.23612
                    0 17  |   18.82854   44.75525     0.42   0.675    -69.61827    107.2754
                    0 18  |     23.791   45.89041     0.52   0.605    -66.89915    114.4812
                    0 19  |    24.7706   47.22187     0.52   0.601    -68.55083     118.092
                    0 20  |   20.55126   48.44575     0.42   0.672    -75.18884    116.2914
                    1  1  |  -29.31765   58.54926    -0.50   0.617    -145.0246    86.38935
                    1  2  |   36.63405   55.57909     0.66   0.511    -73.20321    146.4713
                    1  3  |   46.22644   52.95198     0.87   0.384    -58.41903    150.8719
                    1  4  |  -71.46725   54.37256    -1.31   0.191    -178.9201    35.98561
                    1  5  |  -58.40785   52.82245    -1.11   0.271    -162.7973    45.98163
                    1  6  |   7.476816   52.83236     0.14   0.888    -96.93226    111.8859
                    1  7  |   42.27642   52.80432     0.80   0.425    -62.07723    146.6301
                    1  8  |   6.305942   54.26214     0.12   0.908    -100.9287    113.5406
                    1  9  |  -15.24324   52.77248    -0.29   0.773     -119.534    89.04749
                    1 10  |  -11.56403   52.78387    -0.22   0.827    -115.8773    92.74921
                    1 11  |  -.5263929   52.78524    -0.01   0.992    -104.8423    103.7895
                    1 12  |   61.33646   52.77097     1.16   0.247     -42.9513    165.6242
                    1 13  |  -21.04295   52.83421    -0.40   0.691    -125.4557    83.36978
                    1 14  |   -37.6009   52.96313    -0.71   0.479    -142.2684     67.0666
                    1 15  |  -87.96331   53.11732    -1.66   0.100    -192.9355     17.0089
                    1 16  |  -67.58757   52.43743    -1.29   0.199    -171.2162    36.04103
                    1 17  |  -8.409546   52.55439    -0.16   0.873    -112.2693    95.45019
                    1 18  |  -7.335754    52.9886    -0.14   0.890    -112.0536    97.38208
                    1 19  |   27.97178   53.76045     0.52   0.604    -78.27141     134.215
                    1 20  |  -23.61705   54.75836    -0.43   0.667    -131.8324    84.59825
                          |
         himvalue#company |
                    0  1  |          0  (empty)
                    0  2  |          0  (empty)
                    0  3  |          0  (empty)
                    0  4  |  -1.287127   59.33765    -0.02   0.983    -118.5522    115.9779
                    0  5  |          0  (omitted)
                    0  6  |  -12.31769   56.49739    -0.22   0.828    -123.9697    99.33434
                    0  7  |          0  (omitted)
                    0  8  |          0  (omitted)
                    0  9  |          0  (omitted)
                    0 10  |          0  (omitted)
                    1  1  |          0  (omitted)
                    1  2  |          0  (omitted)
                    1  3  |          0  (omitted)
                    1  4  |          0  (omitted)
                    1  5  |          0  (empty)
                    1  6  |          0  (omitted)
                    1  7  |          0  (empty)
                    1  8  |          0  (omitted)
                    1  9  |          0  (empty)
                    1 10  |          0  (empty)
                          |
                    _cons |   74.17678   31.76796     2.33   0.021     11.39589    136.9577
        ------------------+----------------------------------------------------------------
                  sigma_u |  133.05491
                  sigma_e |  58.116325
                      rho |  .83978518   (fraction of variance due to u_i)
        -----------------------------------------------------------------------------------
        F test that all u_i=0: F(9, 147) = 68.93                     Prob > F = 0.0000

        Comment


        • #5
          Thank you so much Andrew! Your help is greatly appreciated

          Comment

          Working...
          X