Announcement

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

  • Global macro with adjusted logistic regression with factor variables

    I want to use global macro in crude and adjusted logistic regression.

    webuse bpwide
    generate bp = (bp_after > bp_before)
    tab bp

    global expVar = "sex agegrp"

    foreach x of global expVar { // crude
    logistic bp i.`x'
    }


    logistic bp bp_before i.$expVar // adjusted

    As sex and agegrp are factor variables I need i. in front of these variables. But in adjusted logistic, I can only have i. in front of the first variable in the result.
    I can re-do this by creating a new global macro as
    global expVar = "i.sex i.agegrp"

    But I do not want to have multiple macros for the same list of variables.
    Nick Cox ​​​​​​Can you please help?

  • #2
    The output of help factor variables tells us how to use factor variable notation, and specifically tells us it can be applied to groups of variables by enclosing the list of variable names within parentheses following the factor variable operator. So perhaps the following will do what you want.
    Code:
    logistic bp bp_before i.($expVar)

    Comment


    • #3
      Thank you so much William Lisowski . My bad, I tried curly "{ }" brackets but didn't think of using the normal ones "( )" and was looking for a solution on global macros rather than factor variables.
      Your suggestion worked perfectly.
      Thank you

      Comment

      Working...
      X