Announcement

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

  • #16
    Hey everyone, I have another follow up question that's come up while applying the concept above to another set of variables, if that's okay!
    Suppose I have two variables with an odd number of responses each and I need two different scales (like suggested in #10).
    For both questions, I would like the neutral response "in the middle" to be split by the vertical centre line (so, for variable apple it would be the response "Neutral" while for orange it would be "Maybe").

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(female treatment apple orange)
    0 0 1 3
    0 0 3 3
    0 0 2 2
    0 0 3 1
    0 0 5 1
    0 0 4 2
    0 0 3 3
    0 1 2 2
    0 1 3 2
    0 1 2 3
    0 1 4 3
    1 0 1 1
    1 0 5 2
    1 0 3 3
    1 0 4 2
    1 0 2 3
    1 1 3 2
    1 1 2 1
    1 1 5 3
    1 1 2 1
    end
    
    
    label values apple scale15
    label values orange scale13
    label def scale15 1 "Strongly disagree", modify
    label def scale15 2 "Disagree", modify
    label def scale15 3 "Neutral", modify
    label def scale15 4 "Agree", modify
    label def scale15 5 "Strongly agree", modify
    label def scale13 1 "No", modify
    label def scale13 2 "Maybe", modify
    label def scale13 3 "Yes", modify
    
    
    lab values female female
    lab def female 0 "Male" 1 "Female"
    
    gen long id = _n 
    rename (apple-orange) (Percent=)
    reshape long Percent, i(id) j(food) string 
    label def what 1 apple 2 orange
    encode food, gen(what) label(what)
    
    egen which = group(female treatment)
    label def which 1 "male control" 2 "male treated" 3 "female control" 4 "female treated"
    label val which which 
    
    label var what "Whatever this is, really"
    label var Percent "% disagreeing or agreeing"
    recode Percent 1=1 2=2 3=4 4=6 5=8 if what==1
    recode Percent 1=3 2=5 3=7 if what==2
    label drop scale13
    label def scale18 1 "Strongly disagree" 2 "Disagree" 4 "Neutral" 6 "Agree" 8 "Strongly agree" 3 "No" 5 "Maybe" 7 "Yes"
    label val Percent scale18
    
    floatplot Percent, over(what) by(which, compact note("") row(1) legend(pos(12))) center(4) textoffset(0) fcolors(red red*0.8 blue red*0.6 blue*0.6 red*0.4 blue*0.2 red*0.2) legend(row(2) order(1 "Strongly disagree" 2 "Disagree" 4 "Neutral" 6 "Agree" 8 "Strongly agree" - 3 "No" 5 "Maybe" 7 "Yes"- )) ysc(reverse) subtitle(, fcolor(none)) aspect(0.95)
    Here the center line goes through apple's "Neutral" response and parts orange between "No" and "Maybe". Am I correct thinking that my desired outcome is impossible when the two variables have different scales (except via graph combine)?


    Someone suggested trying to "split" the "Maybe" response into two distinct responses (say "Maybe1" and "Maybe2" with 50% of the votes each) by recoding the Percent variable accordingly. That way apple has an odd number of response options and orange has an even number. Center line would go through apple's "Neutral" and between "Maybe1" and "Maybe2". Then assign "Maybe1" and "Maybe2" the same color in floatplot and only mention one of them in the legend, so that it looks like the centre line goes right through the "Maybe" response as well.
    My concern here is:
    1. "Maybe" response might have an odd number of votes -> cannot split into two responses with exact same amount of votes
    2. The text displaying the percentage for each bar would show the percentage for "Maybe1" and "Maybe2". Am I correct thinking there is no way to manipulate the text in any way?

    Hope I explained this somewhat comprehensibly.

    Thanks in advance!!

    Comment


    • #17
      Try something like this:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(female treatment apple orange)
      0 0 1 3
      0 0 3 3
      0 0 2 2
      0 0 3 1
      0 0 5 1
      0 0 4 2
      0 0 3 3
      0 1 2 2
      0 1 3 2
      0 1 2 3
      0 1 4 3
      1 0 1 1
      1 0 5 2
      1 0 3 3
      1 0 4 2
      1 0 2 3
      1 1 3 2
      1 1 2 1
      1 1 5 3
      1 1 2 1
      end
      
      
      label values apple scale15
      label values orange scale13
      label def scale15 1 "Strongly disagree", modify
      label def scale15 2 "Disagree", modify
      label def scale15 3 "Neutral", modify
      label def scale15 4 "Agree", modify
      label def scale15 5 "Strongly agree", modify
      label def scale13 1 "No", modify
      label def scale13 2 "Maybe", modify
      label def scale13 3 "Yes", modify
      
      
      lab values female female
      lab def female 0 "Male" 1 "Female"
      
      gen long id = _n
      rename (apple-orange) (Percent=)
      reshape long Percent, i(id) j(food) string
      label def what 1 apple 2 orange
      encode food, gen(what) label(what)
      
      egen which = group(female treatment)
      label def which 1 "male control" 2 "male treated" 3 "female control" 4 "female treated"
      label val which which
      
      label var what "Whatever this is, really"
      label var Percent "% disagreeing or agreeing"
      recode Percent 1=1 2=2 3=4 4=6 5=8 if what==1
      recode Percent 1=1 2=4 3=8 if what==2
      label drop scale13
      label def scale18 1 "Strongly disagree" 2 "Disagree" 4 "Neutral" 6 "Agree" 8 "Strongly agree" 3 "No" 5 "Maybe" 7 "Yes"
      label val Percent scale18
      
      floatplot Percent, over(what) by(which, compact note("") row(1) legend(pos(12))) center(4) textoffset(0) ///
      fcolors(red red*0.8 gs8  blue*0.8 blue red gs8 blue) legend(row(2) ///
      order(1 "Strongly disagree" 2 "Disagree" 3 "Neutral" 4 "Agree" 5 "Strongly agree" - 1 "No" 3 "Maybe" 5 "Yes"- )) ///
      ysc(reverse) subtitle(, fcolor(none)) aspect(0.95)
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.0 KB
ID:	1763850

      Last edited by Andrew Musau; 16 Sep 2024, 08:38.

      Comment

      Working...
      X