Announcement

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

  • spine plot - "change the order of variable"

    Good morning to everybody!!!

    How to change the order of the variable in spineplot?
    By default it gives them in alphabetical order. Below the code I used but it gives me error thanks in advance to everybody spineplot preference group, legend(size(tiny)) xtitle("") xlabel("") /// percent ylab(0(10)100, labsize(tiny) axis(2)) ytitle("", axis(2)) /// xlab(, labsize(vsmall) axis(2)) xtitle("", axis(2)) name(third, replace) /// bar1(bcolor(cyan)) bar2(bcolor(mint)) /// bar3(bcolor(lime)) bar4(bcolor(midgreen)) bar5(bcolor(dkgreen)) /// bar6(bcolor(red)) bar7(bcolor(orange)) bar8(bcolor(yellow)) /// bar9(bcolor(pink)) bar10(bcolor(cranberry)) bar11(bcolor(purple)) ylab(1 "Adult satisfied" 2 "Life skills training" 3 "Support group, on-line" 4 "Support groups, in person" 5 "Free time activities" 6 "Family relations support and counseling" 7 "Behavior training, for an individual" 8 "Behavior training in groups" 9 "Program for matching autistic peers with each other" 10 "Program for matching an autistic person with a non-autistic peer" 11 "Other")

  • #2
    Good morning to everybody!!!

    How to change the order of the variable in spineplot?
    By default it gives them in alphabetical order. Below the code I used but it gives me error thanks in advance to everybody


    Code:
    spineplot  preference group, legend(size(tiny)) xtitle("")  xlabel("") ///
    percent ylab(0(10)100, labsize(tiny) axis(2)) ytitle("", axis(2))  ///
    xlab(, labsize(vsmall) axis(2)) xtitle("", axis(2)) name(third, replace) ///
    bar1(bcolor(cyan))  bar2(bcolor(mint))  /// 
    bar3(bcolor(lime)) bar4(bcolor(midgreen))  bar5(bcolor(dkgreen))  ///  
    bar6(bcolor(red)) bar7(bcolor(orange)) bar8(bcolor(yellow)) /// 
    bar9(bcolor(pink))  bar10(bcolor(cranberry)) bar11(bcolor(purple))  
    ylab(1 "Adult satisfied" 2 "Life skills training" 3 "Support group, on-line" 4 "Support groups, in person" 5 "Free time activities" 6 "Family relations support and counseling" 7 "Behavior training, for an individual" 8 "Behavior training in groups" 9 "Program for matching autistic peers with each other" 10 "Program for matching an autistic person with a non-autistic peer" 11 "Other")

    Comment


    • #3
      spineplot is from the Stata Journal.

      You give code but no data example or error message, so I can't follow what you should be doing instead.

      The results of

      Code:
      contract preference group 
      dataex
      would help here.

      Comment


      • #4

        Here the data example
        thanks a lot Nick Cox

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input long(group preference) int _freq
        1  1 115
        2  1  25
        3  1  38
        1  2  51
        2  2  19
        3  2  29
        4  2  23
        1  3   9
        2  3  16
        3  3   5
        4  3  12
        1  4  31
        2  4  12
        3  4   9
        4  4  14
        1  5  34
        2  5  20
        3  5  30
        4  5  23
        1  7  45
        2  7  37
        3  7  47
        4  7  60
        1  8  34
        2  8  11
        3  8   9
        4  8  12
        1  9  36
        2  9  37
        3  9  26
        4  9  13
        1 10  49
        2 10  19
        3 10  12
        4 10  10
        1 11  31
        2 11   8
        3 11   1
        4 11  14
        1 12   9
        2 12   3
        4 12   5
        end
        label values group group
        label def group 1 "Autistic adult", modify
        label def group 2 "High", modify
        label def group 3 "Low", modify
        label def group 4 "Professional", modify
        label values preference preference
        label def preference 1 "Adult satisfied", modify
        label def preference 2 "Behavior training, for an individual", modify
        label def preference 3 "Behavior training, in groups", modify
        label def preference 4 "Family relation support and counseling", modify
        label def preference 5 "Free time activities", modify
        label def preference 7 "Life skills training", modify
        label def preference 8 "Other", modify
        label def preference 9 "Program for matching an autistic person with a-non autistic peer", modify
        label def preference 10 "Program for matching autistic peers with each other", modify
        label def preference 11 "Support groups in person", modify
        label def preference 12 "Support groups, on line", modify

        Comment


        • #5
          Thanks. So, your categories are alphabetically ordered. Why are you surprised that spineplot respects that? What do you want that is different?

          Comment


          • #6

            Yes, I would like that categories are ordered like below: 1 "Adult satisfied" 2 "Life skills training" 3 "Support group, on-line" 4 "Support groups, in person" 5 "Free time activities" 6 "Family relations support and counseling" 7 "Behavior training, for an individual" 8 "Behavior training in groups" 9 "Program for matching autistic peers with each other" 10 "Program for matching an autistic person with a non-autistic peer" 11 "Other" I don't know how to do.. Is it possible to have the categories ordered in that way??? Thanks a lot Nick Cox

            Comment


            • #7
              Yes, I would like that categories are ordered like below
              Code:
               
               1 "Adult satisfied" 2 "Life skills training" 3 "Support group, on-line" 4 "Support groups, in person" 5 "Free time activities" 6 "Family relations support and counseling" 7 "Behavior training, for an individual" 8 "Behavior training in groups" 9 "Program for matching autistic peers with each other" 10 "Program for matching an autistic person with a non-autistic peer" 11 "Other"

              Comment


              • #8
                recode to get categories in a different order.

                Comment


                • #9
                  thanks a lot Nick Cox but It gives me error

                  Code:
                  recode preference 1 "Adult satisfied" 2 "Life skills training" 3 "Support group, on-line" 4 "Support groups, in person" 5 "Free time activities" 6 "Family relations support and cou
                  > nseling" 7 "Behavior training, for an individual" 8 "Behavior training in groups" 9 "Program for matching autistic peers with each other" 10 "Program for matching an autistic perso
                  > n with a non-autistic peer" 11 "Other"
                  unknown el Adult satisfied in rule
                  r(198);


                  I use the command "recod" before the code
                  Code:
                   
                   spineplot  preference group, legend(size(tiny)) xtitle("")  xlabel("") /// percent ylab(0(10)100, labsize(tiny) axis(2)) ytitle("", axis(2))  /// xlab(, labsize(vsmall) axis(2)) xtitle("", axis(2)) name(third, replace) /// bar1(bcolor(cyan))  bar2(bcolor(mint))  ///  bar3(bcolor(lime)) bar4(bcolor(midgreen))  bar5(bcolor(dkgreen))  ///   bar6(bcolor(red)) bar7(bcolor(orange)) bar8(bcolor(yellow)) ///  bar9(bcolor(pink))  bar10(bcolor(cranberry)) bar11(bcolor(purple))

                  Comment


                  • #10

                    thanks a lot Nick Cox .
                    But it gives me error.
                    I wrote this:


                    Code:
                    recode preference 1=Adult satisfied 2=Life skills training 3=Support groups on line 4=Support groups, in person 5=Free time activities 6=Family relations support and counseling 7=Behavior training,  individual 8=Behavior training in groups 9=Program formatching an autistic peers with each other 10=Program  matching anautistic person with a non-autistic peer 11=Other, gen(new_preference)


                    Code:
                    spineplot  preference group, legend(size(tiny)) xtitle(" ") xlabel("") ///
                    percent ylab(0(10)100, labsize(tiny) axis(2)) ///
                    xlab(, labsize(vsmall) axis(2)) name(third, replace) ///
                    bar1(bcolor(cyan))  bar2(bcolor(mint))  /// 
                    bar3(bcolor(lime)) bar4(bcolor(midgreen))  bar5(bcolor(dkgreen))  ///  
                    bar6(bcolor(red)) bar7(bcolor(orange)) bar8(bcolor(yellow)) /// 
                    bar9(bcolor(pink))  bar10(bcolor(cranberry)) bar11(bcolor(purple))

                    Comment


                    • #11
                      Indeed. Your recode code is a long way from what is legal. The help explains.

                      Comment


                      • #12
                        Can you help me, please?

                        Comment


                        • #13
                          My advice is to study the help for recode.

                          Comment


                          • #14
                            My solution for these problems are a) clone/copy variable and label, b) attach cloned label with new var and c) recode label ( with -elabel recode- from package -elabel- that is from SSC (Daniel Klein))

                            Using -elabel- my solution looks like
                            Code:
                            elabel copy preference l_preference_r
                            clonevar preference_r = preference
                            elabel value preference_r l_preference_r
                            elabel recode l_preference_r (rules), recodevar

                            Comment


                            • #15
                              Dear Nick Cox thanks a lot.
                              I use your code but there's a problem..I got the desired order but with mismatched percentages. I am associated with the old order. Where is the mistake ??

                              Below the code I used

                              Code:
                              recode preference (1 = 1 "Other") (2 = 2 "Program for matching an autistic person with a non-autistic peer") (3 = 3 "Program for matching autistic peers with each other") (4 = 4 "Behavior training in groups") (5 = 5 "Behavior training, for an individual") (6 = 6 "Family relations support and counseling") (7 = 7 "Free time activities") (8 = 8 "Support groups, in person") (9 = 9 "Support group, on-line") (10 = 10 "Life skills training") (11 = 11 "Adult satisfied") , pre(new) label(newrep)


                              Thanks a lot in advance to everybody

                              Comment

                              Working...
                              X