Announcement

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

  • Interaction term in a quadratic model

    My basic cross-sectional (countrywise) model is based on regress life_exp gdp_pc_ppp sq_gdp_pc_ppp
    Now, I have put each country into one of 5 regions (continents) and generated dummy variables for 4 of them (leaving one as base).
    Next, I need to add an interaction term in order to see whether the life_exp depends on gdp_pc_ppp in a different way in africa than others.
    A bit lost on how to introduce the interaction term in this situation...
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    So, unless you are working with a very old version of Stata, you are doing this the hard way. Factor-variable notation (-help fvvarlist-) in modern Stata makes this very simple. First, get rid of the sq_gdp_pc_ppp variable. You don't need it. And get rid of the four continent dummy variables: you only need your 5-level continent variable. Factor-variable notation takes care of those things as well. I'll assume your continent variable is just called continent and that Africa is coded as 5. Then it's just
    Code:
    regress life_exp 5.continent##c.gdp_pc_ppp##c.gdp_pc_ppp i(2/5).continent
    If you now wish to test the hypothesis that the life_exp gdp_pc_ppp relationship is different for Africa from other continents, that command would be:

    Code:
    testparm 5.continent#c.gdp_pc_ppp 5.content#c.gdp_pc_ppp#c.gdp_pc_ppp
    Added: I assume here that you also want to distinguish the levels of life_exp among the other four continents (though not the relationship of life_exp with gdp_pc_ppp.) If you do not want that, the i(2/5).continent term can be eliminated.

    Comment


    • #3
      To deconstruct your code and make sure I understand
      Code:
      5.continent##c.gdp_pc_ppp##c.gdp_pc_ppp i(2/5).continent
      Code:
      5.continent
      continent indicator has 5 levels
      Code:
      c.gdp_pc_ppp
      simply to say tread the gdp as continuous
      Code:
      5.continent##c.gdp_pc_ppp
      same as 5.continent c.gdp_pc_ppp 5.continent#c.gdp_pc_ppp
      where 5.continent#c.gdp_pc_ppp indicates a 2-way interaction
      Code:
      5.continent##c.gdp_pc_ppp##c.gdp_pc_ppp
      This stumps me a bit, to be honest...
      Thank you for your help!

      Stata SE/17.0, Windows 10 Enterprise

      Comment


      • #4
        You've got most of it right. But not all.

        The notation 5.continent is a specific reference to observations in which continent == 5. When Stata sees 5.continent it constructs a "virtual" indicator (dummy) variable corresponding to 1 for observations where continent == 5 and 0 for observations where continent == something other than 5, and missing value if continent itself is missing. Since I stipulated that I'm assuming that continent itself is coded with Africa = 5, 5.continent is an indicator variable for Africa.

        c.gdp_pc_ppp indeed says to treat gdp as continuous But it's not "simply" that. In the usage to which it is put here, as part of an interaction term, Stata treats variables involved in an interaction as discrete unless you specify that they are continuous. So that c. is crucial for getting it right here. Without it, Stata would wrongly treat it as discrete.

        As for 5.continent##c.gdp_c_ppp##c.gdp_pc_ppp, remember that # denotes interaction terms (and ## denotes interaction along with the constituents of the interaction) and remember that interaction terms are products. So, if we had c.gdp_c_ppp#c.gdp_c_ppp that would be a quadratic term in gdp_c_ppp--that is, it would represent gdp_c_ppp^2. The use of the double # notation says that we want not only the product of these three things, but all of the individual factors and all two-way products. So 5.continent##c.gdp_pc_ppp##c.gdp_pc_ppp expands to:

        Code:
        5.continent   c.gdp_pc_ppp   c.gdp_pc_ppp^2    5.continent*c.gdp_pc_ppp  5.continent*c.gdp_pc_ppp^2
        In other words, it is exactly everything you need to represent a quadratic in ggdp_pc_ppp and its interaction with 5.continent.

        Comment


        • #5
          Oh, cool. Thanks!

          So, for my simple quadratic regression, without any interactions, I could also do
          Code:
          regress life_exp c.gdp_pc_ppp##c.gdp_pc_ppp
          instead of
          Code:
          gen sq_gdp_pc_ppp = gdp_pc_ppp^2
          regress life_exp gdp_pc_ppp sq_gdp_pc_ppp
          ?
          Thank you for your help!

          Stata SE/17.0, Windows 10 Enterprise

          Comment


          • #6
            Oh, about
            Code:
            testparm 5.continent#c.gdp_pc_ppp 5.content#c.gdp_pc_ppp#c.gdp_pc_ppp
            How can I extract/use the F and p values?

            Would something like
            Code:
            `r(F)'
            and
            Code:
            `r(p)'
            work?
            Thank you for your help!

            Stata SE/17.0, Windows 10 Enterprise

            Comment


            • #7
              Yes. In general, if you are not sure where to find results from a command, run -return list- after the command it will show you what is saved where. Sometimes what you want isn't saved at all and you have to calculate it from things that are. But in this case, r(F) and r(p) are there after -testparm-.

              Comment

              Working...
              X