Announcement

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

  • #16
    The code as shown won't work if you have disallowed variable name abbreviation. I vote both ways: variable name abbreviation is in principle a dangerous idea but I got very used to it in 1991 and don't feel compelled to change my habits.

    Comment


    • #17
      What is it that they say about old habits? Good looking graphs... I will possibly use this someday because I find that I ocassionally work with survey data.

      Comment


      • #18
        On more quick question regarding tabplot (which I like more and more when I think about it).

        I created a plot with other variables (at least for the rows). The string variable ,displayed on the x-axis, is not in the correct order. How does tabplot decide which category to put in first, second , ... place? How can I manipulate that?

        Comment


        • #19
          tabplot (SSC) just uses the same sort order as Stata, numeric order for numeric variables and alphanumeric order for string variables. It does that by using egen's group() function internally. In reworking your example I deliberately used strings that would come out right by changing the last category to "75+".

          Code:
            
          input str5 age_class p1 p2 p3 p4  
          "16-24" 40.83 41.00 14.23 3.94  
          "25-34" 43.57 44.09 9.39 2.95  
          "35-44" 46.19 43.09 8.24 2.47  
          "45-54" 45.35 43.97 8.37 2.32  
          "55-64" 41.10 44.44 11.10 3.36  
          "65-74" 35.07 44.30 15.67 4.97  
          "75+" 26.04 41.90 23.03 9.03
          So you may need to recode some variables.Just like Stata, tabplot can't decide on the meaning of categories.
          Last edited by Nick Cox; 22 May 2015, 06:03.

          Comment


          • #20
            Some other possibilities: Code first, then commentary:

            Code:
             
            set scheme s1color 
            clear 
            input str5 age_class p1 p2 p3 p4 
            "16-24" 40.83 41.00 14.23 3.94 
            "25-34" 43.57 44.09 9.39 2.95 
            "35-44" 46.19 43.09 8.24 2.47 
            "45-54" 45.35 43.97 8.37 2.32 
            "55-64" 41.10 44.44 11.10 3.36 
            "65-74" 35.07 44.30 15.67 4.97 
            "75+" 26.04 41.90 23.03 9.03 
            end
            label var age_class "age class" 
            label var p1 "--"
            label var p2 "-"
            label var p3 "+" 
            label var p4 "++"
            encode age_class, gen(age) 
            
            twoway connected p? age , xla(1/7, valuelabel) ///
            yla(, ang(h)) ytitle(percent of answers) /// 
            ms(O Oh Oh O) /// 
            mcolor(red red*0.5 blue*0.5 blue) /// 
            lcolor(red red*0.5 blue*0.5 blue) /// 
            text(`=p1[7]' 7 " --", place(e) color(red))  ///
            text(`=p2[7]' 7 " -", place(e) color(red*0.5) )  ///
            text(`=p3[7]' 7 " +", place(e) color(blue*0.5) )  ///
            text(`=p4[7]' 7 " ++", place(e) color(blue) ) xsc(r(. 7.5)) legend(off) aspect(1) 
            
            graph export slide4.png, as(png) replace 
            
            more 
            
            reshape long p, i(age_class) j(answer) 
            label def answer 1 "++" 2 "+" 3 "-" 4 "--"
            label val answer answer
            graph dot (asis) p  , over(age_class) over(answer) xsize(4) ysize(6) ///
            ytitle(percent of answers) linetype(line) lines(lc(gs12) lw(vthin))
            
            graph export slide5 .png, as(png) replace

            First is a simple line graph or chart. When there is an underlying idea of changing attitudes or behaviours with age, I am happy with line representation, although some might to insist that the predictor is discrete. I'd recommend some effort in loosing the legend and adding annotation on the graph.

            Click image for larger version

Name:	slide4.png
Views:	1
Size:	9.7 KB
ID:	1295469


            Second is a (Cleveland) dot chart.

            Click image for larger version

Name:	slide5.png
Views:	2
Size:	9.1 KB
ID:	1295471
            Attached Files

            Comment

            Working...
            X