Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add histogram of values distribution when graphing conditional marginal effects?

    Hi all,

    I am learning about graphing the marginal effects of a variable conditional on the values of a second variable. I see how to use the margins command and then graph those results with confidence intervals, which gives me a sense of whether the marginal effects of one variable in the interaction are significant over the value range of the other variable in the interaction. But, my conditioning variable has a range of 0 to 85, with a mean of less than 3. I would like to show a histogram of that distribution overlaid on top of the marginal effects graph. I see that in R, there is a package called "interplot" that makes it easy. Does anyone know how to do the same thing in Stata? I'm on version 15 if that matters.

    Here is what I have been doing:

    logit dependentvariable variableA variableB c.variableA#c.variableB covariateC covariate D, cluster(yadayada)
    margins, dydx(variableA) at(variableB=(0(5)85)) vsquish
    marginsplot, ylin(0)

    Thanks so much for any tips.


  • #2
    I have never tried the program overlay (below), but you might see if it works for your purpose.

    Alternatively, you could use graph combine to place histogram(s) outside the main plot like https://www.stata.com/includes/contimages/combine5.gif .

    Code:
    . ssc describe overlay
    
    -----------------------------------------------------------------------------------------------------------------------------------
    package overlay from http://fmwww.bc.edu/repec/bocode/o
    -----------------------------------------------------------------------------------------------------------------------------------
    
    TITLE
          'OVERLAY': module to overlay multiple x vs y graphs
    
    DESCRIPTION/AUTHOR(S)
          
          This command allows the user to overlap the same graph BY a
          variable.  Hence it is possible to produce individual profiles
          simply including patient as the by  variable. You can overlay
          kernel densities, histograms and just about any graphing
          function. However to get the best results the graph function
          needs to have an xlab() and ylab()  otherwise for the final plot
          there is no way of putting the same graphs on the same axes.
          This is an enhanced version of the command published in STB-54 as
          gr43.
          
          Distribution-Date: 20020423
          
          Author: Adrian Mander , GSK
          Support: email [email protected]
          
    
    INSTALLATION FILES                              (type net install overlay)
          overlay.ado
          overlay.hlp
    -----------------------------------------------------------------------------------------------------------------------------------
    (type ssc install overlay to install)
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment

    Working...
    X