meinequality
Stata command for inequality summary effects of nominal and ordinal independent variables
meinequality (Marginal Effects Inequality) is a companion package to Mize and Han's 2025 Sociological Science article "Inequality and total effect summary measures for nominal and ordinal variables."
meinequality calculates a ME inequality statistic for independent variables in a regression model. The command calculates weighted and/or unweighted ME inequalities.
Download meinequality
To download the meinequality command in Stata:
net install meinequality, from("https://tdmize.github.io/data/meinequality") replace
Help file
To read the help file (also available here):
help meinequality
Citation
Please cite the use of the meinequality command by citing the corresponding article:
Mize, Trenton D. and Bing Han. 2025. "Inequality and total effect summary measures for nominal and ordinal variables." Sociological Science. 12:115-157.
Basic syntax
meinequlaity can be used for a single model or to compare ME inequalities across two models.
For a single model, first fit the model and then call meinequality with a list of independent variables for which ME inequalities should be calculated.
regress ...
meinequality varlist
To compare across two models, first fit each individual model and store the estimates for each using est store. E.g.,
logit dv iv1 iv2, vce(robust)
est store basemod
logit dv iv1 iv2 med1 med2, vce(robust)
est store medmod
Note that meinequality in the two model case uses the robust variance estimator. Thus, to match its results we strongly recommend you include vce(robust) as an option on the individual models.
Then, use meinequality listing the independent variables you want ME inequalities calculated for and compared across models. Specify the two stored models( ) to compare.
meinequality varlist, models(basemod medmod)
If the two models are fit on separate samples—such as in the analysis of groups—the group option is required.
meinequality varlist, models(grp1mod grp2mod) group
Examples
This section shows how meinequality can be used in a variety of analyses. These examples are replications of those in Mize and Han 2025.
Ex 4.1 - Inequality as a summary measure
The first example summarizes the effect of a single nominal indepenent variable in a linear regression model.
use "https://tdmize.github.io/data/data/cda_gss", clear
keep if year == 2021
drop if missing(wages, race4)
reg wages i.race4 c.age i.woman
meinequality race4
Model (mod1) is:
regress wages i.race4 c.age i.woman
ME Inequality Estimates (N = 1714)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
race4 | 4.926 0.864 5.703 0.000
Racial-ethnic groups' wages differ by about $4.93 per hour, on average.
The default calculation for meinequality is a weighted ME inequality. Unweighted inequalities can be calculated using the unweighted option.
meinequality race4, unweighted
Model (mod1) is:
regress wages i.race4 c.age i.woman
ME Inequality Estimates (N = 1714)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
Unwgt. ME Inequality |
race4 | 5.788 1.042 5.558 0.000
Ex 4.2.b - Inequality in categorical models
This example uses a binary logit and calculates ME inequalities for multiple IVs.
use "https://tdmize.github.io/data/data/cda_gss", clear
keep if year == 2021
drop if missing(conserv, race4, woman, class, age)
logit conserv i.woman i.race4 i.class
meinequality woman race4 class
Model (mod1) is:
logit conserv i.woman i.race4 i.class
ME Inequality Estimates (N = 3608)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
ME Inequality |
woman | 0.070 0.016 4.466 0.000
race4 | 0.108 0.013 7.991 0.000
class | 0.012 0.017 0.701 0.484
Class has no overall effect on conservative identification. Racial-ethnic groups differ by about 10.8 percentage points on average, while men and women differ by 7.0 percentage points.
Ex 4.3.b - Comparing ME inequalities across models as in tests of mediation/attenuation
This example compares ME inequalities across two models fit on the same sample, such as in tests of mediation/attenuation.
use "https://tdmize.github.io/data/data/cda_hrs", clear
drop if missing(nagiSS, race, college, hatota, hitot)
Each model should first be fit and the estimates stored.
nbreg nagiSS i.race
est store basemod
nbreg nagiSS i.race i.college c.hatota c.hitot
est store medmod
With two models, specify the name of the stored models in the models( ) option of meinequality.
meinequality race, models(basemod medmod)
Model 1 (basemod) is:
nbreg nagiSS i.race, vce(robust)
Model 2 (medmod) is:
nbreg nagiSS i.race i.college c.hatota c.hitot, vce(robust)
ME Inequality Estimates (N_basemod = 18879 , N_medmod = 18879)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
race ME Ineq. |
Model 1 (basemod) | 0.383 0.050 7.700 0.000
Model 2 (medmod) | 0.217 0.048 4.501 0.000
Cross-Model Diff. | 0.166 0.035 4.785 0.000
The ME inequality estimate is 0.166 smaller in the model that includes the mediator than in the base model.
Ex 4.3.a - Comparing ME inequalities across models fit on different samples
This example compares ME inequalities in separate models fit on different samples.
use "https://tdmize.github.io/data/data/cda_gss", clear
drop if missing(spkhomo, reltrad, age, woman)
Each model should first be fit and the estimates stored.
logit spkhomo i.reltrad c.age i.woman if year < 1980, vce(robust)
est store premod
logit spkhomo i.reltrad c.age i.woman if year >= 2010, vce(robust)
est store postmod
With two models, specify the name of the stored models in the models( ) option of meinequality.
When different samples are used for each model—such as when different groups or time periods are compared—the group option must be specified.
meinequality reltrad, models(premod postmod) group unweighted
Model 1 (premod) is:
logit spkhomo i.reltrad c.age i.woman if year < 1980, vce(robust)
Model 2 (postmod) is:
logit spkhomo i.reltrad c.age i.woman if year >= 2010, vce(robust)
ME Inequality Estimates (N_premod = 5593 , N_postmod = 8226)
| Estimate Std. err. z P>|z|
-------------------------+-----------------------------------------------
reltrad Unwgt ME Ineq. |
Model 1 (premod) | 0.156 0.011 14.329 0.000
Model 2 (postmod) | 0.072 0.007 10.913 0.000
Cross-Model Diff. | 0.083 0.013 6.561 0.000
The ME inequality estimate is significantly larger in the first model (pre-1980) than in the second model (post-2010).