Announcement

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

  • Graph to start at y-axis

    Hi
    I have been reproducing the following graph (from "Sample size of 12 per group rule of thumb for a pilot study" by Julious), which I suspect was created in Excel:
    Click image for larger version

Name:	graph1.jpg
Views:	1
Size:	41.9 KB
ID:	1474113

    I used the following code:
    Code:
    clear
    set obs 28
    gen n=_n+2
    gen precision=(invttail(2*n-2,0.025)*sqrt(2))/sqrt(n)
    gen gain_precision=precision[_n-1]-precision[_n]
    label variable n "Sample Size"
    label variable gain_precision "Gain in Precision"
    twoway connected gain_precision n, xlabel(4(1)30, labsize(vsmall)) ylabel(0(0.1)0.6)
    And get this graph:
    Click image for larger version

Name:	graph2.jpg
Views:	1
Size:	43.8 KB
ID:	1474112

    (The line at y=0.5 is an artefact of conversion.)

    Is there any way that I can get the line to start at the y-axis like the original, rather than having the gap between the line and the y-axis?

    Thanks,

    Jane

  • #2
    Because you have an observation with n=3, Stata extends the X axis to 3, even though gain_precision is missing in that observation and thus nothing is actually plotted at 3. The following change takes care of the problem.
    Code:
    twoway connected gain_precision n if gain_precision!=., xlabel(4(1)30, labsize(vsmall)) ylabel(0(0.1)0.6)

    Comment


    • #3
      Oh, of course! Thanks very much, William.

      Comment

      Working...
      X