Announcement

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

  • custom error bars with the lgraph package?

    Hello Stata Gurus,

    I have some panel data and am using the lgraph package to produce plots of the measured means over time

    calling....

    Code:
    lgraph measurement timevar, errortype(sd)
    produces a nice graph with standard deviations on the error bars. However, I would like the error bars to be 1/2 a standard deviation on each side of the mean instead.

    Is anyone willing to share how to create these error bars instead?

    Thanks in advance,

    Jonathan Tward
    Last edited by Jonathan Tward; 22 May 2018, 15:02.

  • #2
    lgraph is from SSC, as you are asked to explain: that is a long-standing request for mentions of all community-contributed commands (FAQ Advice #12). It's a versatile command I have never used. The author, Timothy Mak, posts here occasionally. Looking at the help I see no way to do this. If I were referring a paper or examining a thesis with error bars based on SD/2 I would ask why that was being done.

    I suspect you'll get a definitive reply by emailing Timothy directly.

    Comment


    • #3
      Dear Dr. Cox,

      Thank you so much for the reply. In answer to your question of why a 1/2 standard deviation: I work in medical outcomes research, usually comparative effectiveness of differing treatments for the same conditions in oncology. Specifically, I am often comparing radiation therapy to surgical therapy for prostate cancer. Most quality of life patient surveys use a point scoring system to tabulate QOL in any given domain (urinary function, bowel function, sexual function for example). The community of patient-reported outcomes researchers has accepted that a 1/2 standard deviation from the mean represents a "clinically significant" change in QOL on almost any QOL survey. So if you see a change of 1/2 SD before and after a therapy, it is interpreted to mean that QOL has changed in a way that is meaningful to a patient and therefore implies a that they have significant improvement or bother in their QOL.

      As I have been toying around on my own, I have come up with a solution, which I am happy to share:

      The example presumes you are looking at how QOL for treatment A vs Treatment B differs over time.
      Assume the following variables for repeated measurements using a survey that scores quality of life (QOL):

      QOLscore = a measurement of quality of life, numeric
      timevar = when the qolscore was measured relative to an intervention (e.g. -5 is 5 days before treatment, 13 is 13 days after treatment), numeric
      treatment= treatment group (categorical like "group a" or "group b")
      individualidentifier = some unique identifier of an individual, categorical

      Code:
      //create bins of time to reflect pre and post treatment values.  example will make bins from pretreat to 5 days after, by day
      egen timebins= cut( timevar), at(-0.5,0,1,2,3,4,5)
      
      //create a factor variable of treatment
      egen tx=group( treatment), label
      
      //need to get rid of any duplicate surveys by individuals within any timebin
      sort individualidentifier timebins
      by individualidentifier timebins:  gen dup = cond(_N==1,0,_n)
      tabulate dup
      drop if dup>1
      
      
      //collapse the data and generate mean and SD
      collapse (mean) QOLscore (sd) QOLsd=QOLscore, by (timebins tx)
      
      //get the 1/2 sd
      generate minsd=(QOLscore- QOLsd/2)
      generate maxsd=(QOLscore+ QOLsd/2)
      
      //make the graph with 1/2 sd by feeding minsd and maxsd to the lgraph command by specifying errortype
      
      
      lgraph QOLscore timebins tx, errortype(collapse(minsd maxsd)) ytitle( score w/ 1/2SD)

      This will produce the graph I am looking for.

      I hope this helps others looking to make weird custom errorbars in panel data over time.

      I could not figure out any way to work with the xtgraph command to get these types of custom bars.
      Last edited by Jonathan Tward; 29 May 2018, 17:13.

      Comment

      Working...
      X