rhypothesis-testmarginal-effectsmodelsummaryr-marginaleffects

Displaying marginal effects using avg_slopes() for Specific Level Transitions in plm Models with Interaction Terms


I am analyzing panel data using the plm package in R and have run into a challenge with interpreting and calculating the output from the avg_slopes function. My model looks at life_satisfaction as a function of employment_level (with three categories: non_working, part_time, full_time), interaction with current_children(one_child, two_children, more_than_two_children), and other control variables.

Here's a simplified representation of my model:

mod_2 <- plm(life_satisfaction ~ employment_level * current_children + ...,
             data = data_analyse_mother, 
             index = c("pid", "syear"), 
             model = "within")`

I'm using avg_slopes() to understand the marginal effects of shifting between employment levels, particularly when changing from non_working to full_time, and from part_time to full_time, and from part_time to non-working across different levels of current_children.

Here's the avg_slopes call:

avg <- avg_slopes(mod_2, variables = "employment_level", by="current_children")

The output provides contrasts between non_working and full_time, as well as part_time and full_time, but it does not directly show the contrast from non_working to part_time. Below is a replicated table of the output:

| term             | contrast                               | current_children         | estimate    |
|------------------|----------------------------------------|--------------------------|-------------|
| employment_level | mean(Not_Working) - mean(Full_Time)    | more_than_two_children   | -0.33049722 |
| employment_level | mean(Not_Working) - mean(Full_Time)    | one_child                | -0.21408351 |
| employment_level | mean(Not_Working) - mean(Full_Time)    | two_children             | -0.25985500 |
| employment_level | mean(Part_Time) - mean(Full_Time)      | more_than_two_children   | -0.22848561 |
| employment_level | mean(Part_Time) - mean(Full_Time)      | one_child                | -0.09376425 |
| employment_level | mean(Part_Time) - mean(Full_Time)      | two_children             | -0.06093251 |

I need to compare the effect of transitioning from non_working to part_time. What is the appropriate approach to obtain this specific contrast using avg_slopes.

I tried the pairwise hypothesis, but it didn`t work.


Solution

  • The default is to compare all levels to the baseline category (the first observed category or the "reference" level of a factor). You can change this by using the avg_comparisons() function and its variables argument:

    avg <- avg_comparisons(mod_2, 
      variables = list("employment_level" = "pairwise"), 
      by = "current_children")
    

    Note that avg_slopes() is just a thin wrapper around avg_comparisons(), which specifies comparison="dydx" for numeric variables. The results should be the same.

    Please read the comparisons() function documentation for more details: https://marginaleffects.com/man/comparisons.html#arguments