Independent variables can be entered into a regression model one of two ways:
Continuous
Nominal (n.b., binary is nominal but with only 2 categories)
For an ordinal IV, you must choose how to enter it (ordinal is not an option)
Stata: Use factor syntax with c. to specify a continuous predictor; i. for a nominal predictor
R: Use as_numeric to specify a continuous variable; as_factor for a nominal variable
Continuous vs nominal specifications
A continuous specification is simpler
E.g., For a 5-category ordinal IV only need to estimate 1 coefficient
A nominal is more complicated but always more accurate*
If entering as nominal, need 4 coefficients (representing 4 categories and one omitted reference category)
4 coefficients will always provide a somewhat better fit* than 1
Which should you choose? Try both:
If inferences are very similar, choose the simpler specification (continuous)
If inferences diverge, choose the more complicated but more accurate specification (nominal)
*We will cover how to provide a significance test of this in the Testing section. But R2 will always be same or higher in nominal specification (even if not significantly different)
The examples use the 2020 American National Election Studies (ANES):
combomarginsplot con_reli nom_reli, /// labels("Continuous""Nominal") xtitle("Importance of religion") /// xlab(1 "Extremely" 2 "Very" 3 "Moderately" 4 "A little" 5 "Not at all") ///title("[2.7.a] Trump feeling thermometer by importance of religion", size(medlarge)) ///subtitle("Nominal vs continuous specification of {it:relimport}")
Variables that uniquely identify margins: relimport _filenumber
library(haven) # import Stata data and labelslibrary(dplyr) # data manipulationlibrary(ggplot2) # graphslibrary(marginaleffects) # predictions and marginal effectslibrary(cleanplots) # graph schemecleanplots_defaults()source("https://raw.githubusercontent.com/tdmize/Rfunctions/main/ME_helper_functions.R")anes <-read_dta("https://tdmize.github.io/data/data/cda_anes.dta")# Keep only model vars and drop any missing data on themanes <- anes[c("feel_trump", "age", "hhincome", "woman", "lgb", "race4","educ", "relimport", "wrongtrack")]anes <- anes[complete.cases(anes), ]# Treat binary/nominal variables as factors using their value labelsanes <- anes |>mutate(woman =as_factor(woman), lgb =as_factor(lgb),race4 =as_factor(race4), wrongtrack =as_factor(wrongtrack))conmod <-lm(feel_trump ~as.numeric(relimport) +as_factor(educ) + age + hhincome + woman + lgb + race4 + wrongtrack, data = anes)con_reli <-avg_predictions(conmod, by ="relimport",newdata =datagrid(relimport = unique, grid_type ="counterfactual"))con_reli
reli_prs <-bind_rows(Continuous = con_reli, Nominal = nom_reli, .id ="spec")ggplot(reli_prs, aes(x = relimport, y = estimate, ymin = conf.low, ymax = conf.high,color = spec)) +geom_pointrange(position =position_dodge(width =0.2)) +geom_line(position =position_dodge(width =0.2)) +scale_x_continuous(breaks =1:5,labels =c("Extremely", "Very", "Moderately", "A little", "Not at all")) +labs(title ="[2.7.a] Trump feeling thermometer by importance of religion",subtitle ="Nominal vs continuous specification of relimport",x ="Importance of religion", y ="Trump feeling thermometer", color =NULL)
*These look similar enough to probably choose the continuous specification. But I would also do some statistical tests to decide (more in the Testing section of the class)
educ_prs <-bind_rows(Continuous = con_educ, Nominal = nom_educ, .id ="spec")ggplot(educ_prs, aes(x = educ, y = estimate, ymin = conf.low, ymax = conf.high,color = spec)) +geom_pointrange(position =position_dodge(width =0.2)) +geom_line(position =position_dodge(width =0.2)) +scale_x_continuous(breaks =1:5, labels =c("< High School", "High School","Some College", "College Degree", "Grad+")) +labs(title ="[2.7.b] Trump feeling thermometer by educational attainment",subtitle ="Nominal vs continuous specification of education",x ="Educational attainment", y ="Trump feeling thermometer", color =NULL)
*These look quite different to me. I would not feel comfortable using the continuous specification and would instead use the nominal specification of educational attainment
Nominal independent variables
The traditional approach for interpreting nominal IVs involves specifying an omitted reference category and interpreting the coefficients which represent contrasts between the omitted category and each included group
An issue with this approach is you do not know how included categories compare to each other
This approach also reifies the omitted category as the most important (Johfre and Freese 2021)
You also do not have any sense of how large an effect the nominal IV has overall (only specific contrasts)
One partial solution is to plot predictions for all categories of the nominal IV
There is no reference group in this approach
Stata: marginsplot with recast(scatter) for a dot plot; do not use default which connects dots with a line. Or, use coefplot
In R, avg_predictions with hypothesis = ~ meanotherdev is similar, comparing group’s prediction to the mean across all other groups
But, doesn’t account for differing group sizes
Quantifying holistic effects of nominal IVs
An important issue with any pairwise comparison approach is the high chance of a Type I error (false positive)
We will cover this more in the Testing section of the class
Another set of alternatives examine the holistic effect of the IV
The sheaf coefficient provides a single value for the overall effect of the nominal IV (Heise 1972)
Key limitation is it has no clear/satisfying interpretation
“There are many cases in which a summary of a nominal or ordinal independent variable’s (IV) effect as a holistic construct…is needed and useful for interpretation. For example, does educational attainment or occupational sector have a larger impact on wages? Both variables in this case involve multiple categories and answering this question requires somehow quantifying each IVs’ holistic effect” (Mize and Han 2025)
Marginal effect (ME) inequality statistics
A new approach summarizes the average level of inequality patterned by the nominal IV using marginal effects (Mize and Han 2025)
I.e., How different the predictions are across the nominal groupings, on average
Define each pairwise comparison (category a vs. b) as a ME:
Usually, the various groups of the nominal IV will differ in size, so should be given different weight in the ME inequality, proportional to their size
“…ME inequality can be described as the average difference in outcomes between observations in distinct groups.”
“Alternatively, ME inequality could be used to quantify a causal effect of a nominal or ordinal IV. In this case, ME inequality summarizes how outcomes would typically change if an observation switched from their current category to another category.” (Mize and Han 2025)
Calculating ME inequalities in Stata and R
In Stata, use the meinequality command or the meinequality option on mecompare