Announcement

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

  • Interaction among variables included in a global

    I have a list of variables grouped into two globals

    global x ="x1 x2 x3 "
    global z="z1 z2"

    I need to make the regression of y x1 x2 x3 z1 z2 x1*z1 x1*z2 x2*z2 x2*z1 x3*z1 x3*z2 (so all variables included in globals and their interactiosn)

    I prove:

    regress y ${x}##${z}

    but there is an error and STATA says: "# invalid name"

    Any help would be much appreciated. Unlike the example, I have more than five explanatory variables.

    Ana

  • #2
    Code:
    sysuse auto, clear
    
    local x mpg headroom trunk
    local y weight length
    
    regress price c.(`x')##c.(`y')
    You can also do this with global macros if you have some good reason for that choice.

    Note the c. prefixes: variables that appear in interactions are, by default, treated as discrete. So on the assumption that your intent is that the variables be continuous, I have added the c. prefixes. If you intend them to be discrete, then just omit the c. prefixes--but be sure to retain the parentheses surrounding the dereferenced macros.

    It is OK for the x's to be discrete and the y's continuous or vice versa. However, you cannot do this using a mix of continuous and discrete variables within x or within y.
    Last edited by Clyde Schechter; 16 Jun 2025, 08:54.

    Comment


    • #3
      Thanks a lot. It works

      Comment

      Working...
      X