Announcement

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

  • Fixed effects panel analysis with interaction

    I am doing a fixed effects panel analysis, and I want to include an interaction term.
    Is it correct that when I add the interaction, I use the demeaned values (variable - mean of variable).

    So if I do the fixed effect regression without interaction term:
    dep var = indep var1 + indep var2 + control variables

    And when I add an interaction term:
    dep var = demeaned indep var1 + demeaned indep var2 + demeaned indep var1*demeaned indep var2 + control variables.




  • #2
    If you are using xtreg, fe, the command performs the demeaning for you. Therefore, you can enter interactions as you normally would in Stata using factor variable notation, and there is nothing more to do.

    Code:
    webuse grunfeld, clear
    xtset company year
    xtreg invest c.mvalue##c.kstock i.year, fe
    Res.:

    Code:
    . xtreg invest c.mvalue##c.kstock i.year, fe
    
    Fixed-effects (within) regression               Number of obs     =        200
    Group variable: company                         Number of groups  =         10
    
    R-squared:                                      Obs per group:
         Within  = 0.8714                                         min =         20
         Between = 0.8278                                         avg =       20.0
         Overall = 0.8211                                         max =         20
    
                                                    F(22, 168)        =      51.72
    corr(u_i, Xb) = 0.3976                          Prob > F          =     0.0000
    
    -----------------------------------------------------------------------------------
               invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    ------------------+----------------------------------------------------------------
               mvalue |   .0484422   .0131124     3.69   0.000     .0225558    .0743286
               kstock |   -.097855   .0501606    -1.95   0.053    -.1968814    .0011713
                      |
    c.mvalue#c.kstock |   .0000884   9.06e-06     9.75   0.000     .0000705    .0001063
                      |
                 year |
                1936  |   8.667003   19.18959     0.45   0.652    -29.21681    46.55082
                1937  |   10.28049   20.47135     0.50   0.616    -30.13375    50.69472
                1938  |   -5.38731   18.94361    -0.28   0.776    -42.78551    32.01089
                1939  |  -17.27588   19.70084    -0.88   0.382    -56.16898    21.61722
                1940  |   12.77391   19.95843     0.64   0.523    -26.62774    52.17555
                1941  |    40.7847   19.94917     2.04   0.042     1.401347    80.16806
                1942  |   37.33487   19.67586     1.90   0.059    -1.508929    76.17867
                1943  |   26.04217   20.16038     1.29   0.198    -13.75815    65.84249
                1944  |   29.63069   20.33981     1.46   0.147    -10.52385    69.78523
                1945  |   24.20958   20.83062     1.16   0.247    -16.91391    65.33308
                1946  |   53.21976   21.17733     2.51   0.013      11.4118    95.02773
                1947  |   51.76566   21.23089     2.44   0.016     9.851961    93.67937
                1948  |   59.53744   21.93594     2.71   0.007     16.23183    102.8431
                1949  |   39.20456   22.56621     1.74   0.084    -5.345315    83.75444
                1950  |   44.72188   23.10263     1.94   0.055    -.8869846    90.33075
                1951  |   64.29612   23.79396     2.70   0.008     17.32243    111.2698
                1952  |   75.70263   24.89758     3.04   0.003      26.5502    124.8551
                1953  |   79.39711   26.12458     3.04   0.003     27.82235    130.9719
                1954  |   68.76686   27.36828     2.51   0.013      14.7368    122.7969
                      |
                _cons |   41.98642   16.96277     2.48   0.014     8.498777    75.47407
    ------------------+----------------------------------------------------------------
              sigma_u |   95.63904
              sigma_e |  41.456004
                  rho |  .84182855   (fraction of variance due to u_i)
    -----------------------------------------------------------------------------------
    F test that all u_i=0: F(9, 168) = 70.77                     Prob > F = 0.0000
    
    .

    Comment


    • #3
      Thank you! I have a question regarding the interpretation of an interaction effect. How can I correctly interpret this? I use logged variables because I use variables of expenditures in million euros.
      Last edited by Floore Bursens; 22 Jan 2026, 02:44.

      Comment


      • #4
        Your question is not fully clear because it does not specify whether both the outcome and the independent variables are logged, or whether only the independent variable is logged. In addition, the nature of the interaction term is not stated (e.g., continuous--continuous or categorical--continuous). Assuming a log-log model with a continuous-continuous interaction, the interpretation of the interaction coefficient can be derived using calculus. Consider the log-log model:

        \[
        \ln Y
        =
        \beta_0
        + \beta_1 \ln X
        + \beta_2 \ln Z
        + \beta_3 \bigl( \ln X \cdot \ln Z \bigr)
        \]

        In log-log models, coefficients are elasticities. The elasticity of \(Y\) with respect to \(X\) is given by:
        \[
        \frac{\partial \ln Y}{\partial \ln X}
        =
        \beta_1 + \beta_3 \ln Z
        \]

        Taking the partial derivative of this expression with respect to \(\ln Z\) yields:
        \[
        \frac{\partial}{\partial \ln Z}
        \left(
        \frac{\partial \ln Y}{\partial \ln X}
        \right)
        =
        \frac{\partial}{\partial \ln Z}
        \left(
        \beta_1 + \beta_3 \ln Z
        \right)
        =
        \beta_3
        \]

        Therefore, the coefficient on the interaction term, \( \beta_3 \), measures how the elasticity of \(Y\) with respect to \(X\) changes when \(Z\) increases by 1%.

        Comment


        • #5
          .
          Last edited by Floore Bursens; 26 Jan 2026, 04:08.

          Comment


          • #6
            Thank you again!
            I have an additional question regarding my analysis. I want to research the impact of expenditures on social services on macro-outcomes. Is it better for the independent variables to use variables that explain expenditures in % of GDP or use variables that explain expenditures in euro (and than the log of these variables)? My dependent variable is for example number of people in poverty, employment rate, ...
            I find it difficult to analyse myself what is the best option and if it makes a difference.
            Last edited by Floore Bursens; 26 Jan 2026, 04:09.

            Comment


            • #7
              Floore:
              most depends on the "tribal jargon" of your research field (that differs from mine).
              Personally, and assuming that you go log-log, I would log "variables that explain expenditures in euro".
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment

              Working...
              X