My goal is to compare the AMEs between two subpopulations of my sample in a logit model. However, there are two different moments in my analysis I can think of on where I can divide my sample into those two subpopulations, leading to very different results.
In the example below y would be my binary dependent variable; a and b are covariates and subpop is a dummy, dividing my sample into those two subgroups.

Possibility 1:
forval i=0/1 {
logit y a b if subpop==`i'
margins, dydx(a b)
}
Possibility 2:
forval i=0/1 {
logit y a b i.subpop
margins if rich==`i', dydx(a b)
}
I know for the latter code, the over() and the subpop() command can be used as well, which does not change the results with my data. What does change the magnitude of the effects of a and b on y tremendously is whether I divide my population before the logit command is executed or after the logit command is executed (i.e. before the margins command is executed). So my question is, which option is the “correct” one or rather how do the two options differ in the interpretation of results?
Thanks a lot in advance!