I have a mixed effects logistic regression model:
Variable x1 is coded 0/1. I create the predicted probabilities for both values of x1:
Then I obtain the predicted probabilities for each observation included in the model:
To make out-of-sample predictions, I load my second dataset with the same variables:
Now I can get the predicted probabilities for each observation in the new dataset:
My question is: How do I get what the 'margins' command created for the original dataset, but for the new dataset?
When I try this:
Stata tells me this:
I also tried to recreate original output based on 'margins' by calculating the mean of probhat for each value of x1, hoping that I could use the same approach to get out-of-sample subgroup predicted probabilities:
However, the mean based on this code is different from the mean for x1==0 based on the 'margins' command.
Code:
quietly melogit y i.x1 i.x2 || x3:
Code:
margins x1
Code:
predict probhat if e(sample) summarize probhat
Code:
use "C:\file path\newdata.dta", clear
Code:
predict probhat_new summarize probhat_new
When I try this:
Code:
margins anypriors
Code:
e(sample) does not identify the estimation sample
Code:
summarize probhat if x1== 0, meanonly scalar mean_probhat_x1_0 = r(mean) gen mean_probhat=. replace mean_probhat = mean_probhat_x1_0 if x1== 0 summarize mean_probhat
Comment