Announcement

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

  • Creating a single box plot of pre-post survey responses to individual items, ordered by item

    Dear Stata Users,

    I'm trying to use graph box (Stata 13.1) to display summary data for survey responses to individual items before and after an intervention, using the over command. However I am unable to rearrange the data so that the items are ordered with before/after box plots for each item.

    Variable description/Code:

    "sespd" and "noedpd" are categorical variables with 5 item Likert scale response options.
    "after" is coded as 0 for the survey response before the intervention and 1 for the response after the intervention

    graph box sespd noedpd, over(after) ascategory

    produces graph1

    What I would like to see is the data ordered by 0 1 for sespd followed by 0 1 for noedpd

    I tried to use sort, but it can only be specified as an over sub option, so I don't think this is the command I need.

    Thanks,
    Any help would be appreciated.






  • #2
    If I understand correctly, what you need to do is to have a *single* variable for the response, not two of them. So something like:

    Code:
    gen response= sespd
    replace response=noedpd if response==.
    graph box response, over(after) ascategory
    Did this get you what you wanted? It was a bit vague to me, but I think I understood your need.

    Comment


    • #3
      Sorry if I was unclear,
      I'll add a few more details. There are 90 responders in the dataset, and each responder does the survey before and after the intervention.

      sespd and noedpd are responses to separate questions, so there are 180 responses for sespd (before and after) and 180 responses for noedpd (before and after). Because they are separate questions, combining wouldn't work...

      Comment


      • #4
        Ah. Then you want graph combine. See this and see if it's close to what you want:

        Code:
        clear
        set obs 1000
        set seed 1971
        
        *====generate responses
        gen sespd=round(uniform()*5+.5)
        gen noedpd=round(uniform()*5+.5)
        
        gen after=0 if _n<=500
        replace after=1 if _n>500
        
        replace sespd=sespd+.5 if after==1
        
        *=======split into two variables
        
        graph box sespd, over(after) ysc(r(0 6))
        graph save Graph c:\data\sespd.gph, replace
        graph box noedpd, over(after) box(1, color(red)) ysc(r(0 6))
        graph save Graph c:\data\noedpd.gph, replace
        graph combine "C:\data\noedpd.gph" "C:\data\sespd.gph"

        Comment


        • #5
          better, with "ycommon" option:

          Code:
           graph box sespd, over(after) ysc(r(0 6))
          graph save Graph c:\data\sespd.gph, replace
          graph box noedpd, over(after) box(1, color(red)) ysc(r(0 6))
          graph save Graph c:\data\noedpd.gph, replace
          graph combine "C:\data\noedpd.gph" "C:\data\sespd.gph", ycommon

          Comment


          • #6
            Inspired by Ben's post #4. However, with a 5-level categorical scale, I find that a box plot is not a very informative graph. Here is an example of stacked bars. Just for inspiration.
            Code:
            set obs 100
            set seed 12345
            
            gen sespd=ceil(5*runiform())
            gen noedpd=ceil(5*runiform())
            
            gen after=_n>50
            label define after 0 "Before" 1 "After"
            label values after after
            gen one=1
            
            graph bar (count) one ,                        ///
            over(sespd) over(after) asyvars stack          ///
            bar(1, fcolor(gs0))                            ///
            bar(2, fcolor(gs9))                            ///
            bar(3, fcolor(gs12))                           ///
            bar(4, fcolor(gs14))                           ///
            bar(5, fcolor(gs16))                           ///
            legend(order(5 4 3 2 1))                       ///
            ytitle("sespd")                                ///
            name(p1, replace)
            
            graph bar (count) one ,                        ///
            over(noedpd) over(after) asyvars stack         ///
            bar(1, fcolor(gs0))                            ///
            bar(2, fcolor(gs9))                            ///
            bar(3, fcolor(gs12))                           ///
            bar(4, fcolor(gs14))                           ///
            bar(5, fcolor(gs16))                           ///
            legend(order(5 4 3 2 1))                       ///
            ytitle("noedpd")                               ///
            name(p2, replace)
            
            graph combine p1 p2

            Comment


            • #7
              I have to agree with Svend that box plots of 5-point Likert scales can at best be a little weird and at worst really strange with the side-effects of ties.

              Comment


              • #8
                Wow, that is a whole lot better, in numerous ways. Not quite as easy to see a simple change in the mean, though.

                Comment


                • #9
                  Thanks for all of your suggestions, very helpful!

                  Comment

                  Working...
                  X