Announcement

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

  • Twoway graphing: How to smooth several curves while using rarea

    Dear Statalisters,

    I am currently working on a twoway graph using point estimates created by using a stcompet command, producing the estimates for plotting the cumulative incidence and upper and lower confidence interval bounds. To shade the area between the confidence intervals, I'm using twoway area and for the incidence curve I am using a simple line option to make the confidence interval lines to correspond to the cumulative incidence curve.

    The problem I face is that I have to smooth these lines due to institute policies, and to my understanding - I can't add the lowess option while simultaneously using rarea and line commands.

    Is there a way to smooth the curves used by rarea and line? I've tried to search through this forum and different books without finding a good solution for this.

    My syntax looks somewhat like this:

    twoway (rarea CI_low CI_upper year, fcolor("75 45 122") fintensity(20) lcolor(white)) ///
    (line CI_est year, lcolor("72 44 122") lpattern(solid) lwidth(thick)), ///
    ytitle("{bf: Cumulative incidene of"} "{"bf: disease (%)}", margin(medium))
    yscale(range (0 20)) ///
    ylabel(0 "0" 5 "5" 10 "10" 15 "15" 20 "20", angle(horizontal)) ///
    xtitle("{bf: Years of age}", margin(medium)) ////
    xscale(range(0 40)) ///
    xlabel(0 (10) 40) ///
    graphregion(color(white)) ///
    xsize(8) ysize(4)

    Any help would be highly appreciated since I know about other colleagues that are having similar issues.

    Kind regards,
    Håkon

  • #2

    Note: -stcompet- is from Vincenzo Coviello and May Boggess, Stata Journal 4,2 (https://www.stata-journal.com/articl...article=st0059).

    Cannot you not smooth the lines before generating the graphs:

    Code:
    clear
    set obs 5000
    set seed 1234
    gen t25 = -1/.25 * log(1-uniform())
    gen t99 = -1/.99 * log(1-uniform())
    gen time = min(t99,t25)
    gen byte fail = (t25<t99) + 2*(t25>=t99) 
    replace fail = 0 if time>=2
    replace time = 2 if time>2
    stset time, f(fail==1) noshow
    sts gen KM = s
    gen Complement = 1- KM
    stcompet  Incidence=ci High = hi Low = lo, compet1(2)
    keep if fail==1
    twoway rarea Low High time , sort fintensity(20) /// 
        || line Incidence time, sort name(gr1,replace)
    
    lowess Incidence time, gen(smooth_i) nograph
    lowess Hig time, gen(smooth_h) nograph
    lowess Low time, gen(smooth_l) nograph
    
    twoway rarea smooth_l smooth_h time , sort fintensity(20) /// 
        || line smooth_i time , sort name(gr2,replace)

    Comment


    • #3
      Dear Scott,

      Thank you so much for such a good reply! That worked perfectly, creating smooth lines before making the graph did the job.

      I hope I'll someday get experienced enough with Stata to make a contribution back to this community, which has helped me a lot so far..!

      Best,
      Håkon

      Comment

      Working...
      X