I came across a significant difference in computation time between the two lines -margins var1#var2- and -margins var2, at(r(levels)). I use age dummies instead of treating it as a continuous variable (-c.age-), as to plot the crude data.
The full code is the following:
Why is there such a big difference in computation time? Is any of the two 'wrong'? The resulting plots are identical.
The full code is the following:
HTML Code:
use https://www.stata-press.com/data/r18/nhanes2, clear timer clear timer on 1 logit highbp sex##age // estimates dummies, at() and margins with interactions is equivalent margins age#sex // does not work with continuous age (after specifying -c.-) (but -at() also works in this case) marginsplot, name(g2, replace) timer off 1 gr combine g1 g2 timer list 1 **can also compute age#sex using at(), but this is much slower, see comparison below** timer on 2 logit highbp sex##age // estimates dummies, at() and margins with interactions is equivalent levelsof age margins sex, at(age=(`r(levels)')) marginsplot, name(g3, replace) timer off 2 timer list 2 gr combine g2 g3
Comment