Announcement

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

  • Creating a stacked bar chart for 3 different variables

    Hello Statalis,

    I have done a conjoint experiment survey, where respondents were asked to choose between two random profiles.
    I would like to display some of these decisions in a stacked bar chart, but I just did not find a way to do it the way I imagine it, but maybe it is impossible anyways, which is why I am now asking here.

    So I have three "battle" variables, BYvO (Choice between young and old profile; value: 1=young 2=old), BYvM (Choice between Young and midage profile, value: 1=young and 2=midage) and BMvO (Choice between midage and old profile, value 1=midage 2=old).
    For each variable isolated I can create charts like the following (percentage means n% chose old profile in decision between young and old profile)
    The following catplot was installed with relatively easy code: "catplot BYvO, percent asyvars stack"
    Click image for larger version

Name:	BYvOstacked.png
Views:	1
Size:	44.1 KB
ID:	1617849





    I've done that with the other variables as well and then tried to combine them using
    "catplot BYvO, percent asyvars stack saving(bar1)
    catplot BYvM, percent asyvars stack saving(bar2)
    catplot BMvO, percent asyvars stack saving(bar3)

    graph combine bar1.gph bar2.gph bar3.gph, ycommon commonscheme"
    Click image for larger version

Name:	combined.png
Views:	1
Size:	67.5 KB
ID:	1617850



    but that creates just these three different charts, so I want to know if I can put them into one graph with the same axis and different labels for each bar.

    What I had in mind (sorry for bad drawing):
    Click image for larger version

Name:	WhatsApp Image 2021-07-07 at 21.02.28.jpeg
Views:	1
Size:	163.7 KB
ID:	1617851




    Thank you very much for your help!
    Tristan

    PS: Sorry I tried to make the images smaller, but it won't save it that way
    Last edited by Tristan Muno; 07 Jul 2021, 13:07.

  • #2
    Data example please (https://www.statalist.org/forums/help#stata)

    Comment


    • #3
      Here's my data:

      the values of c_00## variables represent the Profile Nr which is assigned (which is randomized);

      c_0007 c_0008 c_0009 c_0010 c_0011 c_0012
      1 2 6 5 3 4
      6 4 1 2 5 3
      4 6 1 3 5 2
      6 3 1 2 5 4
      1 4 5 2 3 6
      6 1 4 3 5 2
      2 4 6 1 5 3
      1 3 5 2 4 6
      4 2 5 3 6 1
      3 2 1 6 4 5
      5 1 4 6 2 3
      3 2 1 6 4 5
      2 3 1 4 5 6
      2 4 1 6 5 3
      2 4 1 3 5 6
      6 5 2 1 3 4
      1 4 2 3 5 6
      4 2 5 3 6 1
      6 3 5 2 1 4
      1 4 2 6 3 5
      1 5 2 4 3 6
      2 4 1 6 5 3
      6 3 2 5 1 4
      2 3 1 5 4 6
      6 2 1 3 4 5
      3 1 2 6 4 5
      5 2 6 3 1 4
      2 3 1 4 6 5
      6 3 5 4 2 1
      1 4 6 5 3 2
      4 2 6 3 5 1
      4 3 5 2 6 1
      3 6 2 1 4 5
      6 3 2 5 4 1
      1 4 5 3 6 2
      6 1 3 4 2 5
      2 4 6 1 5 3
      1 3 2 4 5 6
      2 3 1 4 5 6
      5 3 1 4 2 6
      5 4 6 1 2 3
      2 4 6 1 5 3
      6 5 3 4 2 1
      5 3 2 4 1 6
      1 4 5 3 2 6
      4 6 3 5 2 1
      6 3 4 5 2 1
      5 6 2 4 3 1
      1 4 2 6 3 5
      5 3 2 6 4 1
      4 3 5 1 2 6
      5 3 2 6 4 1
      5 2 6 3 4 1
      6 3 1 4 5 2
      1 4 3 2 5 6
      4 1 2 5 3 6
      1 3 6 4 5 2
      5 4 3 6 1 2
      6 2 1 5 3 4
      5 4 6 3 2 1
      4 2 3 5 6 1
      2 4 3 5 6 1
      2 3 4 6 1 5
      1 4 3 2 6 5
      2 1 5 6 4 3
      5 1 4 3 6 2
      6 5 1 2 3 4
      2 3 4 5 1 6
      6 4 3 1 5 2
      2 3 4 6 1 5
      2 4 3 1 6 5
      2 6 3 1 4 5
      6 2 3 4 5 1
      3 2 4 6 5 1
      1 5 2 6 4 3
      1 6 5 3 2 4
      3 5 1 4 6 2
      3 2 6 4 1 5
      5 3 6 4 2 1
      1 6 2 4 3 5
      4 1 5 6 2 3
      3 2 5 1 4 6
      2 3 5 1 4 6
      5 2 4 6 1 3
      2 6 1 5 4 3
      3 5 6 1 2 4
      4 5 2 6 1 3
      5 6 2 4 3 1
      6 1 2 5 3 4
      2 4 5 3 6 1
      4 1 5 6 3 2
      6 1 2 3 4 5
      6 5 1 4 2 3
      3 6 5 4 1 2
      6 4 5 2 1 3
      3 6 5 1 2 4
      4 1 2 3 5 6
      4 2 1 6 5 3
      4 5 6 2 1 3
      1 4 3 6 2 5
      5 6 1 4 2 3
      4 5 6 2 3 1
      4 5 3 2 6 1
      4 6 3 5 2 1
      4 2 3 1 5 6
      1 6 3 4 2 5
      5 2 3 1 4 6
      4 6 2 1 3 5
      5 1 2 4 6 3
      6 2 5 4 1 3
      6 2 4 5 1 3
      1 5 3 2 6 4
      1 6 5 3 4 2
      2 4 1 6 3 5
      1 4 5 3 6 2
      2 6 4 1 5 3
      5 1 6 3 4 2
      5 1 2 6 4 3
      2 1 3 5 6 4
      6 5 4 1 2 3
      2 1 4 5 6 3
      2 3 4 5 6 1
      6 1 4 2 3 5
      2 3 1 5 6 4
      6 4 2 1 5 3
      1 3 6 2 5 4
      1 5 3 6 2 4
      1 2 4 3 5 6
      5 1 4 3 6 2
      5 1 4 2 3 6
      1 5 4 2 3 6
      1 5 4 3 2 6
      1 6 3 2 5 4
      2 5 3 6 4 1
      6 5 4 2 3 1
      2 5 4 6 3 1
      2 1 3 6 5 4
      2 3 5 4 1 6
      1 4 5 3 2 6
      2 1 3 5 6 4
      4 6 5 3 2 1
      5 6 4 3 2 1
      2 1 4 6 5 3
      6 1 3 4 5 2
      2 5 3 4 6 1
      6 1 4 2 5 3
      1 2 5 6 4 3
      3 1 4 6 5 2
      4 3 6 2 1 5
      3 2 4 1 5 6
      3 4 5 6 2 1



      then, the "Decisions" within the experiment are coded v_1## (values represent Profile Nr. which was chosen)


      v_152 v_154 v_155 v_156 v_157 v_158 v_159 v_160
      1 6 4 1 3 6 6 2
      6 1 5 2 5 1 1 4
      6 1 5 3 5 1 1 6
      6 1 5 6 3 1 6 4
      1 5 6 1 4 5 1 6
      6 4 2 3 1 4 6 2
      2 1 5 2 5 6 2 3
      1 5 6 1 3 5 5 6
      2 5 1 4 2 5 5 1
      3 1 5 6 2 1 1 5
      1 4 3 6 1 4 4 3
      2 1 5 6 2 1 1 5
      2 1 5 2 5 1 1 6
      2 1 5 2 5 1 1 3
      4 3 5 2 5 1 1 6
      6 2 4 6 3 2 2 4
      1 2 6 1 5 2 2 6
      4 5 1 4 6 5 5 1
      6 5 1 2 1 5 5 4
      1 2 3 6 3 2 2 5
      1 2 3 4 3 2 2 6
      2 1 5 6 5 1 1 3
      6 5 1 5 1 2 2 4
      2 1 6 5 4 1 1 6
      2 1 5 6 2 5 1 5
      1 2 5 6 1 5 2 5
      2 3 4 3 2 4 6 4
      2 1 5 2 6 5 1 5
      6 5 1 6 2 1 5 1
      1 5 2 1 3 2 6 2
      2 6 5 3 5 1 6 1
      3 5 1 2 6 1 5 1
      3 1 5 1 4 5 2 5
      6 5 1 5 4 1 2 1
      1 3 6 1 6 5 1 4
      1 3 5 6 2 5 6 1
      2 6 5 2 5 6 2 3
      1 2 5 1 5 2 1 6
      2 1 5 2 5 1 2 6
      5 1 2 5 2 1 5 6
      5 1 2 5 2 6 5 3
      2 1 5 2 5 6 2 3
      6 4 2 6 2 3 6 1
      3 4 1 5 1 2 5 6
      1 5 6 1 2 5 1 6
      4 5 2 5 2 3 4 1
      6 4 1 6 3 1 6 1
      5 2 1 5 6 1 5 1
      1 2 5 1 4 5 1 5
      5 6 1 5 3 1 5 1
      4 1 6 4 3 6 4 6
      5 6 1 5 3 1 5 1
      5 3 1 5 2 1 5 1
      3 4 2 4 3 2 6 2
      1 3 5 1 5 6 1 6
      4 2 3 4 3 6 4 6
      1 4 5 1 5 2 1 2
      5 6 1 5 1 2 5 2
      2 5 3 6 3 4 6 4
      5 6 1 5 2 1 5 1
      4 3 1 4 6 1 4 1
      2 5 1 2 6 1 2 1
      2 6 5 2 1 5 2 5
      1 2 5 1 6 5 1 5
      2 6 3 2 4 3 2 3
      5 3 2 5 6 2 5 2
      6 2 3 2 3 4 6 4
      2 5 1 5 1 6 2 6
      6 1 5 1 5 2 6 2
      2 6 5 6 1 5 2 5
      2 1 5 1 6 5 2 5
      2 1 5 1 4 5 2 5
      6 4 1 4 2 1 3 1
      2 6 1 6 5 1 4 1
      5 2 3 1 5 2 1 5
      1 5 2 1 6 5 5 6
      5 1 6 3 5 1 1 5
      3 4 1 3 2 6 6 2
      3 6 1 5 3 6 6 3
      6 2 3 4 6 2 2 6
      1 5 2 6 1 5 5 1
      2 1 4 1 2 5 5 2
      3 1 4 1 3 5 5 3
      2 6 1 6 2 4 4 2
      6 5 4 5 6 1 1 6
      5 1 2 1 5 6 6 5
      5 6 1 6 5 2 2 5
      6 2 1 4 6 2 2 6
      1 2 4 5 1 2 2 1
      4 5 1 3 4 5 5 4
      1 5 2 6 1 5 5 1
      6 2 4 6 4 2 2 1
      5 1 2 6 2 1 1 5
      6 5 1 3 1 5 5 6
      6 5 1 2 1 5 5 4
      6 5 2 1 2 5 5 6
      1 2 5 3 5 2 2 1
      2 1 5 6 5 1 1 2
      5 6 1 2 1 6 6 5
      4 6 2 6 2 3 3 4
      6 4 2 4 6 3 1 6
      5 2 1 2 5 1 6 5
      5 2 1 2 5 1 3 5
      6 5 2 5 2 1 3 6
      2 1 5 1 5 6 3 2
      1 4 2 4 2 3 3 5
      2 3 6 1 2 6 3 6
      6 1 5 1 3 5 2 5
      5 2 6 5 1 2 5 1
      6 5 1 6 2 5 6 2
      2 4 1 6 2 4 6 2
      5 3 6 1 5 3 1 5
      1 3 4 1 6 5 1 6
      2 6 3 2 4 1 2 4
      4 3 6 1 4 5 1 4
      2 4 3 2 6 4 2 6
      5 6 2 5 1 6 5 1
      5 2 3 5 1 2 5 1
      2 5 6 5 1 3 2 1
      5 1 2 1 5 4 6 5
      1 5 6 5 1 4 2 1
      2 4 6 2 6 4 2 3
      6 2 3 6 3 4 6 1
      2 5 6 2 6 1 2 3
      6 2 5 1 5 2 6 4
      1 2 5 2 5 6 1 3
      1 6 2 1 5 4 1 5
      2 4 6 1 2 6 1 2
      1 4 2 5 1 2 5 1
      5 2 6 5 1 6 5 1
      1 2 6 1 5 6 1 5
      1 3 6 1 5 6 1 5
      1 2 4 1 6 4 1 6
      5 6 1 2 5 1 2 5
      5 2 1 6 5 1 6 5
      5 6 1 2 5 1 2 5
      1 6 5 6 1 4 2 1
      3 4 6 4 3 6 2 3
      4 3 6 3 4 6 1 4
      2 3 6 2 6 4 2 1
      6 5 2 4 2 1 4 6
      5 3 2 5 2 1 5 6
      1 6 5 2 5 3 2 1
      1 4 5 6 5 2 6 1
      2 3 1 2 6 1 2 5
      1 2 5 2 5 3 6 1
      2 6 4 6 4 3 1 2
      1 6 5 6 5 2 3 1
      4 6 1 2 3 6 6 3
      2 1 5 1 5 4 4 2
      3 6 2 6 4 1 3 1

      Comment


      • #4
        Here's how I proceeded:
        In the survey, the Decisions were coded:
        v_152 : c_0001 vs. c_0002
        v_154 : c_0003 vs c_0004
        v_155 : c_0005 vs c_0006
        v_156 : c_0001 vs c_0004
        v_157 : c_0002 vs c_0005
        v_158 : c_0003 vs c_0006
        v_159 : c_0001 vs c_0003
        v_160 : c_0002 vs c_0006

        because the c_00## were given Profile numbers randomly, I then coded the following variables to tell at which #Decision (D1, D2, [...] D8) which "Battle" occured:

        generate B1v2 = . //variable for battle between profile 1 and profile 2
        replace B1v2 = 1 if c_0007 == 1 & c_0008 == 2 | c_0007 == 2 & c_0008 == 1 //1v2 in D1
        replace B1v2 = 2 if c_0009 == 1 & c_0010 == 2 | c_0009 == 2 & c_0010 == 1 //1v2 in D2
        replace B1v2 = 3 if c_0011 == 1 & c_0012 == 2 | c_0011 == 2 & c_0012 == 1 // etc
        replace B1v2 = 4 if c_0007 == 1 & c_0010 == 2 | c_0007 == 2 & c_0010 == 1
        replace B1v2 = 5 if c_0008 == 1 & c_0011 == 2 | c_0008 == 2 & c_0011 == 1
        replace B1v2 = 6 if c_0009 == 1 & c_0012 == 2 | c_0009 == 2 & c_0012 == 1
        replace B1v2 = 7 if c_0007 == 1 & c_0009 == 2 | c_0007 == 2 & c_0009 == 1
        replace B1v2 = 8 if c_0008 == 1 & c_0012 == 2 | c_0008 == 2 & c_0012 == 1


        generate B1v3 = .
        replace B1v3 = 1 if c_0007 == 1 & c_0008 == 3 | c_0007 == 3 & c_0008 == 1 //1v3 in D1
        replace B1v3 = 2 if c_0009 == 1 & c_0010 == 3 | c_0009 == 3 & c_0010 == 1 //1v3 in D2
        replace B1v3 = 3 if c_0011 == 1 & c_0012 == 3 | c_0011 == 3 & c_0012 == 1 // etc
        replace B1v3 = 4 if c_0007 == 1 & c_0010 == 3 | c_0007 == 3 & c_0010 == 1
        replace B1v3 = 5 if c_0008 == 1 & c_0011 == 3 | c_0008 == 3 & c_0011 == 1
        replace B1v3 = 6 if c_0009 == 1 & c_0012 == 3 | c_0009 == 3 & c_0012 == 1
        replace B1v3 = 7 if c_0007 == 1 & c_0009 == 3 | c_0007 == 3 & c_0009 == 1
        replace B1v3 = 8 if c_0008 == 1 & c_0012 == 3 | c_0008 == 3 & c_0012 == 1


        generate B1v4 = .
        replace B1v4 = 1 if c_0007 == 1 & c_0008 == 4 | c_0007 == 4 & c_0008 == 1 //1v4 in D1
        replace B1v4 = 2 if c_0009 == 1 & c_0010 == 4 | c_0009 == 4 & c_0010 == 1 //1v4 in D2
        replace B1v4 = 3 if c_0011 == 1 & c_0012 == 4 | c_0011 == 4 & c_0012 == 1 // etc
        replace B1v4 = 4 if c_0007 == 1 & c_0010 == 4 | c_0007 == 4 & c_0010 == 1
        replace B1v4 = 5 if c_0008 == 1 & c_0011 == 4 | c_0008 == 4 & c_0011 == 1
        replace B1v4 = 6 if c_0009 == 1 & c_0012 == 4 | c_0009 == 4 & c_0012 == 1
        replace B1v4 = 7 if c_0007 == 1 & c_0009 == 4 | c_0007 == 4 & c_0009 == 1
        replace B1v4 = 8 if c_0008 == 1 & c_0012 == 4 | c_0008 == 4 & c_0012 == 1


        generate B1v5 = .
        replace B1v5 = 1 if c_0007 == 1 & c_0008 == 5 | c_0007 == 5 & c_0008 == 1 //1v5 in D1
        replace B1v5 = 2 if c_0009 == 1 & c_0010 == 5 | c_0009 == 5 & c_0010 == 1 //1v5 in D2
        replace B1v5 = 3 if c_0011 == 1 & c_0012 == 5 | c_0011 == 5 & c_0012 == 1 // etc
        replace B1v5 = 4 if c_0007 == 1 & c_0010 == 5 | c_0007 == 5 & c_0010 == 1
        replace B1v5 = 5 if c_0008 == 1 & c_0011 == 5 | c_0008 == 5 & c_0011 == 1
        replace B1v5 = 6 if c_0009 == 1 & c_0012 == 5 | c_0009 == 5 & c_0012 == 1
        replace B1v5 = 7 if c_0007 == 1 & c_0009 == 5 | c_0007 == 5 & c_0009 == 1
        replace B1v5 = 8 if c_0008 == 1 & c_0012 == 5 | c_0008 == 5 & c_0012 == 1


        generate B1v6 = .
        replace B1v6 = 1 if c_0007 == 1 & c_0008 == 6 | c_0007 == 6 & c_0008 == 1 //1v6 in D1
        replace B1v6 = 2 if c_0009 == 1 & c_0010 == 6 | c_0009 == 6 & c_0010 == 1 //1v6 in D2
        replace B1v6 = 3 if c_0011 == 1 & c_0012 == 6 | c_0011 == 6 & c_0012 == 1 // etc
        replace B1v6 = 4 if c_0007 == 1 & c_0010 == 6 | c_0007 == 6 & c_0010 == 1
        replace B1v6 = 5 if c_0008 == 1 & c_0011 == 6 | c_0008 == 6 & c_0011 == 1
        replace B1v6 = 6 if c_0009 == 1 & c_0012 == 6 | c_0009 == 6 & c_0012 == 1
        replace B1v6 = 7 if c_0007 == 1 & c_0009 == 6 | c_0007 == 6 & c_0009 == 1
        replace B1v6 = 8 if c_0008 == 1 & c_0012 == 6 | c_0008 == 6 & c_0012 == 1


        generate B2v3 = .
        replace B2v3 = 1 if c_0007 == 2 & c_0008 == 3 | c_0007 == 3 & c_0008 == 2 //2v3 in D1
        replace B2v3 = 2 if c_0009 == 2 & c_0010 == 3 | c_0009 == 3 & c_0010 == 2 //2v3 in D2
        replace B2v3 = 3 if c_0011 == 2 & c_0012 == 3 | c_0011 == 3 & c_0012 == 2 // etc
        replace B2v3 = 4 if c_0007 == 2 & c_0010 == 3 | c_0007 == 3 & c_0010 == 2
        replace B2v3 = 5 if c_0008 == 2 & c_0011 == 3 | c_0008 == 3 & c_0011 == 2
        replace B2v3 = 6 if c_0009 == 2 & c_0012 == 3 | c_0009 == 3 & c_0012 == 2
        replace B2v3 = 7 if c_0007 == 2 & c_0009 == 3 | c_0007 == 3 & c_0009 == 2
        replace B2v3 = 8 if c_0008 == 2 & c_0012 == 3 | c_0008 == 3 & c_0012 == 2


        generate B2v4 = .
        replace B2v4 = 1 if c_0007 == 2 & c_0008 == 4 | c_0007 == 4 & c_0008 == 2 //2v4 in D1
        replace B2v4 = 2 if c_0009 == 2 & c_0010 == 4 | c_0009 == 4 & c_0010 == 2 //2v4 in D2
        replace B2v4 = 3 if c_0011 == 2 & c_0012 == 4 | c_0011 == 4 & c_0012 == 2 // etc
        replace B2v4 = 4 if c_0007 == 2 & c_0010 == 4 | c_0007 == 4 & c_0010 == 2
        replace B2v4 = 5 if c_0008 == 2 & c_0011 == 4 | c_0008 == 4 & c_0011 == 2
        replace B2v4 = 6 if c_0009 == 2 & c_0012 == 4 | c_0009 == 4 & c_0012 == 2
        replace B2v4 = 7 if c_0007 == 2 & c_0009 == 4 | c_0007 == 4 & c_0009 == 2
        replace B2v4 = 8 if c_0008 == 2 & c_0012 == 4 | c_0008 == 4 & c_0012 == 2


        generate B2v5 = .
        replace B2v4 = 1 if c_0007 == 2 & c_0008 == 5 | c_0007 == 5 & c_0008 == 2 //2v5 in D1
        replace B2v4 = 2 if c_0009 == 2 & c_0010 == 5 | c_0009 == 5 & c_0010 == 2 //2v5 in D2
        replace B2v4 = 3 if c_0011 == 2 & c_0012 == 5 | c_0011 == 5 & c_0012 == 2 // etc
        replace B2v4 = 4 if c_0007 == 2 & c_0010 == 5 | c_0007 == 5 & c_0010 == 2
        replace B2v4 = 5 if c_0008 == 2 & c_0011 == 5 | c_0008 == 5 & c_0011 == 2
        replace B2v4 = 6 if c_0009 == 2 & c_0012 == 5 | c_0009 == 5 & c_0012 == 2
        replace B2v4 = 7 if c_0007 == 2 & c_0009 == 5 | c_0007 == 5 & c_0009 == 2
        replace B2v4 = 8 if c_0008 == 2 & c_0012 == 5 | c_0008 == 5 & c_0012 == 2


        generate B2v6 = .
        replace B2v6 = 1 if c_0007 == 2 & c_0008 == 6 | c_0007 == 6 & c_0008 == 2 //2v6 in D1
        replace B2v6 = 2 if c_0009 == 2 & c_0010 == 6 | c_0009 == 6 & c_0010 == 2 //2v6 in D2
        replace B2v6 = 3 if c_0011 == 2 & c_0012 == 6 | c_0011 == 6 & c_0012 == 2 // etc
        replace B2v6 = 4 if c_0007 == 2 & c_0010 == 6 | c_0007 == 6 & c_0010 == 2
        replace B2v6 = 5 if c_0008 == 2 & c_0011 == 6 | c_0008 == 6 & c_0011 == 2
        replace B2v6 = 6 if c_0009 == 2 & c_0012 == 6 | c_0009 == 6 & c_0012 == 2
        replace B2v6 = 7 if c_0007 == 2 & c_0009 == 6 | c_0007 == 6 & c_0009 == 2
        replace B2v6 = 8 if c_0008 == 2 & c_0012 == 6 | c_0008 == 6 & c_0012 == 2


        generate B3v4 = .
        replace B3v4 = 1 if c_0007 == 3 & c_0008 == 4 | c_0007 == 4 & c_0008 == 3 //3v4 in D1
        replace B3v4 = 2 if c_0009 == 3 & c_0010 == 4 | c_0009 == 4 & c_0010 == 3 //3v4 in D2
        replace B3v4 = 3 if c_0011 == 3 & c_0012 == 4 | c_0011 == 4 & c_0012 == 3 // etc
        replace B3v4 = 4 if c_0007 == 3 & c_0010 == 4 | c_0007 == 4 & c_0010 == 3
        replace B3v4 = 5 if c_0008 == 3 & c_0011 == 4 | c_0008 == 4 & c_0011 == 3
        replace B3v4 = 6 if c_0009 == 3 & c_0012 == 4 | c_0009 == 4 & c_0012 == 3
        replace B3v4 = 7 if c_0007 == 3 & c_0009 == 4 | c_0007 == 4 & c_0009 == 3
        replace B3v4 = 8 if c_0008 == 3 & c_0012 == 4 | c_0008 == 4 & c_0012 == 3


        generate B3v5 = .
        replace B3v5 = 1 if c_0007 == 3 & c_0008 == 5 | c_0007 == 5 & c_0008 == 3 //3v5 in D1
        replace B3v5 = 2 if c_0009 == 3 & c_0010 == 5 | c_0009 == 5 & c_0010 == 3 //3v5 in D2
        replace B3v5 = 3 if c_0011 == 3 & c_0012 == 5 | c_0011 == 5 & c_0012 == 3 // etc
        replace B3v5 = 4 if c_0007 == 3 & c_0010 == 5 | c_0007 == 5 & c_0010 == 3
        replace B3v5 = 5 if c_0008 == 3 & c_0011 == 5 | c_0008 == 5 & c_0011 == 3
        replace B3v5 = 6 if c_0009 == 3 & c_0012 == 5 | c_0009 == 5 & c_0012 == 3
        replace B3v5 = 7 if c_0007 == 3 & c_0009 == 5 | c_0007 == 5 & c_0009 == 3
        replace B3v5 = 8 if c_0008 == 3 & c_0012 == 5 | c_0008 == 5 & c_0012 == 3


        generate B3v6 = .
        replace B3v6 = 1 if c_0007 == 3 & c_0008 == 6 | c_0007 == 6 & c_0008 == 3 //3v6 in D1
        replace B3v6 = 2 if c_0009 == 3 & c_0010 == 6 | c_0009 == 6 & c_0010 == 3 //3v6 in D2
        replace B3v6 = 3 if c_0011 == 3 & c_0012 == 6 | c_0011 == 6 & c_0012 == 3 // etc
        replace B3v6 = 4 if c_0007 == 3 & c_0010 == 6 | c_0007 == 6 & c_0010 == 3
        replace B3v6 = 5 if c_0008 == 3 & c_0011 == 6 | c_0008 == 6 & c_0011 == 3
        replace B3v6 = 6 if c_0009 == 3 & c_0012 == 6 | c_0009 == 6 & c_0012 == 3
        replace B3v6 = 7 if c_0007 == 3 & c_0009 == 6 | c_0007 == 6 & c_0009 == 3
        replace B3v6 = 8 if c_0008 == 3 & c_0012 == 6 | c_0008 == 6 & c_0012 == 3


        generate B4v5 = .
        replace B4v5 = 1 if c_0007 == 4 & c_0008 == 5 | c_0007 == 5 & c_0008 == 4 //4v5 in D1
        replace B4v5 = 2 if c_0009 == 4 & c_0010 == 5 | c_0009 == 5 & c_0010 == 4 //4v5 in D2
        replace B4v5 = 3 if c_0011 == 4 & c_0012 == 5 | c_0011 == 5 & c_0012 == 4 // etc
        replace B4v5 = 4 if c_0007 == 4 & c_0010 == 5 | c_0007 == 5 & c_0010 == 4
        replace B4v5 = 5 if c_0008 == 4 & c_0011 == 5 | c_0008 == 5 & c_0011 == 4
        replace B4v5 = 6 if c_0009 == 4 & c_0012 == 5 | c_0009 == 5 & c_0012 == 4
        replace B4v5 = 7 if c_0007 == 4 & c_0009 == 5 | c_0007 == 5 & c_0009 == 4
        replace B4v5 = 8 if c_0008 == 4 & c_0012 == 5 | c_0008 == 5 & c_0012 == 4


        generate B4v6 = .
        replace B4v6 = 1 if c_0007 == 4 & c_0008 == 6 | c_0007 == 6 & c_0008 == 4 //4v6 in D1
        replace B4v6 = 2 if c_0009 == 4 & c_0010 == 6 | c_0009 == 6 & c_0010 == 4 //4v6 in D2
        replace B4v6 = 3 if c_0011 == 4 & c_0012 == 6 | c_0011 == 6 & c_0012 == 4 // etc
        replace B4v6 = 4 if c_0007 == 4 & c_0010 == 6 | c_0007 == 6 & c_0010 == 4
        replace B4v6 = 5 if c_0008 == 4 & c_0011 == 6 | c_0008 == 6 & c_0011 == 4
        replace B4v6 = 6 if c_0009 == 4 & c_0012 == 6 | c_0009 == 6 & c_0012 == 4
        replace B4v6 = 7 if c_0007 == 4 & c_0009 == 6 | c_0007 == 6 & c_0009 == 4
        replace B4v6 = 8 if c_0008 == 4 & c_0012 == 6 | c_0008 == 6 & c_0012 == 4


        generate B5v6 = .
        replace B5v6 = 1 if c_0007 == 5 & c_0008 == 6 | c_0007 == 6 & c_0008 == 5 //5v6 in D1
        replace B5v6 = 2 if c_0009 == 5 & c_0010 == 6 | c_0009 == 6 & c_0010 == 5 //5v6 in D2
        replace B5v6 = 3 if c_0011 == 5 & c_0012 == 6 | c_0011 == 6 & c_0012 == 5 // etc
        replace B5v6 = 4 if c_0007 == 5 & c_0010 == 6 | c_0007 == 6 & c_0010 == 5
        replace B5v6 = 5 if c_0008 == 5 & c_0011 == 6 | c_0008 == 6 & c_0011 == 5
        replace B5v6 = 6 if c_0009 == 5 & c_0012 == 6 | c_0009 == 6 & c_0012 == 5
        replace B5v6 = 7 if c_0007 == 5 & c_0009 == 6 | c_0007 == 6 & c_0009 == 5
        replace B5v6 = 8 if c_0008 == 5 & c_0012 == 6 | c_0008 == 6 & c_0012 == 5


        Then I created other variables, to sort the battles after the profiles demographic property, in this case age

        ********************BATTLES AGE*********************************************** ********
        ************************************************** ************************************
        **BATTLE YOUNG VS OLD

        generate BYvO = .
        label variable BYvO "Young vs Old Profile"
        label define BYvOLabel 1 "Young Profile" 2 "Old Profile"
        label value BYvO BYvOLabel

        replace BYvO = 1 if B1v3 == 1 & v_152 == 3 //if Profile 3 is chosen in B1v3
        replace BYvO = 1 if B1v3 == 2 & v_154 == 3
        replace BYvO = 1 if B1v3 == 3 & v_155 == 3
        replace BYvO = 1 if B1v3 == 4 & v_156 == 3
        replace BYvO = 1 if B1v3 == 5 & v_157 == 3
        replace BYvO = 1 if B1v3 == 6 & v_158 == 3
        replace BYvO = 1 if B1v3 == 7 & v_159 == 3
        replace BYvO = 1 if B1v3 == 8 & v_160 == 3

        replace BYvO = 2 if B1v3 == 1 & v_152 == 1 //if Profile 3 is chosen in B1v3
        replace BYvO = 2 if B1v3 == 2 & v_154 == 1
        replace BYvO = 2 if B1v3 == 3 & v_155 == 1
        replace BYvO = 2 if B1v3 == 4 & v_156 == 1
        replace BYvO = 2 if B1v3 == 5 & v_157 == 1
        replace BYvO = 2 if B1v3 == 6 & v_158 == 1
        replace BYvO = 2 if B1v3 == 7 & v_159 == 1
        replace BYvO = 2 if B1v3 == 8 & v_160 == 1


        replace BYvO = 1 if B1v4 == 1 & v_152 == 4 //if Profile 4 is chosen in B1v4
        replace BYvO = 1 if B1v4 == 2 & v_154 == 4
        replace BYvO = 1 if B1v4 == 3 & v_155 == 4
        replace BYvO = 1 if B1v4 == 4 & v_156 == 4
        replace BYvO = 1 if B1v4 == 5 & v_157 == 4
        replace BYvO = 1 if B1v4 == 6 & v_158 == 4
        replace BYvO = 1 if B1v4 == 7 & v_159 == 4
        replace BYvO = 1 if B1v4 == 8 & v_160 == 4

        replace BYvO = 2 if B1v4 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v4
        replace BYvO = 2 if B1v4 == 2 & v_154 == 1
        replace BYvO = 2 if B1v4 == 3 & v_155 == 1
        replace BYvO = 2 if B1v4 == 4 & v_156 == 1
        replace BYvO = 2 if B1v4 == 5 & v_157 == 1
        replace BYvO = 2 if B1v4 == 6 & v_158 == 1
        replace BYvO = 2 if B1v4 == 7 & v_159 == 1
        replace BYvO = 2 if B1v4 == 8 & v_160 == 1


        replace BYvO = 1 if B3v5 == 1 & v_152 == 3 //if Profile 3 is chosen in B3v5
        replace BYvO = 1 if B3v5 == 2 & v_154 == 3
        replace BYvO = 1 if B3v5 == 3 & v_155 == 3
        replace BYvO = 1 if B3v5 == 4 & v_156 == 3
        replace BYvO = 1 if B3v5 == 5 & v_157 == 3
        replace BYvO = 1 if B3v5 == 6 & v_158 == 3
        replace BYvO = 1 if B3v5 == 7 & v_159 == 3
        replace BYvO = 1 if B3v5 == 8 & v_160 == 3

        replace BYvO = 2 if B3v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B3v5
        replace BYvO = 2 if B3v5 == 2 & v_154 == 5
        replace BYvO = 2 if B3v5 == 3 & v_155 == 5
        replace BYvO = 2 if B3v5 == 4 & v_156 == 5
        replace BYvO = 2 if B3v5 == 5 & v_157 == 5
        replace BYvO = 2 if B3v5 == 6 & v_158 == 5
        replace BYvO = 2 if B3v5 == 7 & v_159 == 5
        replace BYvO = 2 if B3v5 == 8 & v_160 == 5


        replace BYvO = 1 if B4v5 == 1 & v_152 == 4 //if Profile 4 is chosen in B4v5
        replace BYvO = 1 if B4v5 == 2 & v_154 == 4
        replace BYvO = 1 if B4v5 == 3 & v_155 == 4
        replace BYvO = 1 if B4v5 == 4 & v_156 == 4
        replace BYvO = 1 if B4v5 == 5 & v_157 == 4
        replace BYvO = 1 if B4v5 == 6 & v_158 == 4
        replace BYvO = 1 if B4v5 == 7 & v_159 == 4
        replace BYvO = 1 if B4v5 == 8 & v_160 == 4

        replace BYvO = 2 if B4v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B4v5
        replace BYvO = 2 if B4v5 == 2 & v_154 == 5
        replace BYvO = 2 if B4v5 == 3 & v_155 == 5
        replace BYvO = 2 if B4v5 == 4 & v_156 == 5
        replace BYvO = 2 if B4v5 == 5 & v_157 == 5
        replace BYvO = 2 if B4v5 == 6 & v_158 == 5
        replace BYvO = 2 if B4v5 == 7 & v_159 == 5
        replace BYvO = 2 if B4v5 == 8 & v_160 == 5



        ***BATTLES YOUNG VS MIDDLE**************

        generate BYvM = .
        label variable BYvM "Young Profile vs Midage Profile"
        label define BYvMLabel 1 "Young Profile" 2 "Midage Profile"
        label value BYvM BYvMLabel

        replace BYvM = 1 if B2v3 == 1 & v_152 == 3 //if Profile 3 is chosen in B2v3
        replace BYvM = 1 if B2v3 == 2 & v_154 == 3
        replace BYvM = 1 if B2v3 == 3 & v_155 == 3
        replace BYvM = 1 if B2v3 == 4 & v_156 == 3
        replace BYvM = 1 if B2v3 == 5 & v_157 == 3
        replace BYvM = 1 if B2v3 == 6 & v_158 == 3
        replace BYvM = 1 if B2v3 == 7 & v_159 == 3
        replace BYvM = 1 if B2v3 == 8 & v_160 == 3

        replace BYvM = 2 if B2v3 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v3
        replace BYvM = 2 if B2v3 == 2 & v_154 == 2
        replace BYvM = 2 if B2v3 == 3 & v_155 == 2
        replace BYvM = 2 if B2v3 == 4 & v_156 == 2
        replace BYvM = 2 if B2v3 == 5 & v_157 == 2
        replace BYvM = 2 if B2v3 == 6 & v_158 == 2
        replace BYvM = 2 if B2v3 == 7 & v_159 == 2
        replace BYvM = 2 if B2v3 == 8 & v_160 == 2


        replace BYvM = 1 if B3v6 == 1 & v_152 == 3 //if Profile 3 is chosen in B3v6
        replace BYvM = 1 if B3v6 == 2 & v_154 == 3
        replace BYvM = 1 if B3v6 == 3 & v_155 == 3
        replace BYvM = 1 if B3v6 == 4 & v_156 == 3
        replace BYvM = 1 if B3v6 == 5 & v_157 == 3
        replace BYvM = 1 if B3v6 == 6 & v_158 == 3
        replace BYvM = 1 if B3v6 == 7 & v_159 == 3
        replace BYvM = 1 if B3v6 == 8 & v_160 == 3

        replace BYvM = 2 if B3v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B3v6
        replace BYvM = 2 if B3v6 == 2 & v_154 == 6
        replace BYvM = 2 if B3v6 == 3 & v_155 == 6
        replace BYvM = 2 if B3v6 == 4 & v_156 == 6
        replace BYvM = 2 if B3v6 == 5 & v_157 == 6
        replace BYvM = 2 if B3v6 == 6 & v_158 == 6
        replace BYvM = 2 if B3v6 == 7 & v_159 == 6
        replace BYvM = 2 if B3v6 == 8 & v_160 == 6


        replace BYvM = 1 if B2v4 == 1 & v_152 == 4 //if Profile 4 is chosen in B2v4
        replace BYvM = 1 if B2v4 == 2 & v_154 == 4
        replace BYvM = 1 if B2v4 == 3 & v_155 == 4
        replace BYvM = 1 if B2v4 == 4 & v_156 == 4
        replace BYvM = 1 if B2v4 == 5 & v_157 == 4
        replace BYvM = 1 if B2v4 == 6 & v_158 == 4
        replace BYvM = 1 if B2v4 == 7 & v_159 == 4
        replace BYvM = 1 if B2v4 == 8 & v_160 == 4

        replace BYvM = 2 if B2v4 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v4
        replace BYvM = 2 if B2v4 == 2 & v_154 == 2
        replace BYvM = 2 if B2v4 == 3 & v_155 == 2
        replace BYvM = 2 if B2v4 == 4 & v_156 == 2
        replace BYvM = 2 if B2v4 == 5 & v_157 == 2
        replace BYvM = 2 if B2v4 == 6 & v_158 == 2
        replace BYvM = 2 if B2v4 == 7 & v_159 == 2
        replace BYvM = 2 if B2v4 == 8 & v_160 == 2


        replace BYvM = 1 if B4v6 == 1 & v_152 == 4 //if Profile 4 is chosen in B4v6
        replace BYvM = 1 if B4v6 == 2 & v_154 == 4
        replace BYvM = 1 if B4v6 == 3 & v_155 == 4
        replace BYvM = 1 if B4v6 == 4 & v_156 == 4
        replace BYvM = 1 if B4v6 == 5 & v_157 == 4
        replace BYvM = 1 if B4v6 == 6 & v_158 == 4
        replace BYvM = 1 if B4v6 == 7 & v_159 == 4
        replace BYvM = 1 if B4v6 == 8 & v_160 == 4

        replace BYvM = 2 if B4v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B4v6
        replace BYvM = 2 if B4v6 == 2 & v_154 == 6
        replace BYvM = 2 if B4v6 == 3 & v_155 == 6
        replace BYvM = 2 if B4v6 == 4 & v_156 == 6
        replace BYvM = 2 if B4v6 == 5 & v_157 == 6
        replace BYvM = 2 if B4v6 == 6 & v_158 == 6
        replace BYvM = 2 if B4v6 == 7 & v_159 == 6
        replace BYvM = 2 if B4v6 == 8 & v_160 == 6

        **********MIDDLE VS OLD***************************
        generate BMvO = .
        label variable BMvO "Midage Profile vs Old Profile"
        label define BMvOLabel 1 "Midage Profile" 2 "Old Profile"
        label value BMvO BMvOLabel

        replace BMvO = 1 if B1v2 == 1 & v_152 == 2 //if Profile 2 is chosen in B1v2
        replace BMvO = 1 if B1v2 == 2 & v_154 == 2
        replace BMvO = 1 if B1v2 == 3 & v_155 == 2
        replace BMvO = 1 if B1v2 == 4 & v_156 == 2
        replace BMvO = 1 if B1v2 == 5 & v_157 == 2
        replace BMvO = 1 if B1v2 == 6 & v_158 == 2
        replace BMvO = 1 if B1v2 == 7 & v_159 == 2
        replace BMvO = 1 if B1v2 == 8 & v_160 == 2

        replace BMvO = 2 if B1v2 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v2
        replace BMvO = 2 if B1v2 == 2 & v_154 == 1
        replace BMvO = 2 if B1v2 == 3 & v_155 == 1
        replace BMvO = 2 if B1v2 == 4 & v_156 == 1
        replace BMvO = 2 if B1v2 == 5 & v_157 == 1
        replace BMvO = 2 if B1v2 == 6 & v_158 == 1
        replace BMvO = 2 if B1v2 == 7 & v_159 == 1
        replace BMvO = 2 if B1v2 == 8 & v_160 == 1


        replace BMvO = 1 if B2v5 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v5
        replace BMvO = 1 if B2v5 == 2 & v_154 == 2
        replace BMvO = 1 if B2v5 == 3 & v_155 == 2
        replace BMvO = 1 if B2v5 == 4 & v_156 == 2
        replace BMvO = 1 if B2v5 == 5 & v_157 == 2
        replace BMvO = 1 if B2v5 == 6 & v_158 == 2
        replace BMvO = 1 if B2v5 == 7 & v_159 == 2
        replace BMvO = 1 if B2v5 == 8 & v_160 == 2

        replace BMvO = 2 if B2v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B2v5
        replace BMvO = 2 if B2v5 == 2 & v_154 == 5
        replace BMvO = 2 if B2v5 == 3 & v_155 == 5
        replace BMvO = 2 if B2v5 == 4 & v_156 == 5
        replace BMvO = 2 if B2v5 == 5 & v_157 == 5
        replace BMvO = 2 if B2v5 == 6 & v_158 == 5
        replace BMvO = 2 if B2v5 == 7 & v_159 == 5
        replace BMvO = 2 if B2v5 == 8 & v_160 == 5


        replace BMvO = 1 if B1v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B1v6
        replace BMvO = 1 if B1v6 == 2 & v_154 == 6
        replace BMvO = 1 if B1v6 == 3 & v_155 == 6
        replace BMvO = 1 if B1v6 == 4 & v_156 == 6
        replace BMvO = 1 if B1v6 == 5 & v_157 == 6
        replace BMvO = 1 if B1v6 == 6 & v_158 == 6
        replace BMvO = 1 if B1v6 == 7 & v_159 == 6
        replace BMvO = 1 if B1v6 == 8 & v_160 == 6

        replace BMvO = 2 if B1v6 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v6
        replace BMvO = 2 if B1v6 == 2 & v_154 == 1
        replace BMvO = 2 if B1v6 == 3 & v_155 == 1
        replace BMvO = 2 if B1v6 == 4 & v_156 == 1
        replace BMvO = 2 if B1v6 == 5 & v_157 == 1
        replace BMvO = 2 if B1v6 == 6 & v_158 == 1
        replace BMvO = 2 if B1v6 == 7 & v_159 == 1
        replace BMvO = 2 if B1v6 == 8 & v_160 == 1


        replace BMvO = 1 if B5v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B5v6
        replace BMvO = 1 if B5v6 == 2 & v_154 == 6
        replace BMvO = 1 if B5v6 == 3 & v_155 == 6
        replace BMvO = 1 if B5v6 == 4 & v_156 == 6
        replace BMvO = 1 if B5v6 == 5 & v_157 == 6
        replace BMvO = 1 if B5v6 == 6 & v_158 == 6
        replace BMvO = 1 if B5v6 == 7 & v_159 == 6
        replace BMvO = 1 if B5v6 == 8 & v_160 == 6

        replace BMvO = 2 if B5v6 == 1 & v_152 == 5 //if Profile 5 is chosen in B5v6
        replace BMvO = 2 if B5v6 == 2 & v_154 == 5
        replace BMvO = 2 if B5v6 == 3 & v_155 == 5
        replace BMvO = 2 if B5v6 == 4 & v_156 == 5
        replace BMvO = 2 if B5v6 == 5 & v_157 == 5
        replace BMvO = 2 if B5v6 == 6 & v_158 == 5
        replace BMvO = 2 if B5v6 == 7 & v_159 == 5
        replace BMvO = 2 if B5v6 == 8 & v_160 == 5


        And I would like to present these three last generated variables, BYvO, BYvM and BMvO if possible in a combined stacked bar chart like I wrote in the first post, because I have several other Profile properties which I also need to involve in my work, so I would like to keep each individual property as dense and clean as possible, especially descriptive properties like age.

        Comment


        • #5
          Thanks for #4 and #5. I can't say that I absorbed much of it, but this may get you closer to where you want to be.

          catplot is from SSC, as you are asked to explain (FAQ Advice #12).


          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(BYvO BYvM BMvO)
          . 2 1
          2 2 2
          2 2 2
          2 2 1
          2 2 2
          . 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          1 1 1
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          1 2 1
          2 2 1
          2 1 2
          2 2 2
          2 2 1
          1 2 1
          2 2 2
          2 2 2
          . 2 2
          2 2 2
          2 2 .
          1 1 1
          2 2 2
          2 2 2
          2 2 2
          . 2 2
          2 2 2
          2 1 2
          2 2 2
          1 2 .
          2 2 2
          2 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          1 2 1
          2 2 2
          2 2 2
          2 1 2
          1 2 1
          2 2 2
          2 . 2
          2 . 2
          1 2 1
          2 . 2
          2 1 2
          1 1 1
          2 2 2
          1 2 1
          2 1 2
          2 2 2
          1 1 1
          2 2 2
          1 1 2
          2 2 2
          2 2 .
          2 2 2
          1 2 1
          2 2 1
          1 . 1
          2 2 2
          2 2 2
          2 2 .
          2 2 2
          2 1 2
          2 1 2
          2 2 2
          2 2 2
          2 2 2
          2 . 2
          . 1 1
          2 2 1
          1 2 1
          2 2 2
          2 1 2
          . 1 2
          1 2 1
          2 2 2
          2 2 2
          2 2 .
          1 2 1
          2 2 2
          2 1 2
          2 2 2
          1 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 .
          2 2 2
          2 2 2
          2 2 .
          1 2 1
          1 2 1
          2 2 2
          2 2 2
          2 2 1
          2 2 2
          1 2 2
          1 2 .
          2 2 2
          2 2 2
          2 2 1
          1 2 1
          2 2 2
          1 2 2
          1 2 1
          1 1 .
          1 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          1 2 1
          1 2 1
          2 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 1
          2 2 2
          2 2 2
          2 2 2
          2 2 2
          1 2 1
          2 2 .
          2 2 2
          2 2 .
          2 2 2
          1 2 1
          1 1 1
          1 2 1
          1 2 1
          2 . 2
          2 2 2
          . 2 2
          2 2 1
          2 2 2
          1 1 1
          2 2 2
          1 2 1
          2 1 2
          1 1 1
          end
          label values BYvO BYvOLabel
          label def BYvOLabel 1 "Young Profile", modify
          label def BYvOLabel 2 "Old Profile", modify
          label values BYvM BYvMLabel
          label def BYvMLabel 1 "Young Profile", modify
          label def BYvMLabel 2 "Midage Profile", modify
          label values BMvO BMvOLabel
          label def BMvOLabel 1 "Midage Profile", modify
          label def BMvOLabel 2 "Old Profile", modify
          
          gen y1 = cond(BYvO == 2, 3, BYvO)
          gen y2 = BYvM 
          gen y3 = BMvO + 1 
          
          gen id = _n 
          
          reshape long y, i(id) j(which)
          label def y 1 "Young" 2 "Midage" 3 "Old"
          label def which 1 "Young versus Old" 2 "Young versus Midage" 3 "Midage versus Old"
          label val y y 
          label val which which 
          
          set scheme s1color 
          catplot y, over(which) l1title("Profile") percent(which) stack asyvars bar(1, blcolor(red) bfcolor(red*0.2)) bar(3, blcolor(black) bfcolor(gs12))  bar(2, blcolor(blue) bfcolor(blue*0.2)) legend(row(1))
          Click image for larger version

Name:	catplot.png
Views:	1
Size:	22.4 KB
ID:	1617930

          Comment


          • #6
            Nick Cox You are truly a legend - thank you so much sir, that is exactly what I meant!

            How do I apply that to other variables? I'd love to understand you're coding -

            Most importantly for political ideology:


            generate BLvR = .
            label variable BLvR "Left vs Right Profile"
            label define BLvRLabel 1 "Left Profile" 2 "Right Profile"
            label value BLvR BLvRLabel

            replace BLvR = 1 if B1v2 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v2
            replace BLvR = 1 if B1v2 == 2 & v_154 == 1
            replace BLvR = 1 if B1v2 == 3 & v_155 == 1
            replace BLvR = 1 if B1v2 == 4 & v_156 == 1
            replace BLvR = 1 if B1v2 == 5 & v_157 == 1
            replace BLvR = 1 if B1v2 == 6 & v_158 == 1
            replace BLvR = 1 if B1v2 == 7 & v_159 == 1
            replace BLvR = 1 if B1v2 == 8 & v_160 == 1

            replace BLvR = 2 if B1v2 == 1 & v_152 == 2 //if Profile 2 is chosen in B1v2
            replace BLvR = 2 if B1v2 == 2 & v_154 == 2
            replace BLvR = 2 if B1v2 == 3 & v_155 == 2
            replace BLvR = 2 if B1v2 == 4 & v_156 == 2
            replace BLvR = 2 if B1v2 == 5 & v_157 == 2
            replace BLvR = 2 if B1v2 == 6 & v_158 == 2
            replace BLvR = 2 if B1v2 == 7 & v_159 == 2
            replace BLvR = 2 if B1v2 == 8 & v_160 == 2


            replace BLvR = 1 if B1v5 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v5
            replace BLvR = 1 if B1v5 == 2 & v_154 == 1
            replace BLvR = 1 if B1v5 == 3 & v_155 == 1
            replace BLvR = 1 if B1v5 == 4 & v_156 == 1
            replace BLvR = 1 if B1v5 == 5 & v_157 == 1
            replace BLvR = 1 if B1v5 == 6 & v_158 == 1
            replace BLvR = 1 if B1v5 == 7 & v_159 == 1
            replace BLvR = 1 if B1v5 == 8 & v_160 == 1

            replace BLvR = 2 if B1v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B1v5
            replace BLvR = 2 if B1v5 == 2 & v_154 == 5
            replace BLvR = 2 if B1v5 == 3 & v_155 == 5
            replace BLvR = 2 if B1v5 == 4 & v_156 == 5
            replace BLvR = 2 if B1v5 == 5 & v_157 == 5
            replace BLvR = 2 if B1v5 == 6 & v_158 == 5
            replace BLvR = 2 if B1v5 == 7 & v_159 == 5
            replace BLvR = 2 if B1v5 == 8 & v_160 == 5


            replace BLvR = 1 if B2v4 == 1 & v_152 == 4 //if Profile 4 is chosen in B2v4
            replace BLvR = 1 if B2v4 == 2 & v_154 == 4
            replace BLvR = 1 if B2v4 == 3 & v_155 == 4
            replace BLvR = 1 if B2v4 == 4 & v_156 == 4
            replace BLvR = 1 if B2v4 == 5 & v_157 == 4
            replace BLvR = 1 if B2v4 == 6 & v_158 == 4
            replace BLvR = 1 if B2v4 == 7 & v_159 == 4
            replace BLvR = 1 if B2v4 == 8 & v_160 == 4

            replace BLvR = 2 if B2v4 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v4
            replace BLvR = 2 if B2v4 == 2 & v_154 == 2
            replace BLvR = 2 if B2v4 == 3 & v_155 == 2
            replace BLvR = 2 if B2v4 == 4 & v_156 == 2
            replace BLvR = 2 if B2v4 == 5 & v_157 == 2
            replace BLvR = 2 if B2v4 == 6 & v_158 == 2
            replace BLvR = 2 if B2v4 == 7 & v_159 == 2
            replace BLvR = 2 if B2v4 == 8 & v_160 == 2


            replace BLvR = 1 if B4v5 == 1 & v_152 == 4 //if Profile 4 is chosen in B4v5
            replace BLvR = 1 if B4v5 == 2 & v_154 == 4
            replace BLvR = 1 if B4v5 == 3 & v_155 == 4
            replace BLvR = 1 if B4v5 == 4 & v_156 == 4
            replace BLvR = 1 if B4v5 == 5 & v_157 == 4
            replace BLvR = 1 if B4v5 == 6 & v_158 == 4
            replace BLvR = 1 if B4v5 == 7 & v_159 == 4
            replace BLvR = 1 if B4v5 == 8 & v_160 == 4

            replace BLvR = 2 if B4v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B4v5
            replace BLvR = 2 if B4v5 == 2 & v_154 == 5
            replace BLvR = 2 if B4v5 == 3 & v_155 == 5
            replace BLvR = 2 if B4v5 == 4 & v_156 == 5
            replace BLvR = 2 if B4v5 == 5 & v_157 == 5
            replace BLvR = 2 if B4v5 == 6 & v_158 == 5
            replace BLvR = 2 if B4v5 == 7 & v_159 == 5
            replace BLvR = 2 if B4v5 == 8 & v_160 == 5


            *****BATTLES LEFT VS CENTER
            generate BLvC = .
            label variable BLvC "Left vs Right Profile"
            label define BLvCLabel 1 "Left Profile" 2 "Center Profile"
            label value BLvC BLvCLabel

            replace BLvC = 1 if B1v3 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v3
            replace BLvC = 1 if B1v3 == 2 & v_154 == 1
            replace BLvC = 1 if B1v3 == 3 & v_155 == 1
            replace BLvC = 1 if B1v3 == 4 & v_156 == 1
            replace BLvC = 1 if B1v3 == 5 & v_157 == 1
            replace BLvC = 1 if B1v3 == 6 & v_158 == 1
            replace BLvC = 1 if B1v3 == 7 & v_159 == 1
            replace BLvC = 1 if B1v3 == 8 & v_160 == 1

            replace BLvC = 2 if B1v3 == 1 & v_152 == 3 //if Profile 3 is chosen in B1v3
            replace BLvC = 2 if B1v3 == 2 & v_154 == 3
            replace BLvC = 2 if B1v3 == 3 & v_155 == 3
            replace BLvC = 2 if B1v3 == 4 & v_156 == 3
            replace BLvC = 2 if B1v3 == 5 & v_157 == 3
            replace BLvC = 2 if B1v3 == 6 & v_158 == 3
            replace BLvC = 2 if B1v3 == 7 & v_159 == 3
            replace BLvC = 2 if B1v3 == 8 & v_160 == 3


            replace BLvC = 1 if B1v6 == 1 & v_152 == 1 //if Profile 1 is chosen in B1v6
            replace BLvC = 1 if B1v6 == 2 & v_154 == 1
            replace BLvC = 1 if B1v6 == 3 & v_155 == 1
            replace BLvC = 1 if B1v6 == 4 & v_156 == 1
            replace BLvC = 1 if B1v6 == 5 & v_157 == 1
            replace BLvC = 1 if B1v6 == 6 & v_158 == 1
            replace BLvC = 1 if B1v6 == 7 & v_159 == 1
            replace BLvC = 1 if B1v6 == 8 & v_160 == 1

            replace BLvC = 2 if B1v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B1v6
            replace BLvC = 2 if B1v6 == 2 & v_154 == 6
            replace BLvC = 2 if B1v6 == 3 & v_155 == 6
            replace BLvC = 2 if B1v6 == 4 & v_156 == 6
            replace BLvC = 2 if B1v6 == 5 & v_157 == 6
            replace BLvC = 2 if B1v6 == 6 & v_158 == 6
            replace BLvC = 2 if B1v6 == 7 & v_159 == 6
            replace BLvC = 2 if B1v6 == 8 & v_160 == 6


            replace BLvC = 1 if B3v4 == 1 & v_152 == 4 //if Profile 4 is chosen in B3v4
            replace BLvC = 1 if B3v4 == 2 & v_154 == 4
            replace BLvC = 1 if B3v4 == 3 & v_155 == 4
            replace BLvC = 1 if B3v4 == 4 & v_156 == 4
            replace BLvC = 1 if B3v4 == 5 & v_157 == 4
            replace BLvC = 1 if B3v4 == 6 & v_158 == 4
            replace BLvC = 1 if B3v4 == 7 & v_159 == 4
            replace BLvC = 1 if B3v4 == 8 & v_160 == 4

            replace BLvC = 2 if B3v4 == 1 & v_152 == 3 //if Profile 3 is chosen in B3v4
            replace BLvC = 2 if B3v4 == 2 & v_154 == 3
            replace BLvC = 2 if B3v4 == 3 & v_155 == 3
            replace BLvC = 2 if B3v4 == 4 & v_156 == 3
            replace BLvC = 2 if B3v4 == 5 & v_157 == 3
            replace BLvC = 2 if B3v4 == 6 & v_158 == 3
            replace BLvC = 2 if B3v4 == 7 & v_159 == 3
            replace BLvC = 2 if B3v4 == 8 & v_160 == 3


            replace BLvC = 1 if B4v6 == 1 & v_152 == 4 //if Profile 4 is chosen in B4v6
            replace BLvC = 1 if B4v6 == 2 & v_154 == 4
            replace BLvC = 1 if B4v6 == 3 & v_155 == 4
            replace BLvC = 1 if B4v6 == 4 & v_156 == 4
            replace BLvC = 1 if B4v6 == 5 & v_157 == 4
            replace BLvC = 1 if B4v6 == 6 & v_158 == 4
            replace BLvC = 1 if B4v6 == 7 & v_159 == 4
            replace BLvC = 1 if B4v6 == 8 & v_160 == 4

            replace BLvC = 2 if B4v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B4v6
            replace BLvC = 2 if B4v6 == 2 & v_154 == 6
            replace BLvC = 2 if B4v6 == 3 & v_155 == 6
            replace BLvC = 2 if B4v6 == 4 & v_156 == 6
            replace BLvC = 2 if B4v6 == 5 & v_157 == 6
            replace BLvC = 2 if B4v6 == 6 & v_158 == 6
            replace BLvC = 2 if B4v6 == 7 & v_159 == 6
            replace BLvC = 2 if B4v6 == 8 & v_160 == 6

            ************BATTLES CENTER VS RIGHT**
            generate BCvR = .
            label variable BCvR "Center vs Right Profile"
            label define BCvRLabel 1 "Center Profile" 2 "Right Profile"
            label value BCvR BCvRLabel

            replace BCvR = 1 if B2v3 == 1 & v_152 == 3 //if Profile 3 is chosen in B2v3
            replace BCvR = 1 if B2v3 == 2 & v_154 == 3
            replace BCvR = 1 if B2v3 == 3 & v_155 == 3
            replace BCvR = 1 if B2v3 == 4 & v_156 == 3
            replace BCvR = 1 if B2v3 == 5 & v_157 == 3
            replace BCvR = 1 if B2v3 == 6 & v_158 == 3
            replace BCvR = 1 if B2v3 == 7 & v_159 == 3
            replace BCvR = 1 if B2v3 == 8 & v_160 == 3

            replace BCvR = 2 if B2v3 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v3
            replace BCvR = 2 if B2v3 == 2 & v_154 == 2
            replace BCvR = 2 if B2v3 == 3 & v_155 == 2
            replace BCvR = 2 if B2v3 == 4 & v_156 == 2
            replace BCvR = 2 if B2v3 == 5 & v_157 == 2
            replace BCvR = 2 if B2v3 == 6 & v_158 == 2
            replace BCvR = 2 if B2v3 == 7 & v_159 == 2
            replace BCvR = 2 if B2v3 == 8 & v_160 == 2


            replace BCvR = 1 if B3v5 == 1 & v_152 == 3 //if Profile 3 is chosen in B3v5
            replace BCvR = 1 if B3v5 == 2 & v_154 == 3
            replace BCvR = 1 if B3v5 == 3 & v_155 == 3
            replace BCvR = 1 if B3v5 == 4 & v_156 == 3
            replace BCvR = 1 if B3v5 == 5 & v_157 == 3
            replace BCvR = 1 if B3v5 == 6 & v_158 == 3
            replace BCvR = 1 if B3v5 == 7 & v_159 == 3
            replace BCvR = 1 if B3v5 == 8 & v_160 == 3

            replace BCvR = 2 if B3v5 == 1 & v_152 == 5 //if Profile 5 is chosen in B3v5
            replace BCvR = 2 if B3v5 == 2 & v_154 == 5
            replace BCvR = 2 if B3v5 == 3 & v_155 == 5
            replace BCvR = 2 if B3v5 == 4 & v_156 == 5
            replace BCvR = 2 if B3v5 == 5 & v_157 == 5
            replace BCvR = 2 if B3v5 == 6 & v_158 == 5
            replace BCvR = 2 if B3v5 == 7 & v_159 == 5
            replace BCvR = 2 if B3v5 == 8 & v_160 == 5


            replace BCvR = 1 if B2v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B2v6
            replace BCvR = 1 if B2v6 == 2 & v_154 == 6
            replace BCvR = 1 if B2v6 == 3 & v_155 == 6
            replace BCvR = 1 if B2v6 == 4 & v_156 == 6
            replace BCvR = 1 if B2v6 == 5 & v_157 == 6
            replace BCvR = 1 if B2v6 == 6 & v_158 == 6
            replace BCvR = 1 if B2v6 == 7 & v_159 == 6
            replace BCvR = 1 if B2v6 == 8 & v_160 == 6

            replace BCvR = 2 if B2v6 == 1 & v_152 == 2 //if Profile 2 is chosen in B2v6
            replace BCvR = 2 if B2v6 == 2 & v_154 == 2
            replace BCvR = 2 if B2v6 == 3 & v_155 == 2
            replace BCvR = 2 if B2v6 == 4 & v_156 == 2
            replace BCvR = 2 if B2v6 == 5 & v_157 == 2
            replace BCvR = 2 if B2v6 == 6 & v_158 == 2
            replace BCvR = 2 if B2v6 == 7 & v_159 == 2
            replace BCvR = 2 if B2v6 == 8 & v_160 == 2


            replace BCvR = 1 if B5v6 == 1 & v_152 == 6 //if Profile 6 is chosen in B5v6
            replace BCvR = 1 if B5v6 == 2 & v_154 == 6
            replace BCvR = 1 if B5v6 == 3 & v_155 == 6
            replace BCvR = 1 if B5v6 == 4 & v_156 == 6
            replace BCvR = 1 if B5v6 == 5 & v_157 == 6
            replace BCvR = 1 if B5v6 == 6 & v_158 == 6
            replace BCvR = 1 if B5v6 == 7 & v_159 == 6
            replace BCvR = 1 if B5v6 == 8 & v_160 == 6

            replace BCvR = 2 if B5v6 == 1 & v_152 == 2 //if Profile 5 is chosen in B5v6
            replace BCvR = 2 if B5v6 == 2 & v_154 == 2
            replace BCvR = 2 if B5v6 == 3 & v_155 == 2
            replace BCvR = 2 if B5v6 == 4 & v_156 == 2
            replace BCvR = 2 if B5v6 == 5 & v_157 == 2
            replace BCvR = 2 if B5v6 == 6 & v_158 == 2
            replace BCvR = 2 if B5v6 == 7 & v_159 == 2
            replace BCvR = 2 if B5v6 == 8 & v_160 == 2


            Last edited by Tristan Muno; 08 Jul 2021, 16:36.

            Comment


            • #7
              The lengthy code for generating these variables is a distraction when the question is how to plot them.

              In each block of code it seems that the values of one variable don't matter and that you could reduce 8 statements to 1 using a device like

              Code:
              replace  BLvR = 1 if inlist(1, v_152, v_154, v_155, v_156, _v157, _v158, _v159, _v160)
              For the plot:

              Labelling Left as 1 and Right as 2 and then Left as 1 and Center as 2 and then Center as 1 and RIght as 2 just makes a combined plot more difficult.

              It seems that the technique you need is just the same as in #5: to ,map a 3 variables with 2 categories each to 2 variables with 3 categories each. In many countries, and perhaps yours, red denotes left-wing and blue denotes right wing, so grey might fit anything between.

              Comment

              Working...
              X