Announcement

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

  • npregress intro manual replicate figures

    Hi,
    I'm looking for the code behind the figures in npregress intro manual
    https://www.stata.com/manuals/rnpregressintro.pdf
    I would like to replicate figure 15.
    I would really appreciate an answer as no one has ever answered me on this forum
    Thanks
    Click image for larger version

Name:	Screen Shot 2022-04-05 at 5.10.23 PM.png
Views:	1
Size:	146.5 KB
ID:	1658125

  • #2
    Well, It isnt possible to replicate the figure exactly,
    But here is an example using simulated data:
    Code:
    clear
    set seed 3
    set obs 300
    gen x=rnormal()
    ** here y=f(x) + e, where f(x) is the TRUE nonlinear function
    gen y = x^3+rnormal()*5
    keep if !abs(x)<2.5
    
    ** Here simply estimate the simple estiamtor (as lpoly does), by calculating the mean of y if X is within the specified rank
    gen my=.
    forvalues i = 1/300 {
        qui:sum y if inrange(x,x[`i']-.25,x[`i']+.25), meanonly
        qui:replace my = r(mean) in `i'
    }
    ** And just some plot
    two (scatter y x, msymbol(Oh) color(maroon)) ///
          (scatter my x, msymbol(square) mcolor(navy*0.9) msize(3) mfcolor("158 218 229")), ///
          legend(off) title("just an example")
    Last edited by FernandoRios; 05 Apr 2022, 19:34.

    Comment


    • #3
      Thank you so much for your answer! works great

      Comment

      Working...
      X