Announcement

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

  • Interacting binary variable with continuous variable

    Hi,
    I want to create a new variable as an interaction between 2 variables - EFindex (continuous variable) and Dem_Acemoglu_new5 (binary variable). I ran:

    gen frac_dem1 = c.EFindex##i.Dem_Acemoglu_new5

    and got the following error:

    invalid matrix stripe;
    c.EFindex##i.Dem_Acemoglu_new5
    r(198);

    Could someone please clarify? Thank you!

  • #2
    The ## operator expands to three variables, not one. It is as if you wrote:
    Code:
    gen frac_dem1 = c.EFindex i.Dem_Acemoglu_new5 c.EFindex#i.Dem_Acemoglu_new5
    The right hand side of an equation in the -gen- command must be an expression, not a series of unconnected variables.

    On top of that, the i.Dem_Acemoglu_new5 is itself an abbreviation for two variables: 0.Dem_Acemoglu_new5 and 1.Dem_Acemoglu_new5 (assuming that Dem_Acemoglu_new5 takes on the values 0 and 1).

    Now, it is not clear what you want and why you want it. If you want to do a regression that includes continuous variable EFindex and dichotomous variable Dem_Acemoglu_new5 and their interaction as explanatory variables, there is no need to create an interaction variable to do that. You can just issue a command like:
    Code:
    regression_command outcome_variable c.EFindex##i.Dem_Acemoglu_new5 and_perhaps_other_variables...
    and Stata will incorporates those two variables and their interaction, calculated "on the fly", when it runs that command. No need to clutter your data set with extra variables.

    Occasionally, but only occasionally, it is also useful to have a separate variable for an interaction. So, for example, if you want a variable that is 0 when Dem_Acemoglu_new5 is 0 and equals EFindex when Dem_Acemoglu_new5 is 1, you can get that with:
    Code:
    gen frac_dem1= c.EFindex#1.Dem_Acemoglu_new5 // N.B. #, not ##.
    But, let me reiterate, there is no need to create such a variable simply to use interactions in regressions. And if you do need to create such a variable for other reasons, resist the temptation to also use it as an interaction term in a regression, because, although it will work properly in the regression itself, it will definitely lead to erroneous results if you then try to apply -margins-, or any program that uses -margins-.
    Last edited by Clyde Schechter; 26 Aug 2023, 23:09.

    Comment


    • #3
      Clyde Schechter Thank you so much for your reply! I want only the interaction term to be included in the regression. Also, I want to instrument this potentially endogenous interaction term with 4 instruments. I ran the following:

      ivreghdfe lnGDPper lag1_lnGDPper lag2_lnGDPper lag3_lnGDPper lag4_lnGDPper lnGDP_trans (c.EFindex#1.Dem_Acemoglu_new5 = dem_iv1 cen_lat dem_iv2 distcr), cluster (country) first

      ivreghdfe lnGDPper lag1_lnGDPper lag2_lnGDPper lag3_lnGDPper lag4_lnGDPper lnGDP_trans (c.EFindex#i.Dem_Acemoglu_new5 = dem_iv1 cen_lat dem_iv2 distcr), cluster (country) first


      The first command where I prefixed Dem_Acemoglu_new5 with '1' produced significant results, whereas the second one prefixed with 'i' gave me insignificant results. So, I'm unsure which of these 2 regressions is providing a reliable answer to the question I'm interested in. Dem_Acemoglu_new5 = 1 if democracy and 0 if autocracy. I'm interested in democracy. So, I believe the first regression gives me the answer I want? Is that right?

      Thank you!

      Comment


      • #4
        I am not a user of -ivreghdfe-, nor do I have much experience with instrumental-variables approaches in general: they are little used in my field. In the context of any other estimation command that I am familiar with, I would say that the first command, the one with 1.Dem_Acmoglu_new5, is the correct one. But I don't want to stick my neck out on -ivreghdfe- given that I really don't know it.

        Comment


        • #5
          Clyde Schechter Thank you so much!

          Comment

          Working...
          X