Announcement

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

  • Combining many multiple variables in a bar chart

    Hi there

    I'm looking to create a chart which looks like this http://imgur.com/a/POYQi

    I have 10 dummy variables for each person in my dataset of the form

    Dum1 = Coffee is favourite drink
    Dum2 = Coffee is least favourite drink

    Dum3: Tea is favourite drink
    Dum4: Tea is least favourite drink
    ...
    Dum10: Whisky is least favourite drink

    etc for 5 drinks.

    Each variable takes the value 1 or 0.

    (People were able to select multiple favourite or least favourite drinks)

    Is there a way to create a graph from these 10 variables?


    Many thanks

    George B




  • #2
    Code:
    clear 
    set scheme s1color 
    set obs 1200 
    version 8.2: set seed 2803 
    gen dum1 = runiform() > 0.2 
    gen dum2 = runiform() < 0.1 
    gen dum3 = runiform() > 0.5 
    gen dum4 = runiform() < 0.5 
    gen dum5 = runiform() > 0.2 
    gen dum6 = runiform() < 0.1 
    gen dum7 = runiform() > 0.5 
    gen dum8 = runiform() < 0.5 
    gen dum9 = runiform() > 0.2 
    gen dum10 = runiform() < 0.1 
    gen id = _n 
    reshape long dum, i(id) j(which) 
    gen pair = ceil(which/2) 
    replace which = mod(_n, 2) 
    label def pair 1 coffee 2 tea 3 coke 4 beer 5 whisky 
    label val pair pair 
    label def which 0 most 1 least 
    label val which which 
    keep if dum 
    separate dum, by(which) 
    graph bar (sum) dum?, over(which) over(pair) legend(off)

    Comment


    • #3
      Hi Nick

      Thanks for that - really appreciate it

      George

      Comment

      Working...
      X