Announcement

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

  • Set base group for 2 variables when including interaction terms in a regression

    Dear all,

    I am currently running a regression in Stata that involves an interaction term between years and countries (this is a simplified regression because I am training myself in interaction terms). What I would like to do is set the base group of 2 variables for this regression, namely country and year. I want Base country=USA, and Base year= 2011. The code that I use to do this looks as follows:
    Code:
    fvset base 88 country // set USA  as base country, country dummy observation that is dropped
    fvset base 2011 year   // set 2011 as base year
    reg logp i.country#i.year,  baselevels
    When I run the regression however, it seems that the code only works for the case where year=2011. In every other year, the base country is not USA anymore. I test this by running the regression without the year interaction for specific years to confirm this. I confirm that in these cases another country is chosen as the base country. Therefore, my question is the following. Would anyone have a clue why my regression is not setting USA as base country for years other than 2011? I presume I have an error in my code, but I cannot find it. Any help would be greatly appreciated.

    Best,

    Satya

  • #2
    Well, your -reg- command is not really an interaction model: it includes an interaction term, but without the "main" effects. So in this context, country# year has only a single base level, which in your case would be the level where country == 88 and year = 2011. Everything else is represented.

    A true interaction model would be -reg logp i.country##i.year, baselevels-, and in that case 88 will be the base level for country, 2011 will be the base level for year, and the interaction terms will be all combinations of country and year except those where country == 88 OR year == 2011, which is what I interpret your post as saying you want.

    Comment


    • #3
      Hi Clyde,

      Thank you for your reply. Actually, what I would like to do is the following. I want to have base that is "USA, 2011". Thus, across countries, the base group will be USA, in every year. Across time, the base year will be 2011, for every country. For every year ≠ 2011 I want this to hold. This means that I would like an interaction between any country with the year 2013 to still have base country USA, and base year 2011. In a similar vein, I would interaction of USA with the year 2013 to have USA, 2011 as its base so that its coefficient in 2013 is not set to 0, because its base is in 2011. Is this possible? I figured it could be possible, because it is essentially doing a simultaneous interaction across both space and time. If this does not make sense and/or is not how interaction terms between variables work, my apologies. I will abandon the idea then.

      Best,

      Satya

      Comment


      • #4
        Yes, that is exactly what I suggested in #2.

        Comment


        • #5
          Hi Clyde,

          Thank you for your reply. When I run your code that you suggested, the interaction of each country that is not the U.S. with the year 2011 has a coefficient of zero. Here, I expected that the coefficient should differ from zero, because while 2011 is the base year, any country that is not USA is not the base country and therefore I expected that the interaction term of this country with the year 2011 should produce a coefficient different from zero. In addition, the coefficients for the interaction between the U.S. and year is zero for all years, and here again I expected that besides the interaction term between the U.S. and year=2011, the other country-year interactions for years other than 2011 should be different from zero because in these cases the year is different from the base group. In essence, I would want non-zero interaction terms for all combinations of country and year except those where country == 88 AND year == 2011 (if possible).

          Best,

          Satya

          Comment


          • #6
            Well, it doesn't seem to be possible using -fvset-: that's probably some kind of bug in Stata. But you can do it with the ib# notation.

            Code:
            reg logp ib88.country##ib2011.year

            Comment


            • #7
              Hi Clyde,

              Thank you for your response. I have tried this code, but unfortunately it delivers the exact same issue as mentioned in post #5. I was curious whether the code did work for you?

              Best,

              Satya

              Comment


              • #8
                I'm sorry in #6 I typed ## when I meant to type #. (I almost never use #, so ## is a strong habit that I'm often not even aware of typing.)

                Here's how it works:

                Code:
                . webuse grunfeld, clear
                
                .
                . regress kstock ib5.company#ib1950.year, baselevels
                
                      Source |       SS           df       MS      Number of obs   =       200
                -------------+----------------------------------   F(199, 0)       =         .
                       Model |  18042049.3       199  90663.5642   Prob > F        =         .
                    Residual |           0         0           .   R-squared       =    1.0000
                -------------+----------------------------------   Adj R-squared   =         .
                       Total |  18042049.3       199  90663.5642   Root MSE        =         0
                
                ------------------------------------------------------------------------------
                      kstock |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                company#year |
                     1 1935  |     -659.5          .        .       .            .           .
                     1 1936  |     -609.7          .        .       .            .           .
                     1 1937  |     -505.4          .        .       .            .           .
                     1 1938  |     -453.1          .        .       .            .           .
                     1 1939  |     -458.9          .        .       .            .           .
                     1 1940  |     -455.1          .        .       .            .           .
                     1 1941  |     -407.1          .        .       .            .           .
                     1 1942  |     -358.6          .        .       .            .           .
                     1 1943  |     -398.2          .        .       .            .           .
                     1 1944  |     -460.7          .        .       .            .           .
                     1 1945  |     -397.3          .        .       .            .           .
                     1 1946  |     -260.1          .        .       .            .           .
                     1 1947  |   99.20001          .        .       .            .           .
                     1 1948  |      260.1          .        .       .            .           .
                     1 1949  |      357.8          .        .       .            .           .
                     1 1950  |      436.7          .        .       .            .           .
                     1 1951  |      545.4          .        .       .            .           .
                     1 1952  |      768.2          .        .       .            .           .
                     1 1953  |       1115          .        .       .            .           .
                     1 1954  |       1564          .        .       .            .           .
                     2 1935  |     -608.5          .        .       .            .           .
                     2 1936  |     -611.8          .        .       .            .           .
                     2 1937  |     -544.2          .        .       .            .           .
                     2 1938  |     -402.1          .        .       .            .           .
                     2 1939  |     -349.6          .        .       .            .           .
                     2 1940  |     -408.1          .        .       .            .           .
                     2 1941  |     -400.9          .        .       .            .           .
                     2 1942  |     -363.6          .        .       .            .           .
                     2 1943  |     -360.5          .        .       .            .           .
                     2 1944  |     -383.2          .        .       .            .           .
                     2 1945  |     -448.5          .        .       .            .           .
                     2 1946  |     -529.7          .        .       .            .           .
                     2 1947  |     -397.5          .        .       .            .           .
                     2 1948  |     -355.4          .        .       .            .           .
                     2 1949  |     -311.2          .        .       .            .           .
                     2 1950  |     -304.5          .        .       .            .           .
                     2 1951  |     -320.2          .        .       .            .           .
                     2 1952  |     -218.1          .        .       .            .           .
                     2 1953  |  -38.70001          .        .       .            .           .
                     2 1954  |   7.400024          .        .       .            .           .
                     3 1935  |     -564.5          .        .       .            .           .
                     3 1936  |     -557.9          .        .       .            .           .
                     3 1937  |     -544.3          .        .       .            .           .
                     3 1938  |     -506.1          .        .       .            .           .
                     3 1939  |     -489.7          .        .       .            .           .
                     3 1940  |     -475.7          .        .       .            .           .
                     3 1941  |     -441.4          .        .       .            .           .
                     3 1942  |     -374.5          .        .       .            .           .
                     3 1943  |     -342.4          .        .       .            .           .
                     3 1944  |       -341          .        .       .            .           .
                     3 1945  |     -342.7          .        .       .            .           .
                     3 1946  |     -316.3          .        .       .            .           .
                     3 1947  |     -205.9          .        .       .            .           .
                     3 1948  |     -118.9          .        .       .            .           .
                     3 1949  |        -44          .        .       .            .           .
                     3 1950  |  -14.89996          .        .       .            .           .
                     3 1951  |          9          .        .       .            .           .
                     3 1952  |   63.79999          .        .       .            .           .
                     3 1953  |        138          .        .       .            .           .
                     3 1954  |      226.6          .        .       .            .           .
                     4 1935  |     -651.8          .        .       .            .           .
                     4 1936  |     -652.1          .        .       .            .           .
                     4 1937  |     -627.6          .        .       .            .           .
                     4 1938  |     -610.5          .        .       .            .           .
                     4 1939  |       -598          .        .       .            .           .
                     4 1940  |     -595.2          .        .       .            .           .
                     4 1941  |     -587.1          .        .       .            .           .
                     4 1942  |     -590.9          .        .       .            .           .
                     4 1943  |     -595.2          .        .       .            .           .
                     4 1944  |     -601.8          .        .       .            .           .
                     4 1945  |     -607.7          .        .       .            .           .
                     4 1946  |     -577.5          .        .       .            .           .
                     4 1947  |     -565.5          .        .       .            .           .
                     4 1948  |     -552.1          .        .       .            .           .
                     4 1949  |     -514.9          .        .       .            .           .
                     4 1950  |     -499.1          .        .       .            .           .
                     4 1951  |     -458.8          .        .       .            .           .
                     4 1952  |     -371.7          .        .       .            .           .
                     4 1953  |     -316.2          .        .       .            .           .
                     4 1954  |     -247.4          .        .       .            .           .
                     5 1935  |     -479.1          .        .       .            .           .
                     5 1936  |     -458.3          .        .       .            .           .
                     5 1937  |     -426.3          .        .       .            .           .
                     5 1938  |     -370.6          .        .       .            .           .
                     5 1939  |     -339.2          .        .       .            .           .
                     5 1940  |     -318.3          .        .       .            .           .
                     5 1941  |     -294.6          .        .       .            .           .
                     5 1942  |     -255.1          .        .       .            .           .
                     5 1943  |     -235.7          .        .       .            .           .
                     5 1944  |     -192.3          .        .       .            .           .
                     5 1945  |     -163.1          .        .       .            .           .
                     5 1946  |     -127.7          .        .       .            .           .
                     5 1947  |  -95.70001          .        .       .            .           .
                     5 1948  |        -67          .        .       .            .           .
                     5 1949  |  -30.89996          .        .       .            .           .
                     5 1950  |          0  (base)
                     5 1951  |   21.60004          .        .       .            .           .
                     5 1952  |         67          .        .       .            .           .
                     5 1953  |        112          .        .       .            .           .
                     5 1954  |      142.6          .        .       .            .           .
                     6 1935  |     -655.8          .        .       .            .           .
                     6 1936  |     -646.5          .        .       .            .           .
                     6 1937  |     -634.6          .        .       .            .           .
                     6 1938  |     -623.1          .        .       .            .           .
                     6 1939  |     -613.7          .        .       .            .           .
                     6 1940  |     -609.8          .        .       .            .           .
                     6 1941  |     -600.8          .        .       .            .           .
                     6 1942  |     -581.8          .        .       .            .           .
                     6 1943  |     -567.9          .        .       .            .           .
                     6 1944  |     -569.7          .        .       .            .           .
                     6 1945  |       -570          .        .       .            .           .
                     6 1946  |     -568.1          .        .       .            .           .
                     6 1947  |     -550.9          .        .       .            .           .
                     6 1948  |     -534.9          .        .       .            .           .
                     6 1949  |       -513          .        .       .            .           .
                     6 1950  |     -497.9          .        .       .            .           .
                     6 1951  |     -485.1          .        .       .            .           .
                     6 1952  |     -462.3          .        .       .            .           .
                     6 1953  |     -450.8          .        .       .            .           .
                     6 1954  |     -423.6          .        .       .            .           .
                     7 1935  |     -562.1          .        .       .            .           .
                     7 1936  |     -537.3          .        .       .            .           .
                     7 1937  |     -519.9          .        .       .            .           .
                     7 1938  |     -497.2          .        .       .            .           .
                     7 1939  |     -467.5          .        .       .            .           .
                     7 1940  |     -439.4          .        .       .            .           .
                     7 1941  |     -410.2          .        .       .            .           .
                     7 1942  |       -386          .        .       .            .           .
                     7 1943  |       -362          .        .       .            .           .
                     7 1944  |     -344.1          .        .       .            .           .
                     7 1945  |     -326.1          .        .       .            .           .
                     7 1946  |     -311.1          .        .       .            .           .
                     7 1947  |     -288.7          .        .       .            .           .
                     7 1948  |     -272.9          .        .       .            .           .
                     7 1949  |     -255.6          .        .       .            .           .
                     7 1950  |     -232.8          .        .       .            .           .
                     7 1951  |     -211.7          .        .       .            .           .
                     7 1952  |     -195.4          .        .       .            .           .
                     7 1953  |     -176.1          .        .       .            .           .
                     7 1954  |       -151          .        .       .            .           .
                     8 1935  |     -660.5          .        .       .            .           .
                     8 1936  |     -661.5          .        .       .            .           .
                     8 1937  |     -654.9          .        .       .            .           .
                     8 1938  |     -644.2          .        .       .            .           .
                     8 1939  |     -638.8          .        .       .            .           .
                     8 1940  |     -635.8          .        .       .            .           .
                     8 1941  |     -626.1          .        .       .            .           .
                     8 1942  |     -601.5          .        .       .            .           .
                     8 1943  |     -577.9          .        .       .            .           .
                     8 1944  |     -571.1          .        .       .            .           .
                     8 1945  |     -569.9          .        .       .            .           .
                     8 1946  |     -576.3          .        .       .            .           .
                     8 1947  |     -551.2          .        .       .            .           .
                     8 1948  |     -531.7          .        .       .            .           .
                     8 1949  |     -520.5          .        .       .            .           .
                     8 1950  |     -525.6          .        .       .            .           .
                     8 1951  |     -532.6          .        .       .            .           .
                     8 1952  |     -516.8          .        .       .            .           .
                     8 1953  |     -487.5          .        .       .            .           .
                     8 1954  |     -448.8          .        .       .            .           .
                     9 1935  |     -500.3          .        .       .            .           .
                     9 1936  |     -488.3          .        .       .            .           .
                     9 1937  |     -479.3          .        .       .            .           .
                     9 1938  |     -464.3          .        .       .            .           .
                     9 1939  |     -454.3          .        .       .            .           .
                     9 1940  |     -439.3          .        .       .            .           .
                     9 1941  |     -428.3          .        .       .            .           .
                     9 1942  |     -414.3          .        .       .            .           .
                     9 1943  |     -388.3          .        .       .            .           .
                     9 1944  |     -380.3          .        .       .            .           .
                     9 1945  |     -346.3          .        .       .            .           .
                     9 1946  |     -360.3          .        .       .            .           .
                     9 1947  |     -329.3          .        .       .            .           .
                     9 1948  |     -303.3          .        .       .            .           .
                     9 1949  |     -292.3          .        .       .            .           .
                     9 1950  |     -286.3          .        .       .            .           .
                     9 1951  |     -271.3          .        .       .            .           .
                     9 1952  |     -248.3          .        .       .            .           .
                     9 1953  |     -219.3          .        .       .            .           .
                     9 1954  |     -194.3          .        .       .            .           .
                    10 1935  |     -657.8          .        .       .            .           .
                    10 1936  |    -657.59          .        .       .            .           .
                    10 1937  |    -657.73          .        .       .            .           .
                    10 1938  |    -657.74          .        .       .            .           .
                    10 1939  |    -657.92          .        .       .            .           .
                    10 1940  |    -658.09          .        .       .            .           .
                    10 1941  |    -658.18          .        .       .            .           .
                    10 1942  |    -658.47          .        .       .            .           .
                    10 1943  |    -658.72          .        .       .            .           .
                    10 1944  |    -658.89          .        .       .            .           .
                    10 1945  |    -658.99          .        .       .            .           .
                    10 1946  |    -659.07          .        .       .            .           .
                    10 1947  |     -658.4          .        .       .            .           .
                    10 1948  |    -656.92          .        .       .            .           .
                    10 1949  |    -654.91          .        .       .            .           .
                    10 1950  |    -653.56          .        .       .            .           .
                    10 1951  |    -653.23          .        .       .            .           .
                    10 1952  |    -652.37          .        .       .            .           .
                    10 1953  |    -650.62          .        .       .            .           .
                    10 1954  |    -647.97          .        .       .            .           .
                             |
                       _cons |      662.3          .        .       .            .           .
                ------------------------------------------------------------------------------
                I'm using version 16.1. Maybe you're using an older version?

                Comment


                • #9
                  Hi Clyde,

                  Thank you for your reply. I am using Stata 16.0. I run the code you have provided, but I get the same result now again that led to my post #1. I confirm this because if I for example do the regression for the year 2012, (and then only include country without the interaction with year), I get coefficients which are the same as the ones for the interaction between country and year=2012. But in the single regression my base country is not the U.S., it is a different country. So I am afraid this does not work either. I am starting to think what I am trying to do does not make sense, and I feel it is a bit cumbersome for you to help me on this matter, so please feel free to let me know if this is the case.

                  Best,

                  Satya

                  Comment


                  • #10
                    Well, I would update to version 16.1 (-update all-, or have your system administrator do that if you do not have administrative privileges on your computer). Then try again--conceivably it's a version specific issue. But I'd be surprised if that behavior changed between 16.0 and 16.1. I can't help but think that somehow you are doing things differently from what I am recommending: as you can see, it definitely works for me.

                    And what you are asking to do is a reasonable thing--it does make sense. At this point I'm at a loss as to why you cannot get it to work using ib88.country#ib2011.year.

                    Added: One last minute thought. Remove the fvset commands from your code and do your regression with
                    ib88.country#ib2011.year.

                    Comment


                    • #11
                      Hi Clyde,

                      Thank you for your reply. I have managed to update Stata and dropped the fvset commands, and it seems to work now. Thank you for all your help for this question.

                      Best,

                      Satya

                      Comment

                      Working...
                      X