BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
carolinabeef
Fluorite | Level 6

Hello!

 

I'm having a few problems trying to run and interpret output from the "Predictive margins and average marginal effects" macro on SAS 9.4 using Windows 10: https://support.sas.com/kb/63/038.html

 

Right now, I'm attempting to run a simplified model using four variables, with the goal of examining margins effects of t7dmar_c on Mar_8 at different levels of t7cgender (i.e., the interactive effect of t7cgender*t7dmar_c):

Mar_8 is the outcome variable and has a negative binomial distribution

Mar_7 is a continuous predictor variable

t7dmar_c is a continuous predictor variable

t7cgender is a dichotomous (0, 1) predictor variable, to be examined as a moderator of the relationship between t7dmar_c and Mar_8

 

Here is my sas code for the macro:

 

%Margins(data = marginsdata,
class = t7cgender, 
response = MAR_8,
dist = negbin,
model = t7cgender t7dmar_c MAR_7 t7dmar_c*t7cgender,
margins = t7dmar_c, 
at = t7cgender)

 

I've gotten the macro to run in this form; however, I'm having trouble with a couple of things:

 

1. The output for the regression provides coefficients for t7dmar_c in the order of ~0.4, but the marginal effects provides coefficients ranging from ~40-100. Why would this be? My understanding is that these marginal effects should be using the sample units as in the regression. See attached for an XL file containing the output, as well as data.

 

 

2. The macro takes a VERY LONG time to run on my computer (several hours, to overnight, depending on the type of model I'm running). This is especially true when using a continuous variable in the "at = " portion. In some cases I even get "ERROR: The SAS System stopped processing this step because of insufficient memory." I'm guessing this is because it is estimating an enormous number of effects, especially in the case of the interaction between two continuous variables. I don't need marginal effects at every level in the data, and believe reducing the number of levels at which these effects are estimated should solve this problem (e.g., as it has above using a dichotomous moderator). I've read in the notes that I could request specific levels of marginal effects using both the "marginswhere = " and "atwhere = " statements. Yet, I cannot figure out how to get the model to produce marginal effects at only these levels. 

 

For example: 

 

 

%Margins(data = marginsdata,
class = t7cgender, 
response = MAR_8,
dist = negbin,
model = t7cgender t7dmar_c MAR_7 t7dmar_c*t7cgender,
margins = t7dmar_c,

marginswhere = 1,
at = t7cgender)

 

 

This will run, but provides no different output than the previous model. I would expect it to provide marginal effects of t7dmar_c only at 1. How can I request specific levels of the marginal effects? Any examples would be appreciated, as none are provided in the "Results" portion of the macro description. Perhaps I'm not understanding how these statements should be used, but I could use some help figuring it out. 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

If you want to estimate the marginal effect of a continuous predictor, you should use effect=, not margins=. margins= provides predictive margins, effect=. In the first Margins call that you show, specify effect=t7dmar_c, not margins=t7dmar_c. Generally, margins= is used with CLASS variables. If a continuous variable is specified, its number of levels should be reduced to a small number of levels using margwhere=. The large amount of time used is probably due to the t7dmar_c having a large number of levels requiring estimation of a large number of predictive margins. Similarly, at= should have a relatively few number of levels. Both margwhere= and atwhere= accept a condition such as would be specified in a WHERE statement. For example: margwhere= age in (20 30 40 50 60 70) or atwhere= age=70

View solution in original post

3 REPLIES 3
SteveDenham
Jade | Level 19

Is there anything in the log?  (Better turn on MLOGIC MPRINT and SYMBOLGEN in an OPTIONS statement first).

 

I suspect the culprit is the use of  marginswhere =, while the documentation specifies this as margwhere=,

If marginswhere is an unrecognized option, then it is likely that the macro ignores it and goes on.  This would give identical results to the first macro call.

 

SteveDenham

StatDave
SAS Super FREQ

If you want to estimate the marginal effect of a continuous predictor, you should use effect=, not margins=. margins= provides predictive margins, effect=. In the first Margins call that you show, specify effect=t7dmar_c, not margins=t7dmar_c. Generally, margins= is used with CLASS variables. If a continuous variable is specified, its number of levels should be reduced to a small number of levels using margwhere=. The large amount of time used is probably due to the t7dmar_c having a large number of levels requiring estimation of a large number of predictive margins. Similarly, at= should have a relatively few number of levels. Both margwhere= and atwhere= accept a condition such as would be specified in a WHERE statement. For example: margwhere= age in (20 30 40 50 60 70) or atwhere= age=70

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1935 views
  • 3 likes
  • 4 in conversation