Announcement

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

  • Several range plots in one graph

    Hello Stata users

    I am quite new in Stata and try to create a range plot. My data set has 9 variables and 4 records. What I d like to have is a graph with 4 range plots (var1 - var2 / var3 - var4 / var5 - var6 / var7 -var8) for every year.

    var1 var2 var3 var4 var5 var6 var7 var8 year
    31.76 36.24 37.96 41.46 32.75 37.12 38.45 42.04 9
    42.07 45.65 48.09 51.38 42.71 46.83 49.35 52.06 11
    45.05 50.11 52.71 55.15 46.72 51.17 53.26 56 13
    50.75 51.59 57.8 59.74 51.49 60.25 53.71 60.8 15

    I typed the following command: twoway (rcapsym var1 var2 year) (rcapsym var3 var4 year) (rcapsym var5 var6 year) (rcapsym var7 var8 year)

    The output graph looks almost fine, but I would like to have the range plots in parallel not in the same line. More precisely as the values at year 9 are all between 31 and 42, the range plots overlap in the graph. My preferred figure would group for every age the 4 range plots, so that there is no overlapping.

    Thank you very much for your help!

    Mathias Rechsteiner


  • #2
    Just add a small interval to year across groups.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(var1 var2 var3 var4 var5 var6 var7 var8 year)
    31.76 36.24 37.96 41.46 32.75 37.12 38.45 42.04  9
    42.07 45.65 48.09 51.38 42.71 46.83 49.35 52.06 11
    45.05 50.11 52.71 55.15 46.72 51.17 53.26    56 13
    50.75 51.59  57.8 59.74 51.49 60.25 53.71  60.8 15
    end
    
    rename year year1
    forval i=2/4{
    local j= `i'-1
    gen year`i'= year`j'+0.07
    }
    
    set scheme s1color
    twoway (rcapsym var1 var2 year1) (rcapsym var3 var4 year2) \\\
    (rcapsym var5 var6 year3) (rcapsym var7 var8 year4), \\\ 
    xlab(8 9 11 13 15 16)
    Click image for larger version

Name:	rcapsym.png
Views:	1
Size:	21.1 KB
ID:	1462658

    Comment


    • #3
      Thank you very much Andrew for your precious help! It makes my day. Once you see the solutions, it is so obvious how to solve :-)

      Comment

      Working...
      X