Stata: CONSORT Flowchart

Standard

 

>>Update [2017/08/29]: Check out this nice automated Stata-to-CONSORT flowchart program: https://github.com/IsaacDodd/flowchart/ <<

The CONSORT flowchart for randomised controlled trials has become a standard requirement when publishing medical and social science research (see http://www.consort-statement.org/).

For me it is a regular powerpointpain (e.g. here: http://onlinelibrary.wiley.com/enhanced/doi/10.1111/jsr.12135/). I always thought it would be nice to be able to populate the flow diagram automatically.

I recently figured out how to get Stata to draw stuff. Thus here the flow chart draw by Stata (12.0).

flowchart

CONSORT Flowchart in Stata

CONSORT flowchart in Stata (pdf, high resolution)

And here the do-file, which produced the flowchart, nothing fancy, but maybe helpful:

*Definition of boxes and line styles.
local osmall = 	", box margin(small) size(vsmall)"
local omain =	", box margin(small)"
local bc = ", lwidth(medthick) lcolor(black)" 
local bca = ", lwidth(medthick) lcolor(black) mlcolor(black) mlwidth(medthick) msize(medlarge)"

*Drawing the graph
twoway  /// 1) PCI to draw a box 2) PIC horizontal lines 3) pcarrowi: connecting arrows.
   pci 5.2 0 5.2 6 `bc' || pci 5.2 6 0 6 `bc' || pci 0 6 0 0 `bc' || pci 0 0 5.2 0 `bc' ///
|| pci 3 1.5 3 4.5 `bc' || pci 1.9 1.5 1.9 4.5 `bc' || pci 0.9 1.5 0.9 4.5 `bc' ///
|| pcarrowi 5 3 3.5 3 `bca' ///
|| pcarrowi 4.35 3 4.35 3.35 `bca'  ///
|| pcarrowi 3.5 3 3.2 3 `bca'  ///
|| pcarrowi 3 3 2.1 3 `bca'  ///
|| pcarrowi 1.9 3 1.1 3 `bca'  ///
, /// Text placed using "added text" [ACHTUNG sizes change with content]
text(5 3 "Assessed for eligibility (n= )" `omain') ///
text(4.35 4.5 "Excluded ""(n= )" ///
		"Not meeting inclusion criteria " ///
		"(n= )" ///
		"Declined to participate " ///
		"(n= )" ///
		"Other reasons""(n= )" `osmall') ///
text(3.5 3 "Randomized (n= )" `omain') ///
text(3.1 3 "Allocation"  ) ///
text(2.5 1.5 "ACTIVE" ///
		"Allocated to intervention""(n=)" ///
		"Received allocated intervention ""(n=XXX)" ///
		"Did not receive allocated intervention " ///
		"(give reasons)" ///
		"(n= )" `osmall') ///
text(2.5 4.5 "CONTROL" ///
		 "Allocated to intervention" ///
		 "(n= )""Received allocated intervention " ///
		 "(n= )" /// 
		 "Did not receive allocated intervention " ///
		 "(give reasons)" ///
		 "(n= )" `osmall') ///
text(2 3 "Follow-Up" ) ///
text(1.5 1.5 "Lost to follow-up" ///
	"(give reasons)" ///
	"(n= )" ///
	"Discontinued intervention " ///
	"(give reasons)" ///
	"(n= )" `osmall') ///
text(1.5 4.5 "Lost to follow-up" ///
	"(give reasons)" ///
	"(n= )" ///
	"Discontinued intervention " ///
	"(give reasons)" ///
	" (n= )" `osmall') ///
text(1 3 "Analysis" ) ///
text(0.5 1.5 "Analysed" ///
	"(n= )" ///
	"Excluded from analysis" ///
	"(give reasons)" ///
	"(n= )" `osmall') ///
text(0.5 4.5 "Analysed" ///
	"(n= )" ///
	"Excluded from analysis " ///
	"(give reasons)" ///
	"(n= )" `osmall') /// 
legend(off) ///
xlabel("") ylabel("") xtitle("") ytitle("") ///
plotregion(lcolor(black)) ///
graphregion(lcolor(black)) xscale(range(0 6)) ///
xsize(2) ysize(3) /// A4 aspect ratio
title("Consort Flowchart") ///
note("{bf: Adapted from:} www.consort-statement.org/consort-statement/flow-diagram" ///
, size(tiny))

Anyone who fancies can just put a local to automatically fill the flowchart.

 sum participants if(group == "control")
local allocated control = r(N)
Advertisements

4 thoughts on “Stata: CONSORT Flowchart

  1. Hi Iris,
    you can change the background colour in the locals “osmall” and “omain”, by adding this option [fcolor(blue)] replace “blue” with any colour you find in Stata’s colour styles: http://www.stata.com/manuals13/g-4colorstyle.pdf

    This example shows you how it works, just copy it into your Stata:
    *–Start–
    sysuse auto.dta
    scatter price mpg, text(500 30 “Assessed for eligibility (n= )”, box fcolor(blue) color(white))
    *–End–

    Like

  2. Bridget

    This is great! I changed the code to a 4 arm trial..but all the text boxes are overlapping. Any ideas on how to get them to not overlap?

    Like

    • Hi Bridget,
      the textbox size is determined by the text size of its content. Thus the easiest way to solve the problem is to reduce the text size (“size(small)”) in the local:
      *start
      local osmall = “, box margin(small) size(vsmall)”
      *end
      You probably have to try it a few times, and you want to use the relative text sizes ie. not “vsmall” but “*.5” (which is “half the normal size). That way you have a finer control over the text size. (cf. “Relativesize” documentation: http://www.stata.com/manuals13/g-4relativesize.pdf#g-4relativesize)

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s