Announcement

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

  • Storing names of interaction terms in logistic regression to be used with testparm in a loop

    Hi,
    I am trying to run testparm for multiple interaction coefficients (for a categorical variable with multiple levels) after logistic regression in a loop. After testparm I need to put the names of the interaction coefficients generated but I am not finding a way of accessing them through postestimation commands; from the Stata documentation they do not seem to be stored. Do you know if there is a way of accessing the names of the interaction coefficients generated so I can easily use them in a loop without copying and paste each of them?

    Best

  • #2
    If you follow the logistic regression with -logistic, coeflegend-, Stata will replay the results table, but instead of standard errors, confidence intervals and test statistics, it will show you the names of the coefficients it has created.

    You don't say what kind of loop you will be doing this under. If the loop is just over different outcome variables, the coefficient names will be the same for all of the regressions, so you can just run one of them ahead of time and use those names. If you are looping over different sets of explanatory/predictor variables, then, evidently, things will change from one iteration to the next. Nevertheless, if you first just run one of the logistic regressions with the -coeflegend- observation before you write the loop, you should be able to see the pattern of how Stata creates the coefficient names from the variables and then develop code to feed the ones you want into -testparm-.

    Finally, don't forget that if you have discrete variables x and y and want test all of the interaction coefficients, -testparm- supports factor variable notation, so you don't need to know all the details of the coefficient names:
    Code:
    testparm i.x#i.y // JUST THE INTERACTION TERMS
    testparm i.x##i.y // INTERACTION TERMS AND "MAIN" EFFECTS
    Added: When I responded to this, I did not realize that this is one of three identical posts. A much fuller discussion, with more specifics about what O.P. actually wants to do is at https://www.statalist.org/forums/for...parm-in-a-loop.
    Last edited by Clyde Schechter; 29 Sep 2023, 11:15.

    Comment

    Working...
    X