Announcement

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

  • Histogram with multiple variables

    Hello everyone,

    I have a problem creating a histogram for my experimental master's thesis. I need to do a chat data analysis for the arguments used during the chat by group members. I created six dummy variables for the ideas related to risk, honesty, and dishonesty. I want to create the following graph, but I can't find a way to make it. Basically, I want to show the share of those arguments used during the chat.

    Thank you for your time.
    Click image for larger version

Name:	histogram example 2.png
Views:	1
Size:	30.9 KB
ID:	1675146

    Last edited by Esraa Dagli; 26 Jul 2022, 05:09.

  • #2
    This is perhaps one of the many ways to approximate the example graph, but you'll need to create that summary first that looks like the sample data using collapse. Basically, just need to layer on with over() and by().

    Code:
    clear
    input str5 reporting pc subvar y
    A 1 1 0.4
    A 1 2 0.05
    A 1 3 0.02
    A 1 4 0.02
    A 1 5 0.08
    A 2 1 0.36
    A 2 2 0.15
    A 2 3 0.15
    A 2 4 0.0
    A 2 5 0.05
    B 1 1 0.08
    B 1 2 0.08
    B 1 3 0.16
    B 1 4 0.03
    B 1 5 0.0
    B 2 1 0.06
    B 2 2 0.2
    B 2 3 0.06
    B 2 4 0.06
    B 2 5 0.02
    end
    
    label define l_pc 1 "GroupPC" 2 "GroupNoPC"
    label values pc l_pc
    label define l_subvar 1 "Money" 2 "Honesty" 3 "Insecurity" 4 "Rules" 5 "Others' behavior"
    label values subvar l_subvar
    
    graph bar y, over(subvar, lab(angle(45))) over(pc) by(reporting)

    Comment


    • #3
      Thank you soo much! It worked perfectly.

      Comment


      • #4
        I agree with Ken Chui that there are many ways to plot such data. Here I steal Ken's data example and use tabplot from the Stata Journal. For an overview, see https://www.statalist.org/forums/for...updated-on-ssc

        Code:
        set scheme s1color 
        tabplot subvar pc [iw=y], by(reporting, note("")) showval(format(%03.2f)) separate(subvar) xtitle("") ytitle("")

        Click image for larger version

Name:	honestyetc.png
Views:	1
Size:	24.3 KB
ID:	1675211

        Comment

        Working...
        X