marginaleffects always giving the same estimates for a reference category when using two contrasts (R)

40 Views Asked by At

I am trying to calculate marginal effects of a triple interaction using the marginaleffects package in r. My regression looks like the following:

library(fixest)
library(marginaleffects)

fmla <-  as.formula(paste0("DV ~ ",k,"*var1:(var2 + control)  + var2 + control | FE"))

reg <- feols(fmla, data = test_df , vcov="cluster")

plot_cme(congress_reg,variables = c("var2"), condition = list("var1",k), draw = FALSE)

Where k is a set of multiple dummy variables (this function is run in lapply) var1 is a dummy variable and var2 is a factor variable with 5 levels, where the reference level (0) is specified correcly. var1 is interacted without estimating a base effect, because it is completely dependent on var2.

My problem is that when I run this, I want to estimate the contrast for both var1 and k. But every time I run this, I get variation for the marginal effects of var2 by k when var1 = 1, however when var1 = 0, the estimates are identical, regardless of the level of k. I have tried this for different inputs into k. The point estimates may be different in the different levels of var1 and so are the confidence intervals, but within each var1 level, when k = 0, the two estimates are identical. My plots drawn (with a bit of tidying after setting draw = FALSE) of this look like the following:

plot

Where the x-axis is var1, the facet_wrap is var2 and the color is k. I know that these are not accurate, because there is different variation across levels of k in each condition. I also know that there is no missing levels of any of the variables, and no coefficients drop.

Am I misunderstanding how plot_cme calculates the slopes? Can multiple contrasts not be specified like this?

EDIT, Updated with Potential Solution

After writing this question out and playing with the data some more, I realized that I never specified the baseline effect for k in interaction with var2, outside of the triple interaction. When I do this, using a formula like the following:

library(fixest)
library(marginaleffects)

fmla <-  as.formula(paste0("DV ~ ",k,"*var1:(var2 + control)  +",k,"*var2 + control | FE"))

reg <- feols(fmla, data = test_df , vcov="cluster")

plot_cme(congress_reg,variables = c("var2"), condition = list("var1",k), draw = FALSE)

I now do get variation in the estimates, showing the following:

plot2

So I think this is the reason why the second contrast did not work. There was no baseline reference level against which to calculate a marginal effect, so this contrast was fixed.

Is my intuition correct here? Would anyone be able to verify if this was likely the problem, or is there still something I have wrong? (I know this is difficult to say without providing replication data)

0

There are 0 best solutions below