Announcement

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

  • npgraph, post estimation command for npregress

    Hi everyone,

    Hope you are doing great. So I'm currently working with the command npregress and want to plot the results using the post estimation command npgraph, but I have the following questions:
    i. Is there any way I can plot the results from two different regressions in the same graph? I tried using twoway but it appears npgraph is not a two-way plot type.
    ii. I would like to include the confidence intervals in the graph but could not find the option in the help file for the command. I am thinking of trying the addplot option for this but would like to know if there is a better way to do it.

    Thanks,

    Tessa

  • #2
    Replicating npgraph's graph using twoway is not difficult. As the conditional mean plot is overlayed on a scatterplot of the data, I do not know how wise it is to combine two graphs as the y-axis and x-axis represent the underlying data used when running npregress. If the data (variables) are different, there is no way to combine the graphs. In any case, here is how to replicate the graph.

    Code:
    webuse dui, clear
    npregress kernel citations fines
    *GRAPH 1: NPGRAPH
    npgraph, saving(gr1, replace)
    *GRAPH 2: REPLICATION USING TWOWAY
    tw (scatter citations fines) (line _Mean_citations fines , sort ///
    title("R: Mean function of citations")  leg(off) ///
    ytitle("Number of monthly drunk driving citations") ///
    note("Local linear estimates" "kernel= epanechnikov bandwidth=.563108") ///
    saving(gr2, replace))
    *COMBINED
    gr combine gr1.gph gr2.gph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	100.8 KB
ID:	1649673

    Last edited by Andrew Musau; 11 Feb 2022, 17:55.

    Comment


    • #3
      Thanks, Andrew; using graph combine, I got a similar graph to the one you shared. However, I would like for both plots to be overlaid rather than to be side by side.

      Comment


      • #4
        That's just the point of my post in #2. Do it using twoway, but my comment is that this will make sense only if the data (variables) are the same.

        Code:
        webuse dui, clear
        npregress kernel citations fines if college
        rename _Mean_citations mc1
        npregress kernel citations fines if !college
        tw (scatter citations fines if college, mc(blue%40)) ///
        (scatter citations fines if !college, mc(black%40)) ///
        (line mc1 fines if college, sort lc(blue)) ///
        (line _Mean_citations fines if !college, sort lc(black) ///
        title("Mean function of citations") leg(order(3 "College" 4 "Not college")) ///
        ytitle("Number of monthly drunk driving citations") ///
        note("Local linear estimates" "kernel= epanechnikov bandwidth college (not college)=.2895126 (.2413569)"))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	114.4 KB
ID:	1649683

        Last edited by Andrew Musau; 11 Feb 2022, 19:07.

        Comment


        • #5
          On #4, visually, if you are trying to distinguish two different sets of markers in the background, specifying a different marker symbol for each goes a long way.

          Code:
          webuse dui, clear
          npregress kernel citations fines if college
          rename _Mean_citations mc1
          npregress kernel citations fines if !college
          tw (scatter citations fines if college, msy(oh) mc(blue)) ///
          (scatter citations fines if !college, msy(plus) mc(red)) ///
          (line mc1 fines if college, sort lc(blue) lw(medium)) ///
          (line _Mean_citations fines if !college, sort lc(red) lw(medium) ///
          title("Mean function of citations") leg(order(3 "College" 4 "Not college")) ///
          ytitle("Number of monthly drunk driving citations") scheme(s1color) ///
          note("Local linear estimates" "kernel = epanechnikov bandwidth college (not college)=.2895126 (.2413569)"))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	79.6 KB
ID:	1649738

          Comment

          Working...
          X