Announcement

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

  • How to draw this graph with Stata? Tempogram?

    Hi. I want to draw this graph with time use data and have been failing to produce one.
    What would be the ways to draw this graph?
    I was told by someone that this is the basic tempogram, but I still couldn't figure out how to do it.
    I do hope to receive some help from you.

    Thank you.

    Click image for larger version

Name:	stata graph.png
Views:	1
Size:	272.7 KB
ID:	1492904

  • #2
    Dear Eunhye,

    Please consult the FAQ page, and read the paragraph: 12.2 What to say about your data

    Next: use dataex to provide some sample of your data (i.e. variables).
    That should be helpful for those who possibly can help you.

    -------------------------

    I suppose what you show is a -so called- stacked area chart/plot/graph.
    This is discussed with an example here at the statalist.

    I hope this helps.
    Eric
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Code:
      // ------------------------------------ create an example dataset
      
      clear all
      set obs 1000
      gen u = .
      forvalues i = 1/24 {
          if inlist(`i', 23, 24, 1, 2, 3, 4, 5, 6, 7) {
              local psleep   = .8
              local pwork    = .1
          }
          else if inrange(`i',9,17) {
              local psleep   = .1
              local pwork    = .8
          }
          else {
              local psleep   = .3
              local pwork    = .2
          }
      
          replace u = runiform()
          gen sleep`i' = u < `psleep'
          gen work`i' = u >= `psleep' & u < `psleep' + `pwork'
          gen private`i' = u >= `psleep' + `pwork'
      }
      drop u
      
      // -------------------------------------- start making the graph
      
      // we need an id-variable, maybe one already exist in your data
      // in that case you can skip this step and use that id instead
      gen id = _n
      
      // create a dataset that for each (in this case) hour shows the
      // proportion in each activity
      reshape long sleep work private, i(i) j(hour)
      collapse (mean) sleep work private, by(hour)
      
      // turn proportions in percentages
      replace sleep   = sleep   * 100
      replace work    = work    * 100
      replace private = private * 100
      
      // turn percentages in cumulative percentages
      replace work = sleep + work
      replace private = 100
      
      // make the graph
      twoway area private hour ||      ///
             area work    hour ||      ///
             area sleep   hour,        ///
             xlab(1 6 12 18 24)        ///
             plotregion(margin(zero))  ///
             legend(order(1 "private"  ///
                          2 "work"     ///
                          3 "sleep"))  ///
             ytitle(percentage)        ///
             xtitle(hour of day)
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        If you don't give your data to me (see the FAQ) there isn't much I can do.... Instead I had to create some example data. I made it such that it has a similar structure as you described, except, to make it more manageable, I chose hourly intervals rather than 10 minute intervals. That does not change the relevant parts of the code. It is now up to you to adapt my example to your problem.

        What you need to do is replace the first part of that code (labeled "create an example dataset") with just opening your dataset. You don't want to create data, you already have it. I only made some artificial data because you did not give the data to us. All you have to do is just open the data you have. In the remaining code you need to change the variable names, for example sleep with ActA (no number, that is what reshape takes care of), probably you want to change the name "hour" to something like "time" to avoid confusion. You will need to change the xlab() option to something more reasonable for 10 minute intervals. If you are uncertain about what a command does, just look at the help file for that command, or look at the data before and after the command was executed. Other than that you should be fine.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X