Announcement

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

  • Line graph for categorical data

    Hi, I have a problem of translating my categorical data into a line graph showing change over time. I have used the survey data, the answer is rather 0 for disagree and 1 for agree. I have one question but it is coded under different variables because they come from different years of survey, hence different datasets and I just merged the datasets together. Also the data goes by country. I attached the image, there are two other countries apart from Egypt. Q601_3 and Q601_31 are essentially the same question but recoded from different datasets hence different years, so I kept them under different variables. I do not understand how I can do a line graph over years using these two variables as basically one. I will attach below the graph that I made in excel. I tabulated the data and made a new table in excel exclusively with percentages to get this type of graph. At this point I wouldn't mind a bar graph as well, but I can't seem to combine both variables together.

    graph hbar, by(COUNTRY) over(Q601_3)
    graph hbar, by(COUNTRY) over(Q601_31)

    This code worked, but it is not what I am looking for, unfortunately.

    Also I do not understand how to potentially remove one of the responses for the graph (have just disagree or just agree).

    I hope what I tried to explain was clear. Thank you! Also attached my merged dataset, I tried to combine the variables but the result turned out even more weird...
    Attached Files

  • #2
    Please see https://www.statalist.org/forums/help#stata for advice about .dta attachments and images (please don't).

    You've done the calculations; the issue is a good graph. Even for a simple set of results like that here, a good graph can be hard to find:

    1. A legend is at best a necessary evil, Even here it obliges mental back and forth (which color is Egypt? which country is blue?). Lose rhe legend! Kill the key! (if you can)

    2. But direct labelling can lead to a mess because some values may be close. Your Excel graph makes the point.

    3. Grey is a dull and recessive colour. That can be a real virtue for some purposes -- https://www.stata-journal.com/articl...article=gr0040 -- but not here.

    4. As postings and writings elsewhere indicate, I am generally very positive about showing numbers as text on graphs. Here they seem over-kill. If readers need the numbers too, show a table.

    Here are some possibilities. I worked quite hard to get some details shown well, but there is a lot of work to get colours right. It can be positive to look for national colours if so defined. It can be important to avoid colours that are sensitive or offensive in particular countries: I lack the cultural knowledge to comment, unfortunately. Matching colours of text, lines, and marker symbols is fiddly but worthwhile. If I were spending more time on this, I would try thicker lines and arrows, but I stop here.

    Other discussions and trickery at

    https://www.stata-journal.com/articl...article=gr0015

    https://www.stata-journal.com/articl...article=gr0034

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float id str9 name float(pc2 pc4 wave2 wave4)
    1 "Egypt"      8.89 20.25 2 4
    2 "Jordan"    22.91 24.98 2 4
    3 "Palestine" 22.53 28.24 2 4
    end
    label values id name 
    label def name 1 "Egypt", modify
    label def name 2 "Jordan", modify
    label def name 3 "Palestine", modify
    
    set scheme s1color 
    
    twoway pcarrow pc2 id pc4 id, horizontal ysc(reverse) yla(1/3, grid glc(gs12) glw(thin) valuelabel ang(h) noticks) xtitle("Political leadership") subtitle(Wave 2 to wave 4) aspect(0.5) ytitle("") name(EJP1, replace) 
    
    
    twoway pcarrow pc2 id pc4 id,  xla(1/3, grid glc(gs12) glw(thin) valuelabel ang(h) noticks) ytitle("Political leadership") subtitle(Wave 2 to wave 4) xsc(r(0.8 3.2)) aspect(0.5)  xtitle("") yla(, ang(h)) subtitle(Wave 2 to wave 4)  name(EJP2, replace) 
    
    reshape long pc , i(id) j(wave)
    
    line pc wave, by(id, note("") compact row(1) subtitle(Wave 2 to wave 4)) xtitle("") name(EJP3, replace) xla(2 4) yla(, ang(h))  ytitle("Political leadership") 
    
    separate pc, by(name) veryshortlabel
    local textopts ms(none) mlabsize(small)
    twoway connected pc? wave , ms(Oh X Th) xla(2 4) xsc(r(1.8 4.6)) yla(, ang(h)) || scatteri 20.25 4 "Egypt", `textopts' || scatteri 24.98 4 "Jordan", `textopts' || scatteri 28.24 4 "Palestine", `textopts' legend(off) aspect(0.7)  ytitle("Political leadership") subtitle(Wave 2 to wave 4) name(EJP4, replace)
    
    graph combine EJP1 EJP2 EJP3 EJP4
    Click image for larger version

Name:	EJP.png
Views:	1
Size:	36.4 KB
ID:	1656189

    Comment

    Working...
    X