title: Is there a way to subset data for Python statsmodels .get_margeff() like in R margins()?
body: <p>I created a model using mnlogit() from statsmodels that looks something similar to this:</p>
  <blockquote>
  <p>formula = &quot;Switch_Variable ~ Prior_Complication_categ * C(Prior_Delivery_Type) +<br />
  C(RaceName) + C(EthnicityName) + AgeInYears + C(Insurance) +<br />
  TotalScore + Mortality_Score + Readmission_Score + num_deliveries&quot;
  logmodel = smf.mnlogit(formula, data=analysis2_lagged).fit()</p>
  </blockquote>
  <p>I know that you can use logmodel<a href="https://www.statsmodels.org/devel/generated/statsmodels.discrete.discrete_model.LogitResults.get_margeff.html" rel="nofollow noreferrer">.getmargeff()</a> to get marginal effects for the model. There is <em>atexog</em> parameter that allows you to get marginal effects for counterfactual dataset, where it changes the value of whatever variable you put into <em>atexog</em> for all observations and estimates the marginal effects based on that.</p>
  <p>Instead, I wonder whether I could get marginal effects for a subset of data (such as dataset for Prior_Delivery_Type = 1). I know that R margins() allows you to subset data within the margins() function directly (details <a href="https://cran.r-project.org/web/packages/margins/vignettes/Introduction.html#Subsetting" rel="nofollow noreferrer">here</a>).</p>
  <p>If there is no such feature in statsmodels, is there a workaround without using R? Any help would be appreciated!</p>