Options
Every meinequality option, with an example of each
meinequality varlist [if] [in] [, options]Each variable in varlist must have been entered in the model(s) with the i. prefix. The examples use Stata’s nlsw88 data.
sysuse nlsw88, clear(NLSW, 1988 extract)
drop if missing(union, race, age, married, collgrad, south, wage)(368 observations deleted)
.
quietly logit union i.race c.age i.married, vce(robust)
estimates store basemod
quietly logit union i.race c.age i.married i.collgrad c.wage, vce(robust)
estimates store medmodweighted, unweighted, all
A weighted ME inequality (the default) weights each pairwise comparison by the share of the sample in the two levels compared, corrected so the weights sum to one: wab = (pa + pb)/(L - 1). unweighted gives every pair the same weight, 1 / [L(L-1)/2]. all reports both; for a binary variable the two are equal and only the weighted one is shown. The proportions are taken over the model’s estimation sample.
meinequality race, models(medmod)ME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race | 0.081 0.028 2.912 0.004
meinequality race, models(medmod) unweightedME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
Unwgt. ME Inequality |
race | 0.064 0.016 3.993 0.000
meinequality race, models(medmod) allME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race | 0.081 0.028 2.912 0.004
-------------------------+-----------------------------------------------
Unwgt. ME Inequality |
race | 0.064 0.016 3.993 0.000
atmeans – covariates at their means
By default the other variables stay at their observed values and the predictions are averaged over the sample; atmeans sets them to their means.
meinequality race, models(medmod) atmeansME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race | 0.082 0.028 2.894 0.004
models() – one model or two
models() is optional for one model (the estimates in memory are used) and required for two. With two models, the ME inequality is reported for each and their difference is tested; the two must be the same estimation command (use mecompare for a pair of different commands). vce(robust) is strongly recommended on both models.
meinequality race, models(basemod medmod)ME Inequality Estimates (N_basemod = 1878 , N_medmod = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Model 1 (basemod) | 0.081 0.050 1.608 0.108
Model 2 (medmod) | 0.081 0.028 2.912 0.004
Cross-Model Diff. | 0.000 0.028 0.007 0.994
groups and groupnames() – models fit on distinct samples
groups says the two models were fit on non-overlapping samples. A weighted ME inequality then weights each model by the level proportions of its own sample, so the comparison reflects differences in the marginal effects and in composition; unweighted isolates the marginal effects. groupnames() labels the two rows (no spaces within a name; long names are shortened only as needed to fit the table). group(varname), the syntax of earlier versions, is also accepted; varname must take one value in each model’s sample and a different value in each model.
quietly logit union i.race c.age if married == 0, vce(robust)
estimates store notmar
quietly logit union i.race c.age if married == 1, vce(robust)
estimates store marry.
meinequality race, models(notmar marry) groups groupnames(Unmarried Married)ME Inequality Estimates (N_notmar = 656 , N_marry = 1222)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Model 1 (Unmarried) | 0.055 0.032 1.706 0.088
Model 2 (Married) | 0.097 0.061 1.603 0.109
Cross-Model Diff. | -0.042 0.069 -0.619 0.536
meinequality race, models(notmar marry) groups unweightedME Inequality Estimates (N_notmar = 656 , N_marry = 1222)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race Unwgt ME Ineq. |
Model 1 (notmar) | 0.048 0.024 1.995 0.046
Model 2 (marry) | 0.092 0.077 1.189 0.234
Cross-Model Diff. | -0.043 0.081 -0.537 0.592
by() and over() – within levels of another variable
by(varname) computes the ME inequality at each level of a binary or nominal covariate as a counterfactual (the whole sample set to that level); over(varname) computes it within each observed subgroup. The variable must be in the model with the i. prefix.
With either option the table also holds a Diff. row for each pair of levels – the ME inequality at the first level minus that at the second, with its standard error and test, which is the test of whether the inequality differs across the groups (a test of interaction); with a multi-category outcome there is one per outcome. Neither option may name one of the focal variables; mecompare handles that case.
meinequality race, models(medmod) by(collgrad)ME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race(Not college grad) | 0.079 0.027 2.896 0.004
race(College grad) | 0.089 0.031 2.915 0.004
race Diff. | -0.010 0.006 -1.834 0.067
Diff. = Not college grad - College grad
meinequality race, models(medmod) over(collgrad)ME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race(Not college grad) | 0.076 0.026 2.884 0.004
race(College grad) | 0.094 0.032 2.963 0.003
race Diff. | -0.018 0.007 -2.718 0.007
Diff. = Not college grad - College grad
Several variables at once
meinequality race married collgrad, models(medmod)ME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race | 0.081 0.028 2.912 0.004
married | 0.021 0.021 1.021 0.307
collgrad | 0.054 0.026 2.118 0.034
Multi-category outcomes
With an ordinal or nominal outcome, one ME inequality is reported per outcome category. totalme sums them into a single Total ME inequality.
xtile wage3 = wage, nq(3)
quietly mlogit wage3 i.race c.age i.collgrad, vce(robust)
meinequality raceME Inequality Estimates (N = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Pr(Outcome 1) | 0.090 0.049 1.859 0.063
Pr(Outcome 2) | 0.054 0.027 2.045 0.041
Pr(Outcome 3) | 0.072 0.046 1.571 0.116
Display options: ci, level(), decimals(), labwidth(), title()
meinequality race, models(basemod medmod) ci level(90) decimals(4) title("ME inequality of race")ME inequality of race (N_basemod = 1878 , N_medmod = 1878)
| Estimate Std. err. z P>|z| 90% LL 90% UL
-------------------------+-----------------------------------------------------------------------
race ME Ineq. |
Model 1 (basemod) | 0.0810 0.0504 1.6076 0.1079 -0.0019 0.1638
Model 2 (medmod) | 0.0808 0.0277 2.9116 0.0036 0.0351 0.1264
Cross-Model Diff. | 0.0002 0.0282 0.0070 0.9945 -0.0461 0.0465
commands and details
commands prints the command of each model and the margins command (and with two models the suest2 command) that produced the estimates; details prints their output.
meinequality race, models(basemod medmod) commandsModel 1 (basemod) is:
logit union i.race c.age i.married
Model 2 (medmod) is:
logit union i.race c.age i.married i.collgrad c.wage
suest2 model is:
suest2 basemod medmod
margins specification is:
margins race , post
ME Inequality Estimates (N_basemod = 1878 , N_medmod = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Model 1 (basemod) | 0.081 0.050 1.608 0.108
Model 2 (medmod) | 0.081 0.028 2.912 0.004
Cross-Model Diff. | 0.000 0.028 0.007 0.994
Weights, svy, and mi
Weights, the svy: prefix, and mi estimate go on the stored models, not on meinequality; with two models both must carry the same. Multilevel models need a higher-level weight as well (melogit y x [pw=w2] || group:, pweight(w1)) or, better, the svy: prefix. See the help file.
Under mi, one model may be fit with plain mi estimate: or with mi estimate, post:, which return the same pooled statistic; to compare two models, fit both with mi estimate, post:. mi estimate requires the user-written mimrgns package.
Saved results
meinequality is r-class. r(wem1#), r(wem2#), and r(wed#) hold the weighted ME inequality for model 1, model 2, and their difference for the #th variable in varlist; r(uwem1#), r(uwem2#), r(uwed#) the unweighted versions; with a multi-category outcome _o# is appended for the outcome, and with by() or over() _level, with the Diff. rows appending _dlevel1_level2 instead (e.g. r(wem11_d0_1)). r(table) holds the displayed table (estimate, SE, z, p, and the two confidence limits) and r(se_missing) counts quantities whose standard error could not be computed. The margins results are stored as meineq_margins and, with two models, the combined system as meineq_suest2.
meinequality race, models(basemod medmod)ME Inequality Estimates (N_basemod = 1878 , N_medmod = 1878)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Model 1 (basemod) | 0.081 0.050 1.608 0.108
Model 2 (medmod) | 0.081 0.028 2.912 0.004
Cross-Model Diff. | 0.000 0.028 0.007 0.994
return listscalars:
r(se_missing) = 0
r(wed1) = .0001957941094682
r(wem21) = .0807741893221536
r(wem11) = .0809699834316218
r(n_vars) = 1
r(n_mods) = 2
matrices:
r(table) : 3 x 6
Bootstrap standard errors
When the standard errors are unavailable, e.g. after convergence trouble, wrap the command in a small program and use bootstrap:
capture program drop boot_mei
program define boot_mei, rclass
reg wage i.race c.age i.married
meinequality race
return scalar w_mei = r(wem11)
end
bootstrap w_mei=r(w_mei), reps(1000): boot_mei