Announcement

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

  • pairwise box plots

    Is there a way to plot a series of pairwise box plots with stata 12?
    using: graph box variable1-variable10, over(sex) I obtain 10 plots 1 to 10 for males, followed by 10 more for females.
    What I need is to group them so that variable1 for males is close to variable1 for females, then var2 for males and females, and so forth
    It is probably simple, and I may be missing something obvious, but I studied the help and searched the web without finding a solution
    thanks, piersante

  • #2
    Here is a pattern to play with. Where I have turn trunk, you need to give variable1-variable10 (in practice, use better names if you are not really doing so). Where I have foreign you have sex.

    Code:
    sysuse auto, clear
    
    foreach v of var turn trunk { 
        rename `v' y`v' 
    }
    
    gen id = _n 
    reshape long y, i(id) string j(which) 
    
    graph box y, over(foreign) by(which) ytitle(whatever)

    Comment


    • #3
      Thanks a lot. That was useful.
      However the by() splits the figure, while I would prefer to have all the boxes in a single line, with varying spacing so that pairs of boxes by sex are closer toghether. But this is something I could live without.

      I also found an article in the Stata journal of '09 "Speaking Stata: Creating and varying box plots" which gives some more complicated solutions and probably ight produce the outcome that I had in mind.

      Your solution is much simpler, though, and I might follow it.
      So thanks again!

      piersante

      Comment


      • #4
        If you use that 2009 article, check out the 2013 correction at http://www.stata-journal.com/article...ticle=gr0039_1

        Please register with your full name "Piersante Sestini" (?) using the Contact Us button on the bottom right of every page.

        Comment


        • #5
          You can run this to get an idea of different technique

          Code:
          clear 
          set obs 100
          gen x = _n > 50 
          forval j = 1/10 {
              gen y`j' = rnormal()
              separate y`j', by(x) veryshortlabel gen(Y`j') 
          }
          
          graph box Y*
          You would need to get in there to edit the variable labels.

          Comment

          Working...
          X