Announcement

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

  • Margins command error (not found in list of covariates) for continuous variables interaction effects

    Hello, my name is Valentina and I am a PhD student.

    I am trying to conduct a post-hoc analysis on a significant interaction I found. The interaction is between power and closeness and their effect on anger:

    reg anger c.power##c.closeness

    I then followed Aiken & West (1991) and UCLA"s Stata help (https://stats.oarc.ucla.edu/stata/se...ions-stata/#s3), with following code and without mean-centering the variables:

    sum closeness
    return list
    global closea = round(r(mean) + r(sd), 0.1)
    global close = round(r(mean), 0.1)
    global closeb = round(r(mean) - r(sd), 0.1)
    display $closea
    display $closeb
    margins, dydx(power) at(closeness=($closea $close $closeb))


    This worked well. I then wanted to do exactly the same with mean-centered variables to avoid extrapolation. I thus created mean-centered variables:

    summarize closeness, meanonly
    gen centered_closeness = closeness - r(mean)
    summarize power, meanonly
    gen centered_power = power - r(mean)


    and then ran the same commands again:

    sum centered_closeness
    return list
    global centered_closea = round(r(mean) + r(sd), 0.1)
    global centered_close = round(r(mean), 0.1)
    global centered_closeb = round(r(mean) - r(sd), 0.1)
    display $centered_closea
    display $centered_closeb
    margins, dydx(centered_power) at(centered_closeness=($centered_closea $centered_close $centered_closeb))


    Now, I received an error message from Stata: centered_power not found in list of covariates or centered_closeness not found in list of covariates.

    I tried to fix the issue by reading similar error message posts but couldn"t find a solution, since I have only continuous variables.

    Please help! Thank you.

    Valentina

  • #2
    margins refers to the last estimates in memory. As the error message indicates, there is no estimation with the variables centered_power and centered_closeness. You need

    Code:
    reg anger c.centered_power##c.centered_closeness
    prior to the margins command.

    Comment


    • #3
      Thank you so much, Andrew!

      Comment

      Working...
      X