Announcement

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

  • Time series graphs of counts by different variables - which can be easily manipulated and changed

    Dear all,
    I am trying to make a time-series graph showing count of events; by quarter; in groups who received; or did not receive an intervention (coded as a binary variable; this is the first step but there will be others). An example of my data is copied below.

    Using some code from Nick Cox from this forum, this is possible by:

    Code:
    egen no_int = count(int) if int==0, by(date_quart)
    egen yes_int = count(int) if int==1, by(date_quart)
    egen tag = tag(date_quart)
    twoway line no_int yes_int date_quart if tag, sort
    But this is not really practical for making many exploratory graphs. I would like a solution which I can easily manipulate, something like:

    Code:
    twoway (line int date_quart if int == 0) (line int date_quart if int == 0)
    but I cannot see how to do this with counts.

    Ideally I would prefer not to collapse the data unless this is really the simplest solution.

    Any advice would be much appreciated.

    Josh.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 Agegroup str6 Sex float(intervention date_quart)
    "20-24" "Female" 0 231
    "00-04" "Male"   0 231
    "00-04" "Female" 0 231
    "00-04" "Female" 0 231
    "00-04" "Female" 0 231
    "70-74" "Male"   0 231
    "15-19" "Male"   1 231
    "40-44" "Male"   0 231
    "85+"   "Female" 0 231
    "00-04" "Male"   0 231
    "25-29" "Female" 0 231
    "20-24" "Male"   0 231
    "25-29" "Male"   0 231
    "25-29" "Male"   0 231
    "75-79" "Female" 0 231
    "00-04" "Male"   0 231
    "60-64" "Male"   0 231
    "00-04" "Female" 0 231
    "60-64" "Female" 0 231
    "80-84" "Female" 0 231
    "25-29" "Male"   0 230
    "15-19" "Male"   1 230
    "15-19" "Male"   1 230
    "20-24" "Female" 0 230
    "00-04" "Female" 0 230
    "00-04" "Male"   0 230
    "75-79" "Male"   0 230
    "15-19" "Male"   1 230
    "00-04" "Male"   0 230
    "25-29" "Male"   0 230
    end
    format %tq!Qq-CCYY date_quart

  • #2
    I don't get what you want precisely. Are age and sex relevant or not?

    Code:
    histogram date_quart , by(inter, col(1)) freq
    does the counting for you and shows the two categories of intervention separately..

    Comment


    • #3
      Thanks Nick.
      I am looking for something as you propose but which plots lines (rather than histograms) and on the same graph.

      Age and sex aren't yet relevant yet...but they will be in future. It's the reason I didn't want to collapse because I felt that limits flexibility in exploring the data. Probably I should just get better at using "collapse" and switching between wide and long data. Let me try that.

      Thanks again.

      Josh.

      Comment


      • #4
        Code:
        spikeplot date_quart , by(inter, col(1)) recast(line)

        Comment

        Working...
        X