Announcement

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

  • Graphing bar charts or scatter for this case

    Hello

    I have in my dataset some varibales like that:
    ID Date of inclusion
    2345 21/09/2016
    64278 11/10/2016
    But with a lot of more IDs and dates. I want to do a bar plot and a scatter plot of Participants_included x Month of inclusion and compare it to the "ideal" side by side.
    We are inclusion some participants during some months, and my ideal rate of inclusion by month is always 147.
    I was trying to play with the graph options but had no success. How can I do a graph like:
    1) For bar graph: x axis is the month and for each month you would have two bars: included participants and ideal ones (always 147)
    2) Scatter or line: following the same logic, a scatter/line for included and other for ideal. (this could be accumulative or not).

    Thanks in advance

  • #2
    We can't comment on code you don't give to advise on what is wrong or misdirected. And I have to guess here at various elements given the lack of a full data example.

    Although you have daily dates, it seems that you want to summarize by month, presumably calendar month. Also, I imagine that being included in the data at least once each month is what you are monitoring.

    These guesses lie behind this fake example. I haven't gone as far as (e.g.) include bars always 147, which seems to me poor design when the axis labels show the information.

    Code:
    clear
    set obs 147
    gen id = _n
    expand 12
    set seed 2803
    gen ddate = mdy(1,1,2016) + floor(366 * runiform())
    gen mdate = mofd(ddate)
    egen tag = tag(id mdate)
    egen participants = total(tag), by(mdate)
    
    twoway bar participants mdate, barw(0.9) bfcolor(none) base(0) ///
    xla(`=tm(2016m1)'/`=tm(2016m12)', format(%tmMon) noticks) ///
    ytitle("participants / 147") xtitle("") yla(0(20)100, ang(h))
    
    twoway connected participants mdate, sort ///
    xla(`=tm(2016m1)'/`=tm(2016m12)', format(%tmMon) noticks) ///
    ytitle("participants / 147") xtitle("") yla(, ang(h))
    Click image for larger version

Name:	twographs.png
Views:	1
Size:	17.1 KB
ID:	1359817

    Last edited by Nick Cox; 11 Oct 2016, 07:52.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      We can't comment on code you don't give to advise on what is wrong or misdirected. And I have to guess here at various elements given the lack of a full data example.

      Although you have daily dates, it seems that you want to summarize by month, presumably calendar month. Also, I imagine that being included in the data at least once each month is what you are monitoring.

      These guesses lie behind this fake example. I haven't gone as far as (e.g.) include bars always 147, which seems to me poor design when the axis labels show the information.

      Code:
      clear
      set obs 147
      gen id = _n
      expand 12
      set seed 2803
      gen ddate = mdy(1,1,2016) + floor(366 * runiform())
      gen mdate = mofd(ddate)
      egen tag = tag(id mdate)
      egen participants = total(tag), by(mdate)
      
      twoway bar participants mdate, barw(0.9) bfcolor(none) base(0) ///
      xla(`=tm(2016m1)'/`=tm(2016m12)', format(%tmMon) noticks) ///
      ytitle("participants / 147") xtitle("") yla(0(20)100, ang(h))
      
      twoway connected participants mdate, sort ///
      xla(`=tm(2016m1)'/`=tm(2016m12)', format(%tmMon) noticks) ///
      ytitle("participants / 147") xtitle("") yla(, ang(h))
      [ATTACH=CONFIG]n1359817[/ATTACH]
      you guessed that right! Yeah, actually putting a bar for the "goal" of 147 would look ugly. The lined scatter is exactly what I wanted. That tag command sort everything out for me.

      Sorry for not being so specific but Thank you very much!

      Comment

      Working...
      X