Announcement

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

  • interaction term

    Hello,

    I created an interaction term of two binary variables and added it to the model, using two different ways.

    1. logit freq_move i.ace1_2 NbhdSupp_2021_d ace1_2#NbhdSupp_2021_d, nolog

    I used "#" to create the interaction term.

    The results are below:
    freq_move Coefficient Std. err. z P>z [95% conf. interval]
    1.ace1_2 1.037921 .0342157 30.33 0.000 .970859 1.104982
    NbhdSupp_2021_d -.2266996 .051156 -4.43 0.000 -.3269636 -.1264357
    ace1_2#NbhdSupp_2021_d
    0 1 -.0978577 .056232 -1.74 0.082 -.2080703 .0123549
    1 1 0 (omitted)
    _cons -1.941679 .01769 -109.76 0.000 -1.976351 -1.907007

    It seems the values "1" are omitted. So, I tried to create the interaction term manually like this: gen interaction2 = ace1_2 * NbhdSupp_2021_d

    2. logit freq_move i.ace1_2 NbhdSupp_2021_d interaction2, nolog

    Here are the results:
    freq_move Coefficient Std. err. z P>z [95% conf. interval]
    1.ace1_2 1.037921 .0342157 30.33 0.000 .970859 1.104982
    NbhdSupp_2021_d -.3245573 .0233473 -13.90 0.000 -.3703172 -.2787974
    interaction2 .0978577 .056232 1.74 0.082 -.0123549 .2080703
    _cons -1.941679 .01769 -109.76 0.000 -1.976351 -1.907007
    The sign of the interaction term is changed from negative to positive.

    I think it is because the number of value "1" is small. (3.49%)
    interaction
    2 Freq. Percent Cum.
    0 86,978 96.51 96.51
    1 3,147 3.49 100.00
    Total 90,125 100.00

    In this case, how I interpret this result? Should I use a positive coefficient?

    Thanks!

  • #2
    Something is wrong here. You should not be seeing that 1 1 (omitted) in the first. It suggests that your data do not include the observations needed to support an interaction model. Run
    Code:
    tab ace1_2 NbhdSupp_2021_d
    I suspect you will find that the ace1_2 = 1, NbhdSupp_2021_d = 1 will show a zero. If I am right about that, then you cannot do an interaction model here because of the absence of complete data for it.

    If I am wrong, then the problem may have arisen because of the way you wrote your original model. You first show NbhdSupp_2021_d by itself, without a prefix, which leads Stata to think it is continuous. Then you also included it in an interaction term, again without a prefix, which leads Stata to think it is discrete. This sort of thing can get Stata very confused and produce inaccurate results, although I would more expect to see the problem pop up with -margins- than -logit-. Anyway, a better way to do this is actually:
    Code:
    logit freq_move i.ace1_2##i.NbhdSupp_2021_d // N.B. ##, not #
    margins ace1_2#NbhdSupp_2021_d // N.B. #, not ##
    margins ace1_2, dydx(NbhdSupp_2021_d)
    margins NbhdSupp_2021_d, dydx(ace1_2)
    But I emphasize that if that cell in the table I recommended you create above is, in fact, 0, no amount of recoding can fix it: you would need better data to proceed. You must have observations in all four cells of that table in order to fit an interaction model properly.

    Comment


    • #3
      Hello Clyde,

      Thank you for your suggestion. I followed what you suggested.

      Code:
       
       tab ace1_2 NbhdSupp_2021_d
      NbhdSupp_2 ace1_2
      021_d 0 1 Total
      0 29,675 5,812 35,487
      1 51,491 3,147 54,638
      Total 81,166 8,959 90,125

      It seems there are no problems of two variables. And then I ran this code below:
      Code:
       
       logit freq_move i.ace1_2##i.NbhdSupp_2021_d // N.B. ##, not #
      It works!
      freq_move Coefficient Std. err. z P>z [95% conf. interval]
      1.ace1_2 1.037921 .0342157 30.33 0.000 .970859 1.104982
      1.NbhdSupp_2021_d -.3245573 .0233473 -13.90 0.000 -.3703172 -.2787974
      ace1_2#NbhdSupp_2021_d
      1 1 .0978577 .056232 1.74 0.082 -.0123549 .2080703
      _cons -1.941679 .01769 -109.76 0.000 -1.976351 -1.907007

      I found why 1 1 was omitted. I did not put "i" before NbhdSupp_2021_d.

      When I ran this code again, I got the same results.

      Code:
      logit freq_move i.ace1_2 i.NbhdSupp_2021_d ace1_2#NbhdSupp_2021_d, nolog
      Thank you so much for your help, Clyde.

      Comment

      Working...
      X