7.6 Count, ordinal, and nominal models

Count models

  • Data: Health and Retirement Study* (older adults)
  • Outcome: Count of functional limitations

We need to understand difficulties people may have with various activities because of a health or physical problem. Please tell me whether you have any difficulty doing each of the everyday activities that I read to you. Exclude any difficulties that you expect to last less than three months.

  • Walking several blocks
  • Walking one block
  • Walking across a room
  • Climbing several flights of stairs without resting
  • Climbing one flight of stairs without resting
  • Sitting for about two hours
  • Getting up from a chair after sitting for long periods
  • Stooping, kneeling, or crouching
  • Pulling or pushing large objects like a living room chair

*I’m pooling the waves and clustering the SEs on participant ID to account for repeated observations. For more serious analyses, I recommend a longitudinal/panel model

use "https://tdmize.github.io/data/data/hrs_si", clear
(Health and Retirement Study 1992-2022 - Cleaned for MCAP SI)
*Data management
drop if missing(funclim, age, race4cat, wealth_w, collegeB, marstatB, woman, h
hidpn)
(22,650 observations deleted)
*7.6.a - distribution of outcome functional limiations count
hist funclim, percent xlab(0(1)9) ///
    title("[7.6.a] Distribution of count of functional limitations (HRS; older
 adults)")
(bin=54, start=0, width=.16666667)

[7.6.a] Histogram of the count of functional limitations (0 to 9) among older adults in the HRS: about 34% report 0, about 16% report 1, 11% report 2, and the percentages keep falling to about 2% reporting 9.

library(haven)           # import Stata data and labels
library(dplyr)           # data manipulation
library(ggplot2)         # graphs
library(sjmisc)          # frequency tables
library(marginaleffects) # predictions and marginal effects
library(cleanplots)      # graph scheme
cleanplots_defaults()

hrs <- read_dta("https://tdmize.github.io/data/data/hrs_si.dta")

# Data management
hrs <- hrs[c("funclim", "age", "race4cat", "wealth_w", "collegeB", "marstatB", "woman",
  "hhidpn")]
hrs <- hrs[complete.cases(hrs), ]

# 7.6.a - distribution of outcome functional limiations count
ggplot(hrs, aes(x = funclim)) +
  geom_bar(aes(y = after_stat(100 * count / sum(count))), width = .3, fill = "gray60") +
  scale_x_continuous(breaks = 0:9) +
  labs(title = "[7.6.a] Distribution of count of functional limitations (HRS; older adults)",
    x = "Functional limitations, count 0-9", y = "Percent")

[7.6.a] Histogram of the count of functional limitations (0 to 9) among older adults in the HRS: about 34% report 0, about 16% report 1, 11% report 2, and the percentages keep falling to about 2% reporting 9.

HRS functional limitations example

  • Focal IV: Age
    • Mean = 67
  • Moderating IV: College degree (=1) or not (=0)
  • Controls: Gender, marital status, race-ethnicity

RQ: How does aging affect physical health? Does aging have a different effect for those with and without college degrees?

RQ: Will the physical health gap between those with and without college degrees be the same across different ages? How will it change at different ages?

*7.6.b - distribution of focal IV age
hist age, freq width(1) xlab(25(10)105) ylab(0(1000)10000, format(%5.0f)) ///
    title("[7.6.b] Distribution of age (HRS; older adults)") xtitle("Age")
(bin=91, start=18, width=1)

[7.6.b] Histogram of age (in one-year bins) among older adults in the HRS: few respondents are under 50; the frequency jumps to about 9,000 per year of age in the mid-50s to about 60, then declines steadily through the 70s and 80s, with few respondents past 95.

# 7.6.b - distribution of focal IV age
ggplot(hrs, aes(x = age)) +
  geom_histogram(binwidth = 1, fill = "gray60", color = "black") +
  scale_x_continuous(breaks = seq(25, 105, 10)) +
  scale_y_continuous(breaks = seq(0, 10000, 1000)) +
  labs(title = "[7.6.b] Distribution of age (HRS; older adults)", x = "Age", y = "Frequency")

[7.6.b] Histogram of age (in one-year bins) among older adults in the HRS: few respondents are under 50; the frequency jumps to about 9,000 per year of age in the mid-50s to about 60, then declines steadily through the 70s and 80s, with few respondents past 95.

Interaction effects on the rate

// Negative binomial count model for functional limitations.
qui nbreg funclim c.age##i.collegeB i.race4cat i.marstatB i.woman, cluster(hhi
dpn)
est store flmod
# Treat binary/nominal variables as factors
hrs <- hrs |>
  mutate(across(c(collegeB, race4cat, marstatB, woman), as_factor))

# Negative binomial count model for functional limitations
flmod <- MASS::glm.nb(funclim ~ age * collegeB + race4cat + marstatB + woman, data = hrs)

Ignore the coefficient on the interaction (product) term. Count models are nonlinear and coefficients are in a different metric than the predictions. Graph predictions and test interaction in MEs.

  • Graph the predictions for the count/rate
*7.6.c - Graph predicted rate/count of functional limitations
est restore flmod
(results flmod are active now)
qui margins collegeB, at(age=(45(2)95))
marginsplot, ///
    recastci(rline) ciopt(lpat(dash) col(*.5)) plotop(msym(none) lwid(*1.5)) /
//
    title("[7.6.c] Predicted number of functional limitations by age and colle
ge", size(*1.1)) ///
    ylab(0(1)5) ytitle("# of functional limitations") ///
    xtitle("Age") legend(order(3 "No degree" 4 "College"))
Variables that uniquely identify margins: age collegeB

[7.6.c] Predicted number of functional limitations by age (45 to 95) for those with and without a college degree, with confidence intervals. Both rise with age at an increasing rate: without a degree from about 1.8 at 45 to about 4.2 at 95; with a degree from about 0.75 at 45 to about 4.3 at 95. The college advantage is large at younger ages and disappears by the mid-90s.

# 7.6.c - Graph predicted rate/count of functional limitations
# (one age at a time, which needs much less memory with 270,000+ observations)
pr <- bind_rows(lapply(seq(45, 95, 2), function(a) {
  avg_predictions(flmod, by = c("age", "collegeB"), vcov = ~hhidpn,
    newdata = datagrid(age = a, collegeB = unique, grid_type = "counterfactual"))
}))

ggplot(pr, aes(x = age, y = estimate, color = collegeB, fill = collegeB)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(linewidth = 1) +
  scale_color_discrete(labels = c("No degree", "College")) +
  scale_fill_discrete(labels = c("No degree", "College")) +
  scale_y_continuous(breaks = 0:5, limits = c(0, 5)) +
  labs(title = "[7.6.c] Predicted number of functional limitations by age and college",
    x = "Age", y = "# of functional limitations", color = NULL, fill = NULL)

[7.6.c] Predicted number of functional limitations by age (45 to 95) for those with and without a college degree, with confidence intervals. Both rise with age at an increasing rate: without a degree from about 1.8 at 45 to about 4.2 at 95; with a degree from about 0.75 at 45 to about 4.3 at 95. The college advantage is large at younger ages and disappears by the mid-90s.

*AME of age for those w and w/o college degrees
mecompare age, by(collegeB) amount(10) model(flmod)
Predicting: Predicted number of events
Marginal effects (N_flmod=273547)

                                 |  ME #   Estimate  Robust SE      P>|z|
---------------------------------+---------------------------------------
age + 10 (centered)              |                                       
                   no bachelor's |     1      0.461      0.010      0.000
            bachelor's or higher |     2      0.614      0.018      0.000
# Changes in continuous IVs centered on the observed values, like mecompare
options(marginaleffects_contrast_direction = "center")

# AME of age for those w and w/o college degrees
mes <- avg_comparisons(flmod, variables = list(age = 10), by = "collegeB",
  vcov = ~hhidpn, newdata = datagrid(collegeB = unique, grid_type = "counterfactual"))
mes

             collegeB Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
 no bachelor's           0.461    0.00984 46.8   <0.001   Inf 0.442   0.48
 bachelor's or higher    0.614    0.01840 33.4   <0.001 808.4 0.578   0.65

Term: age
Type: response
Comparison: +10

Aging 10 years predicts a 0.46 increase in the number of functional limitations for someone without a college degree. For someone with a college degree, the same 10-year increase in age predicts a 0.61 increase.

metest 2 - 1
                                 |  estimate         se     pvalue 
---------------------------------+--------------------------------
 age_collegeB_1 - age_collegeB_0 |     0.153      0.020      0.000 
hypotheses(mes, hypothesis = "b2 - b1 = 0")

 Hypothesis Estimate Std. Error    z Pr(>|z|)    S 2.5 % 97.5 %
    b2-b1=0    0.153     0.0205 7.47   <0.001 43.6 0.113  0.193

On average, aging has a significantly larger effect on the number of functional limitations for someone with a college degree than for someone without (p < .001).

  • Given the substantial nonlinearities we see in the graph, good to report interaction at different ages and not only the average effect (above)
    • I’ve picked 3 theoretical ideal types of ages 45, 65, 85

With mecompare, use the start() option to specify conditional values of a focal IV

With avg_comparisons, in the newdata = datagrid()

*2nd diffs for age * college, at three ideal types of age
mecompare age, by(collegeB) amount(10) start(age=(45 65 85)) model(flmod)
Predicting: Predicted number of events
Marginal effects (N_flmod=273547)

                                 |  ME #   Estimate  Robust SE      P>|z|
---------------------------------+---------------------------------------
age + 10 (centered)              |                                       
             no bachelor's at 45 |     1      0.307      0.004      0.000
             no bachelor's at 65 |     2      0.437      0.009      0.000
             no bachelor's at 85 |     3      0.622      0.017      0.000
      bachelor's or higher at 45 |     4      0.257      0.003      0.000
      bachelor's or higher at 65 |     5      0.527      0.013      0.000
      bachelor's or higher at 85 |     6      1.080      0.045      0.000
qui metest, clear
qui metest 1 - 4, add rowname("at age 45")
qui metest 2 - 5, add rowname("at age 65")
qui metest 3 - 6, add rowname("at age 85")
metest, title("2nd diff. of effect of age for those w and w/o college degrees"
)
2nd diff. of effect of age for those w and w/o college degrees

                                 |  estimate         se     pvalue 
---------------------------------+--------------------------------
                       at age 45 |     0.050      0.005      0.000 
                       at age 65 |    -0.090      0.015      0.000 
                       at age 85 |    -0.459      0.047      0.000 
# 2nd diffs for age * college, at three ideal types of age
mes <- avg_comparisons(flmod, variables = list(age = 10), by = c("collegeB", "age"),
  vcov = ~hhidpn, newdata = datagrid(collegeB = unique, age = c(45, 65, 85),
    grid_type = "counterfactual"))
mes

             collegeB age Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
 no bachelor's         45    0.307    0.00389 79.1   <0.001   Inf 0.300  0.315
 no bachelor's         65    0.437    0.00871 50.2   <0.001   Inf 0.420  0.454
 no bachelor's         85    0.622    0.01705 36.5   <0.001 964.2 0.588  0.655
 bachelor's or higher  45    0.257    0.00333 77.4   <0.001   Inf 0.251  0.264
 bachelor's or higher  65    0.527    0.01286 41.0   <0.001   Inf 0.502  0.552
 bachelor's or higher  85    1.080    0.04532 23.8   <0.001 414.5 0.991  1.169

Term: age
Type: response
Comparison: +10
hypotheses(mes, hypothesis = ~ revpairwise | age)

 age  Hypothesis Estimate Std. Error     z Pr(>|z|)    S   2.5 %  97.5 %
  45 (b1) - (b4)   0.0502    0.00506  9.92   <0.001 74.7  0.0403  0.0601
  65 (b2) - (b5)  -0.0900    0.01512 -5.95   <0.001 28.5 -0.1196 -0.0603
  85 (b3) - (b6)  -0.4585    0.04750 -9.65   <0.001 70.8 -0.5516 -0.3654

Those without college degrees acquire more functional limitations much earlier in life than those with college degrees. But by older ages, the groups converge.

For individuals in their 40s, aging is associated with a faster increase in functional limitations for someone without a college degree. However, for someone in their 60s, those with college degrees experience a larger increase in functional limitations. By their 80s, the rate is much stronger for someone with a college degree.

*7.6.d - Other side of interaction: effect of college, at different ages
est restore flmod
(results flmod are active now)
qui margins, dydx(college) at(age=(45(2)95))
marginsplot, yline(0) ///
    recastci(rline) ciopt(lpat(dash) col(black*.5)) ///
    plotop(msym(none) lcol(black) lwid(*1.5)) ///
    xlab(45(10)95) ylab(-1.5(.25).5) xtitle("Age") ///
    ytitle("ME of college (vs not)") ///
    title("[7.6.d] Marginal effect of having a college degree, across ages", s
ize(*1.1)) ///
    note("Negative effects mean those with college degrees have fewer function
al limitations", span)
Variables that uniquely identify margins: age

[7.6.d] Marginal effect of having a college degree on the number of functional limitations across ages 45 to 95, with confidence intervals and a line at zero. The effect is about -1.05 from age 45 to the mid-60s, then shrinks toward zero at older ages, crossing zero in the early 90s and ending slightly above zero at 95.

# 7.6.d - Other side of interaction: effect of college, at different ages
mes <- bind_rows(lapply(seq(45, 95, 2), function(a) {
  avg_comparisons(flmod, variables = "collegeB", by = "age", vcov = ~hhidpn,
    newdata = datagrid(age = a, grid_type = "counterfactual"))
}))

ggplot(mes, aes(x = age, y = estimate)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2) +
  geom_line(linewidth = 1) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  scale_x_continuous(breaks = seq(45, 95, 10)) +
  scale_y_continuous(breaks = seq(-1.5, .5, .25), limits = c(-1.5, .5)) +
  labs(title = "[7.6.d] Marginal effect of having a college degree, across ages",
    caption = "Negative effects mean those with college degrees have fewer functional limitations",
    x = "Age", y = "ME of college (vs not)")

[7.6.d] Marginal effect of having a college degree on the number of functional limitations across ages 45 to 95, with confidence intervals and a line at zero. The effect is about -1.05 from age 45 to the mid-60s, then shrinks toward zero at older ages, crossing zero in the early 90s and ending slightly above zero at 95.

*MEs of college, at empirical ideal types of age.
** Moderating continuous IV values go in covariates() option of mecompare
tabstat age, stat(p5 p50 p95)
    Variable |        p5       p50       p95
-------------+------------------------------
         age |        51        65        86
--------------------------------------------
# MEs of college, at empirical ideal types of age
quantile(hrs$age, c(.05, .5, .95))
 5% 50% 95% 
 51  65  86 

Empirical ideal types at 5th, 50th, and 95th percentiles

mecompare college, covariates(age=(51 65 86)) model(flmod)
Predicting: Predicted number of events
Marginal effects (N_flmod=273547)

                                 |  ME #   Estimate  Robust SE      P>|z|
---------------------------------+---------------------------------------
collegeB                         |                                       
     bachelor's - no bachelo     |                                       
                          age=51 |     1     -1.055      0.027      0.000
                          age=65 |     2     -1.019      0.025      0.000
                          age=86 |     3     -0.486      0.063      0.000
mes <- avg_comparisons(flmod, variables = "collegeB", by = "age", vcov = ~hhidpn,
  newdata = datagrid(age = c(51, 65, 86), grid_type = "counterfactual"))
mes

 age Estimate Std. Error      z Pr(>|z|)    S 2.5 % 97.5 %
  51   -1.055     0.0273 -38.65   <0.001  Inf -1.11 -1.001
  65   -1.019     0.0251 -40.58   <0.001  Inf -1.07 -0.970
  86   -0.486     0.0633  -7.67   <0.001 45.7 -0.61 -0.362

Term: collegeB
Type: response
Comparison: bachelor's or higher - no bachelor's

There is a significant education gap, with those with college degrees reporting fewer functional limitations, from the 5th to 95th percentile of age (age 51 to 86). However, as Figure # shows, the gap becomes non-significant by the mid 90s.

*Compare all MEs using pwcompare option of metest
metest 1 2 3, pwcompare rownames("age 51" "age 65" "age 86")
                                 |  estimate         se     pvalue 
---------------------------------+--------------------------------
                age 65 vs age 51 |     0.035      0.014      0.012 
                age 86 vs age 51 |     0.569      0.073      0.000 
                age 86 vs age 65 |     0.534      0.060      0.000 
hypotheses(mes, hypothesis = ~ pairwise)

  Hypothesis Estimate Std. Error    z Pr(>|z|)    S   2.5 % 97.5 %
 (b2) - (b1)   0.0353     0.0142 2.49   0.0127  6.3 0.00754 0.0631
 (b3) - (b1)   0.5689     0.0741 7.67   <0.001 45.8 0.42361 0.7142
 (b3) - (b2)   0.5336     0.0609 8.76   <0.001 58.8 0.41418 0.6530

The pwcompare option of metest and the ~ pairwise option of hypotheses will provide all tests of 2nd differences

The education gap shrinks at older ages. It is somewhat smaller at the median age (65) than at younger ages in the sample (51). It is over half a functional limitation smaller at the oldest ages (86), compared to at younger ages.

Ordinal and nominal models

  • With multi-outcome models, you can:
    • Test for interaction across each outcome category separately

RQ: Does parenthood have a different effect on “excellent” health for the married and the unmarried? On “good” health, etc.

  • Or, aggregate up to total effects across each outcome category, for the effect on the DV as a holistic construct

RQ: Does parenthood have a different effect on health for the married and the unmarried?

  • Or both

GSS self-rated health example

  • Data: GSS 2000 - 2021
  • DV: Self-rated health
use "https://tdmize.github.io/data/data/cda_gss", clear
(cda_gss.dta |  GSS 1972-2021 CDA - Categorical Data Analysis | date created 202
> 3)
**only keep var of interest
drop if missing(healthR, married, parent, woman, race4, age)
(17,923 observations deleted)
drop if year < 2000 | year > 2021
(29,261 observations deleted)
fre healthR
healthR -- Self-rated health
-----------------------------------------------------------------
                    |      Freq.    Percent      Valid       Cum.
--------------------+--------------------------------------------
Valid   1 Poor      |       1167       5.39       5.39       5.39
        2 Fair      |       4310      19.90      19.90      25.28
        3 Good      |      10569      48.79      48.79      74.07
        4 Excellent |       5616      25.93      25.93     100.00
        Total       |      21662     100.00     100.00           
-----------------------------------------------------------------
gss <- read_dta("https://tdmize.github.io/data/data/cda_gss.dta")

# only keep var of interest
gss <- gss[c("healthR", "married", "parent", "woman", "race4", "age", "year")]
gss <- gss[complete.cases(gss), ] |>
  filter(year >= 2000, year <= 2021)

frq(gss, healthR)
Self-rated health (healthR) <numeric> 
# total N=21662 valid N=21662 mean=2.95 sd=0.82

Value |     Label |     N | Raw % | Valid % | Cum. %
----------------------------------------------------
    1 |      Poor |  1167 |  5.39 |    5.39 |   5.39
    2 |      Fair |  4310 | 19.90 |   19.90 |  25.28
    3 |      Good | 10569 | 48.79 |   48.79 |  74.07
    4 | Excellent |  5616 | 25.93 |   25.93 | 100.00
 <NA> |      <NA> |     0 |  0.00 |    <NA> |   <NA>
  • Focal IV: Parent (=1) or not (=0)
  • Moderating IV: Married (=1) or not (=0)
  • Controls: Age, gender, race-ethnicity
  • Model: Using a multinomial logit model, as an ordinal model fails the Brant test, with meaningful differences in conclusions
    • Procedure for testing interactions is identical in nominal and ordinal models

Interaction across each outcome category

*Fit nominal model w/ interaction
qui mlogit healthR i.married##i.parent i.woman i.race4 c.age
est store hmod
# Treat binary/nominal variables as factors
gss <- gss |>
  mutate(across(c(healthR, married, parent, woman, race4), as_factor)) |>
  droplevels()

# Fit nominal model w/ interaction
hlthmod <- nnet::multinom(healthR ~ married * parent + woman + race4 + age, data = gss,
  trace = FALSE)
  • Plot predictions for each outcome category, and at each combination of married and parent
    • Here, 4 * (2*2) = 16
*7.6.e - Plot predictions at combos of married and parent, for each outcome
qui margins married if parent == 0, post
est store pr_par0
est restore hmod
(results hmod are active now)
qui margins married if parent == 1, post
est store pr_par1
coefplot (pr_par0, label("No Children")) (pr_par1, label("Parent")), ///
    xtitle("Pr(Self-Rated Health)") xlab(0(.1).6) ///
    ylab(1 `" "Pr(Poor)" "Unmarried" "' 2 `" "Pr(Poor)" "Married" "'  ///
        3 `" "Pr(Fair)" "Unmarried" "' 4 `" "Pr(Fair)" "Married" "'  ///
        5 `" "Pr(Good)" "Unmarried" "' 6 `" "Pr(Good)" "Married" "'  ///
        7 `" "Pr(Excellent)" "Unmarried" "' 8 `" "Pr(Excellent)" "Married" "')
 ///
    title("[7.6.e] Probability of self-rated health category, by marital and p
arental status") ///
    name(pr_health, replace)

[7.6.e] Dot plot of the predicted probability of each self-rated health category (poor, fair, good, excellent) for unmarried and married respondents, with and without children. Poor health is about .03 to .08, fair about .14 to .24, good about .47 to .50, and excellent about .20 to .33. Unmarried parents have higher probabilities of poor and fair health and a lower probability of excellent health than unmarried non-parents; among the married the parent and non-parent dots are closer together.

# 7.6.e - Plot predictions at combos of married and parent, for each outcome
pr <- avg_predictions(hlthmod, by = c("married", "parent", "group"),
  newdata = datagrid(married = unique, grid_type = "counterfactual")) |>
  mutate(row = factor(paste0("Pr(", group, ")\n", married),
    levels = paste0("Pr(", rep(levels(gss$healthR), each = 2), ")\n",
      levels(gss$married))))

ggplot(pr, aes(x = estimate, y = row, color = parent)) +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high),
    position = position_dodge(.4)) +
  scale_y_discrete(limits = rev) +
  scale_x_continuous(breaks = seq(0, .6, .1), limits = c(0, .6)) +
  labs(title = "[7.6.e] Probability of self-rated health category, by marital and parental status",
    x = "Pr(Self-Rated Health)", y = NULL, color = NULL)

[7.6.e] Dot plot of the predicted probability of each self-rated health category (poor, fair, good, excellent) for unmarried and married respondents, with and without children. Poor health is about .03 to .08, fair about .14 to .24, good about .47 to .50, and excellent about .20 to .33. Unmarried parents have higher probabilities of poor and fair health and a lower probability of excellent health than unmarried non-parents; among the married the parent and non-parent dots are closer together.

*7.6.f - Plot MEs of parental status
est restore hmod
(results hmod are active now)
qui margins married, dydx(parent) post
coefplot, xlab(-.1(.05).1) xline(0) xtitle("ME(Parental Status)") ///
    mcol(black) ciopt(col(black)) ///
    ylab(1 `" "Pr(Poor)" "Unmarried" "' 2 `" "Pr(Poor)" "Married" "'  ///
        3 `" "Pr(Fair)" "Unmarried" "' 4 `" "Pr(Fair)" "Married" "'  ///
        5 `" "Pr(Good)" "Unmarried" "' 6 `" "Pr(Good)" "Married" "'  ///
        7 `" "Pr(Excellent)" "Unmarried" "' 8 `" "Pr(Excellent)" "Married" "')
 ///
    title("", span) name(mes_health, replace)
*Plot 2nd diffs for married X parent
est restore hmod
(results hmod are active now)
margins r.married, dydx(parent) post
Contrasts of average marginal effects                   Number of obs = 21,662
Model VCE: OIM

dy/dx wrt: 1.parent

1._predict: Pr(healthR==Poor), predict(pr outcome(1))
2._predict: Pr(healthR==Fair), predict(pr outcome(2))
3._predict: Pr(healthR==Good), predict(pr outcome(3))
4._predict: Pr(healthR==Excellent), predict(pr outcome(4))

---------------------------------------------------------------
                            |         df        chi2     P>chi2
----------------------------+----------------------------------
0b.parent                   |
           married@_predict |
(Married vs Not Married) 1  |  (omitted)
(Married vs Not Married) 2  |  (omitted)
(Married vs Not Married) 3  |  (omitted)
(Married vs Not Married) 4  |  (omitted)
                     Joint  |  (omitted)
----------------------------+----------------------------------
1.parent                    |
           married@_predict |
(Married vs Not Married) 1  |          1        8.07     0.0045
(Married vs Not Married) 2  |          1        0.09     0.7619
(Married vs Not Married) 3  |          1        1.20     0.2735
(Married vs Not Married) 4  |          1        8.79     0.0030
                     Joint  |          3       14.93     0.0019
---------------------------------------------------------------

-----------------------------------------------------------------------------
                            |   Contrast Delta-method
                            |      dy/dx   std. err.     [95% conf. interval]
----------------------------+------------------------------------------------
0.parent                    |  (base outcome)
----------------------------+------------------------------------------------
1.parent                    |
           married@_predict |
(Married vs Not Married) 1  |     -0.022      0.008        -0.037      -0.007
(Married vs Not Married) 2  |     -0.004      0.013        -0.030       0.022
(Married vs Not Married) 3  |     -0.019      0.017        -0.053       0.015
(Married vs Not Married) 4  |      0.045      0.015         0.015       0.074
-----------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.
matrix sec_ds = (-0.022, -0.037, -0.007 \ ///
                 -0.004, -0.030,  0.022 \ ///
                 -0.019, -0.053,  0.015 \ ///
                  0.045,  0.015,  0.074)
mat rownames sec_ds = Poor Fair Good Excellent
mat colnames sec_ds = SecDiff ll95 ul95
*7.6.g - 2nd differences
coefplot (matrix(sec_ds[,1]), ci((sec_ds[,2] sec_ds[,3]))), ///
    mcol(gs8) ciopt(col(gs8)) ///
    xline(0) xlab(-.1(.05).1) xtitle("2nd Differences (Married * Parent)") ///
    ylab(1 "Pr(Poor)" 2 "Pr(Fair)" 3 "Pr(Good)" 4 "Pr(Excellent)") ///
    title("") name(sec_ds, replace)
*7.6.h - Combine MEs and 2nd diff plot
graph combine mes_health sec_ds, ysize(4) xsize(8) scale(1.1) ///
    title("[7.6.h] Marginal effects of parental status (left), and 2nd differe
nces") ///
    subtitle("2nd difference is difference in size of parent gap, across marit
al statuses")

[7.6.h] Two panels with a line at zero. Left: marginal effects of parental status on each self-rated health category for the unmarried and the married; for the unmarried, parenthood raises the probabilities of poor, fair, and good health by about .02 each and lowers the probability of excellent health by about .06; for the married all four effects are near zero. Right: the second differences (married minus unmarried) are about -.022 for poor, -.004 for fair, -.019 for good, and .045 for excellent; the confidence intervals for poor and excellent exclude zero.

# 7.6.f - MEs of parental status
mes <- avg_comparisons(hlthmod, variables = "parent", by = c("group", "married"),
  newdata = datagrid(married = unique, grid_type = "counterfactual"))

# 2nd diffs for married X parent
sec_ds <- hypotheses(mes, hypothesis = ~ pairwise | group)

# 7.6.h - Combine MEs and 2nd diff plot
panels <- c("Marginal effects of parental status", "2nd Differences (Married * Parent)")
both <- bind_rows(
  mes |> mutate(panel = panels[1], row = paste0("Pr(", group, ")\n", married)),
  sec_ds |> mutate(panel = panels[2], row = paste0("Pr(", group, ")"))) |>
  mutate(panel = factor(panel, levels = panels),
    row = factor(row, levels = rev(c(paste0("Pr(", rep(levels(gss$healthR), each = 2), ")\n",
      levels(gss$married)), paste0("Pr(", levels(gss$healthR), ")")))))

ggplot(both, aes(x = estimate, y = row)) +
  geom_vline(xintercept = 0) +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high)) +
  facet_wrap(~ panel, scales = "free_y") +
  scale_x_continuous(breaks = seq(-.1, .1, .05), limits = c(-.1, .1)) +
  labs(title = "[7.6.h] Marginal effects of parental status (left), and 2nd differences",
    subtitle = "2nd difference is difference in size of parent gap, across marital statuses",
    x = NULL, y = NULL)

[7.6.h] Two panels with a line at zero. Left: marginal effects of parental status on each self-rated health category for the unmarried and the married; for the unmarried, parenthood raises the probabilities of poor, fair, and good health by about .02 each and lowers the probability of excellent health by about .06; for the married all four effects are near zero. Right: the second differences (married minus unmarried) are about -.022 for poor, -.004 for fair, -.019 for good, and .045 for excellent; the confidence intervals for poor and excellent exclude zero.

// AMEs for each outcome category
mecompare parent, by(married) model(hmod)
Predicting: Pr(healthR)
Marginal effects (N_hmod=21662)

                                 |  ME #   Estimate         SE      P>|z|
---------------------------------+---------------------------------------
parent                           |                                       
        Parent - No Children     |                                       
              Poor - Not Married |     1      0.021      0.005      0.000
                  Poor - Married |     2     -0.001      0.006      0.868
              Fair - Not Married |     3      0.021      0.009      0.013
                  Fair - Married |     4      0.017      0.011      0.109
              Good - Not Married |     5      0.019      0.010      0.063
                  Good - Married |     6      0.000      0.014      0.992
         Excellent - Not Married |     7     -0.061      0.009      0.000
             Excellent - Married |     8     -0.016      0.013      0.202
# AMEs for each outcome category
mes

     Group     married  Estimate Std. Error        z Pr(>|z|)    S    2.5 %   97.5 %
 Poor      Not Married  0.020814    0.00516  4.03391   <0.001 14.2  0.01070  0.03093
 Poor      Married     -0.000966    0.00583 -0.16563   0.8685  0.2 -0.01239  0.01046
 Fair      Not Married  0.021244    0.00856  2.48064   0.0131  6.3  0.00446  0.03803
 Fair      Married      0.017172    0.01070  1.60459   0.1086  3.2 -0.00380  0.03815
 Good      Not Married  0.018961    0.01022  1.85563   0.0635  4.0 -0.00107  0.03899
 Good      Married      0.000134    0.01430  0.00935   0.9925  0.0 -0.02789  0.02816
 Excellent Not Married -0.061018    0.00860 -7.09820   <0.001 39.5 -0.07787 -0.04417
 Excellent Married     -0.016341    0.01282 -1.27459   0.2025  2.3 -0.04147  0.00879

Term: parent
Type: probs
Comparison: Parent - No Children

These are the marginal effects of parental status, separately for the married and unmarried, across each outcome category. 2nd diff. per outcome is each pair compared (e.g. 2 - 1). See below.

qui metest, clear
qui metest 2-1, add rowname("Married - Not: Poor")
qui metest 4-3, add rowname("Married - Not: Fair")
qui metest 6-5, add rowname("Married - Not: Good")
qui metest 8-7, add rowname("Married - Not: Excellent")
metest, title("2nd differences: Effect of parenthood across marital status")
2nd differences: Effect of parenthood across marital status

                                 |  estimate         se     pvalue 
---------------------------------+--------------------------------
Married - Not                    |                                
                            Poor |    -0.022      0.008      0.004 
                            Fair |    -0.004      0.013      0.762 
                            Good |    -0.019      0.017      0.274 
                       Excellent |     0.045      0.015      0.003 
# 2nd differences: Effect of parenthood across marital status
sec_ds

     Group  Hypothesis Estimate Std. Error      z Pr(>|z|)   S   2.5 %   97.5 %
 Poor      (b2) - (b1) -0.02178    0.00766 -2.842  0.00449 7.8 -0.0368 -0.00676
 Fair      (b4) - (b3) -0.00407    0.01345 -0.303  0.76207 0.4 -0.0304  0.02228
 Good      (b6) - (b5) -0.01883    0.01719 -1.095  0.27349 1.9 -0.0525  0.01487
 Excellent (b8) - (b7)  0.04468    0.01507  2.965  0.00303 8.4  0.0151  0.07421

“The interaction effect can be tested as the second difference or equality of the two MEs of parental status—for the unmarried and the married—for each outcome (Mize 2019). The right panel of Figure 8 shows the second difference for each outcome category. Two of the four are significant, indicating that parental status has a larger effect for unmarried than for married individuals on the probability of reporting poor or excellent health (though in opposite directions). We find no evidence of interaction for the probability of reporting fair or good health.” (Mize and Han 2025, p.146)

Total marginal effects

  • Although the approach above provides a valid test of interaction, it provides an ambiguous answer given differences across outcome categories
    • In addition, it answers a more nuanced question than “is the effect of parental status on health the same for married and unmarried individuals?”
  • If this broader question is of interest, total MEs can provide a holistic quantification of the effect of parental status to use in the test of interaction
    • In this case, we calculate two total MEs of parental status, one for the married and one for the unmarried, and then test their equality using a second difference test
  • With multi-outcome models, an IV’s total effect is its holistic effect across all outcomes
    • The total ME statistic is the sum of all the marginal effects for that IV (using absolute values) divided by two

\[total\ ME = \frac{\sum_{\lambda = 1}^{\Lambda}\left|\eta_{\lambda}(x_{k} = end, \mathbf{x}_{-k} = \mathbf{x}_{-k}^{*}) - \eta_{\lambda}(x_{k} = start, \mathbf{x}_{-k} = \mathbf{x}_{-k}^{*})\right|}{2}\]

// Calculate Total MEs to simplify interaction test //
mecompare parent, by(married) totalme model(hmod)
Predicting: Pr(healthR)
Marginal effects (N_hmod=21662)

                                 |  ME #   Estimate         SE      P>|z|
---------------------------------+---------------------------------------
parent                           |                                       
        Parent - No Children     |                                       
                    Total ME     |                                       
                     Not Married |     1      0.061      0.009      0.000
                         Married |     2      0.017      0.013      0.196
              Poor - Not Married |     3      0.021      0.005      0.000
                  Poor - Married |     4     -0.001      0.006      0.868
              Fair - Not Married |     5      0.021      0.009      0.013
                  Fair - Married |     6      0.017      0.011      0.109
              Good - Not Married |     7      0.019      0.010      0.063
                  Good - Married |     8      0.000      0.014      0.992
         Excellent - Not Married |     9     -0.061      0.009      0.000
             Excellent - Married |    10     -0.016      0.013      0.202
# Total ME functions
source("https://raw.githubusercontent.com/tdmize/Rfunctions/main/ME_helper_functions.R")

# Calculate Total MEs to simplify interaction test
tme <- avg_comparisons(hlthmod, variables = "parent", by = "married",
  newdata = datagrid(married = unique, grid_type = "counterfactual"),
  hypothesis = totalme(hlthmod))
tme

     married Estimate Std. Error    z Pr(>|z|)    S    2.5 % 97.5 %
 Not Married   0.0610     0.0086 7.10   <0.001 39.5  0.04417 0.0779
 Married       0.0173     0.0134 1.29    0.196  2.3 -0.00895 0.0436

Term: parent
Type: probs

The total effect of parental status is 0.061 for the unmarried; that is, parents and non-parents differ by about 6 percentage points total in terms of their self-rated health. For the married, the total effect of parenthood is only 0.017.

metest 2 - 1
                                 |  estimate         se     pvalue 
---------------------------------+--------------------------------
 parent_TotME~1 - parent_TotME~0 |    -0.044      0.016      0.005 
hypotheses(tme, hypothesis = ~ pairwise)

  Hypothesis Estimate Std. Error     z Pr(>|z|)   S   2.5 %  97.5 %
 (b2) - (b1)  -0.0437     0.0156 -2.81  0.00502 7.6 -0.0742 -0.0132

Parental status has a larger total effect for the unmarried than for the married; that is, in terms of self-rated health, parental status matters more for those who are unmarried than for those who are married (2nd diff. = -0.044, p < .01).

Back to top