Announcement

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

  • Split a string into numbers and graph

    Hi everyone,

    I have a string variable in Stata called runningdays. It denotes all of the days in which people ran, for example, for the first person, he ran for day 1, day2, day 3, till day 11. For the fourth last person, he ran for day 8 only.

    I need to make a graph which shows the days on which the people ran. Like, on day1, 6 people ran, on day 2, 6 people ran, on day 12, 7 people ran, on day 15, 7 people ran, etc.

    Can someone help me with this please? I cannot figure out how to split runningdays and then make a graph.

    Thank you!

    runningdays
    1 2 3 4 5 6 7 8 9 10 11
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    12 13 14 15
    12 13 14 15
    3 4
    3 9 10
    12 13 14 15
    8
    12 13 14 15
    1 2 3 4 5 6 7 8 9 10 11
    1 2 3 4 5 6 7 8 9 10 11
    Last edited by Mantasha Husain; 13 May 2021, 05:18.

  • #2
    Code:
    *Example generated by -dataex-. For more info, type help dataex
    clear
    input str35 runningdays
    "1 2 3 4 5 6 7 8 9 10 11"            
    "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
    "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
    "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
    "12 13 14 15"                        
    "12 13 14 15"                        
    "3 4"                                
    "3 9 10"                             
    "12 13 14 15"                        
    "8"                                  
    "12 13 14 15"                        
    "1 2 3 4 5 6 7 8 9 10 11"            
    "1 2 3 4 5 6 7 8 9 10 11"            
    end
    
    gen id = _n
    quietly  split runningdays, destring
    drop runningdays
    reshape long runningdays, i(id)
    drop if missing(runningdays) 
    histogram runningdays , discrete barwidth(0.6) freq xla(1/15) blcolor(blue) bfcolor(blue*0.2)

    Comment


    • #3
      Here is something that I occasionally see. I think they are called punchcard charts.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float id byte(day1 day2 day3 day4 day5 day6 day7 day8 day9 day10) double day11 byte(day12 day13 day14 day15)
       1 1 2 3 4 5 6 7 8 9 10 11  .  .  .  .
       2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
       3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
       4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
       5 . . . . . . . . .  .  . 12 13 14 15
       6 . . . . . . . . .  .  . 12 13 14 15
       7 . . 3 4 . . . . .  .  .  .  .  .  .
       8 . . 3 . . . . . 9 10  .  .  .  .  .
       9 . . . . . . . . .  .  . 12 13 14 15
      10 . . . . . . . 8 .  .  .  .  .  .  .
      11 . . . . . . . . .  .  . 12 13 14 15
      12 1 2 3 4 5 6 7 8 9 10 11  .  .  .  .
      13 1 2 3 4 5 6 7 8 9 10 11  .  .  .  .
      end
      
      reshape long day, i(id) j(which)
      *ADD FICTIONAL LABELS
      lab def id 1 "Audrey" 2 "Jack" 3 "James" 4 "Alfie" 5 "Edward" 6 "Ella" ///
      7 "Archer" 8 "Brooks" 9 "Carter" 10 "Fletcher" 11 "Graham" 12 "Huxley" 13 "Reed"
      lab values id id
      *GRAPH
      tw (scatter id which, msize(vlarge)  mc(gray%20) scheme(s1color) ///
      ylab(1/13, val angle(horiz) noticks) ytitle("") xlab(1/15, noticks) sort) ///
      (scatter id day, mc(black) msize(vlarge) legend(order(2 "Running day")))
      Res.:
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	119.6 KB
ID:	1609371

      Comment

      Working...
      X