Announcement

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

  • Interaction between dummies variables in a linear reg mode

    I'm trying to determinate if years of residence have an effect in BMI, so I in order to compare my first model (only for foreign people), I want to create a model for local people + foreign people. I want to interact a dummie call foreign that indicates 0 for local and 1 for foreign. The interaction consist of a variable call "year" with the local people (the years is a way to indicate how many years they have been residing supposing that they havent moved abroad), and the foreign one with a variable call "years of residence".
    Until now I did this:
    gen local = (1-foreign)
    reg BMI foreign#c.years_of_residence local#c.year

    But I'm failing. Any advise?
    thanks

  • #2
    Well, you don't say in what way you are "failing." I can imagine several ways this could go wrong, depending on what the data look like (which you don't show).

    As you have provided so little information, the best I can offer you is a generic comment. I take it that you are trying to estimate the effect of years of residence on BMI separately among local and foreign people, and perhaps contrast those. To do this, you should have a single years of residence variable that applies to both groups and contains the appropriate values for them. Let's call that variable yor. Then you need a single 0/1 variable distinguishing local and foreign: let's just call that foreign. Then you would -reg BMI i.foreign##c.yor-. The variable yor is probably going to be a hybrid of your two variables years_of_residence and year. Something like this: -gen yor = cond(foreign, years_of_residence, year)-.

    For more concrete advice, if needed, do post back showing example data, and also show the exact code you ran (maybe it's what you showed above) and also the complete output, including any messages you got from Stata. Do remember that the best way to show example data is with the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Hi Clyde, thanks for the speed in replying. I will try to be more precise.
      Variables:
      year: show how old each individual is
      yor: show how many years a foreign individual have been residing in Spain
      foreign: give us 1 if the individual is foreign and 0 if he is spanish.
      BMI:
      I want to see if the residence have any effect in the BMI, so I consdered the residence for spanish people as the years.

      My code:
      gen spanish = (1-foreign)
      reg BMI foreign#c.yor local#c.year

      But due to of collinearity they only show me the effect for foreign, both in age and yor.
      Thanks

      Comment


      • #4
        Please re-read the second paragraph of my response in #2 which gives a better approach. In particular, you need to use a single variable for the years that covers both the foreign and local people, and you need a single variable foreign, coded 0 for locals and 1 for foreign. There is no use for a separate variable called local. (Also, even if you needed such a variable, you should never name a variable "local" in Stata because -local- is a Stata command name.)

        Try the model I outlined in #2. If you do not know how to interpret its results, post back showing the output you got and I will help you.

        Comment

        Working...
        X