Hello,

I am using Stata 17 to estimate the impact of variable X on a probability P.

I run a regression of the log odds ratio on the variable X.
I would like to get the predicted probability for different years.

I cannot obtain similar confidence intervals when I use predictnl or margin.

Code:
gen log_odds_ratio = ln(P/(1-P))
reg log_odds_ratio X
margins if year == 2010 , expression(exp(predict(xb))/(1+exp(predict(xb))))
which differs from the confidence intervals computed by hand using predictnl:

Code:
gen log_odds_ratio = ln(P/(1-P))
reg log_odds_ratio X
predictnl pred_prob=exp(predict(xb))/(1+exp(predict(xb))) , var(variance)
egen tot_var = total(variance) if year == 2010
count if year == 2010
gen standard_error= 1/r(N)*sqrt(tot_var)
These two give very different standard errors.
I'm confused since the standard error of the average probability should be 1/n sqrt(sum(Variances)).
Any idea what I might doing wrong?

Thanks a lot,

Best,
Nicholas