Technical Details: Different Output between Stata and ggeffects
Stata’s equivalent to the adjusted predictions produced by
ggeffects is the
margins-command. However, the
results are not always identical. For models from non-gaussian families,
point estimates for the adjusted predictions are identical, but the
confidence intervals differ.
Here is an explanation, why there is a difference. First, we fit a logistic regression model.
This is the code in Stata to produce an adjusted predictions plot.
The resulting image looks like this.
When we use ggeffects, the plot slighlty differs.
As we can see, the confidence intervals in the Stata plot are outside
the plausible range of
[0, 1], which means that the
predicted uncertainty from the Stata output has a probability higher
than 1 and lower than 0, while
confidence intervals within the possible range.
It seems like Stata returns incorrect confidence intervals.
Predictions and standard errors returned in Stata are on the
(transformed) response scale. Obviously, the confidence intervals are
then computed by
estimate +/- 1.96 * standard error, which
may lead to confidence intervals that are out of reasonable bounds
(e.g. above 1 or below 0 for predicted probabilities).
The transformed estimate (on the response scale) is always between 0 and 1, and the same is true for the transformed standard errors. However, adding or subtracting approx. 2 * transformed SE to the transformed estimate does no longer ensure that the confidence intervals are within the correct range.
The precise way to do the calculation is to calculate estimates, standard errors and confidence intervals on the (untransformed) scale of the linear predictor and then back-transform.