Announcement

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

  • Tabplot for Count data: pre and post variables by group

    I am trying to use the user command Tabplot (as recommended by Nick Cox) to created histograms of my pre and post count variables (counts of Use of force incidents) by group (control and experimental). I created to different set of charts using the tabplot command and the I combined the two graphs. Below you can see the actual syntax I used.

    Code:
    tabplot PreUOF, xasis percent yasis  by(Group)nodraw name(PreHist, replace)
    tabplot PostUOF, xasis percent yasis  by(Group)nodraw name(PostHist, replace)
    graph combine PreHist PostHist, col(1)
    However, these graphs do not look good por presentation. I would like to have the pre value next to the post value for each group. That is, in the control group, the bar of the pre 3 should be next to post value 3, ext. I would then have two charts one for pre and one for post examinations. My aim is to show the difference between pre and post examinations. Also, I would like to include:

    1. The Y axis
    2. Make the X values smaller
    3. Have one color for pre and one for post


    I tried to do this and look for resources but I couldn't figure it out.

    Thank you!
    Marvin




    Attached Files

  • #2
    You need a different command to do that, possibly graph bar or twoway bar

    Comment


    • #3
      thank you Nick! I will see what I can do

      Comment


      • #4
        Graph.png Hi Nick Cox ,

        Going back to this post (I hope you remember). I think I got what I want. I use create two graphs using the twoway command and then combine them using the command graph combine. My final grpah is attached. My question is only if there is a create the graph without using the graph combine. That is a single graph, maybe using the by option so it looks a little bit better? Below, you can find a sample of my data.

        Code:
        # delimit ;  
            twoway
            (histogram PreUOF if !Group, width(1) percent discrete bfcolor(none) blcolor(brown))
            (histogram PostUOF if !Group, percent discrete  width(1) barw(.8) bfcolor(none) blcolor(navy)),
            legend(order(1 "Pre" 2 "Post")pos(2) ring(0) col(1))
            scheme(s1color)
            yla(, format("%1.0f") ang(h))
            title("Control", size(medium))
            name(ConDis,replace)
            nodraw;
         
            twoway
            (histogram PreUOF if Group, width(1) percent discrete bfcolor(none) blcolor(brown))
            (histogram PostUOF if Group, percent discrete width(1) barw(.8) bfcolor(none) blcolor(navy)),
            legend(off)
            scheme(s1color)
            yla(,format("%1.0f") ang(h))
            title("Experimental", size(medium))
            name(ExpDis,replace)
            nodraw;
        # delimit cr
        graph combine ConDis ExpDis, col(1)  ycommon xcommon title("Pre and Post Frequency Distribution for Control and Experimental Groups", size(medium) span)
        graph export "H:\PMA\5003 Data\5003 Evaluation\Output\Distribution.pdf", as (pdf) replace

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input long(PreUOF PostUOF) byte Group
         5  0 0
         6  2 0
         5  9 0
         5  3 1
         6  4 0
         3  0 0
         7 10 0
         8  3 1
        10  4 1
         3  5 1
         8  2 1
         3  0 1
         3  3 0
         3  0 0
        end
        label values Group Group
        label def Group 0 "Control", modify
        label def Group 1 "Experimental", modify
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	69.2 KB
ID:	1342630
        Attached Files
        Last edited by Marvin Aliaga; 25 May 2016, 15:05.

        Comment


        • #5
          Just try using by(Group) rather than two separate commands with complementary qualifiers.

          Comment


          • #6
            This works:

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input long(PreUOF PostUOF) byte Group
             5  0 0
             6  2 0
             5  9 0
             5  3 1
             6  4 0
             3  0 0
             7 10 0
             8  3 1
            10  4 1
             3  5 1
             8  2 1
             3  0 1
             3  3 0
             3  0 0
            end
            label values Group Group
            label def Group 0 "Control", modify
            label def Group 1 "Experimental", modify
            
            set scheme s1color 
            
            local opts  width(1) percent discrete bfcolor(none) ///
            yla(, format("%1.0f") ang(h))
            
            twoway histogram PreUOF, `opts' blcolor(brown) ||    ///
            histogram PostUOF, `opts' barw(.8) blcolor(navy)     /// 
            legend(order(1 "Pre" 2 "Post")pos(2) ring(0) row(1)) ///
            by(Group, note("") col(1))

            Comment


            • #7
              Wow Nick! Thank you so much! I thought my graph was beautiful but yours is way better! Thank you!

              One more question, I think I will be working more with graphs in Stata at my job. Is there a way to create a new scheme with my organization specifications. For example selecting the color I want for charts (RGB colors) and font. I have a presentation and would like that all my graphs look somewhat the same.

              Thanks,
              Marvin

              Comment


              • #8
                Naturally. You can create your own scheme. I'd also look at the brewscheme work (SSC etc.) of Billy Buchanan, who is active here (as @wbuchanan). I've not looked closely at it but I doubt that there is anyone outside StataCorp who has thought more about schemes than Billy. He knows much, much more about scheme specification than I do.

                I just go for s1color and make changes ad hoc but working out some personal standards and sticking them is wholly admirable. Just don't mix red and green!

                Comment


                • #9
                  Thanks Nick! I will check brewscheme. How can I quickly change the colors you chose to some RGB color. this was try but the lines are black!

                  Code:
                  set scheme s1color
                  local opts  width(1) percent discrete bfcolor(none) ///
                  yla(, format("%1.0f") ang(h))
                  twoway histogram PreUOF, `opts' blcolor(### "242" "97" 34") ||    ///
                  histogram PostUOF, `opts' barw(.8) blcolor(### "246" "178" 34")     /// 
                  legend(order(1 "Pre" 2 "Post")pos(2) ring(0) row(1)) ///
                  by(Group, note("") col(1) title("Pre and Post UOF Frequency Distribution by Group",size(medium))) ylabel(0[10]50)  ///
                  name(Distribution, replace)
                  Last edited by Marvin Aliaga; 27 May 2016, 12:25.

                  Comment


                  • #10
                    This is the way that you specify RGB values:
                    Code:
                    blcolor("242 97 34")
                    or 
                    bfcolor("242 97 34")
                    so something like this:

                    Code:
                    local opts  width(1) percent discrete  ///
                    yla(, format("%1.0f") ang(h))
                    twoway histogram PreUOF, `opts' blcolor(black) bfcolor("242 97 34")||    ///
                    histogram PostUOF, `opts' barw(.8) blcolor(white)  bfcolor("246 178 34")   /// 
                    legend(order(1 "Pre" 2 "Post")pos(2) ring(0) row(1)) ///
                    by(Group, note("") col(1) title("Pre and Post UOF Frequency Distribution by Group",size(medium))) ylabel(0[10]50)  ///
                    name(Distribution, replace)
                    Stata/MP 14.1 (64-bit x86-64)
                    Revision 19 May 2016
                    Win 8.1

                    Comment

                    Working...
                    X