Announcement

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

  • limit number of graphs/page?

    From a novice:

    I have longitudinal weight data on ~75 individuals. I would like to create graphs for each individual, and display them with no more than ~9 graphs per page.
    I can generate all 75 on one page via:

    graph twoway scatter wt time, by(id)

    But, that's impossible to read.
    Is there a way to limit the number of graphs "per page"?

    Thanks!

  • #2
    This forum is for questions about Statalist, not for questions about Stata. Please post in the General forum.

    That said, you can set up a loop that creates separate graphs. Below is an example with the auto data that comes with Stata. If you want a different number of sub-graphs per graph, replace the number 9 by a different number in the two lines where it appears.
    Code:
    sysuse auto, clear
    encode make, gen(id)
    * Count the number of observations
    sum id
    * Specify the number of iterations (=number of graphs)
    local j = ceil(r(N)/9)
    * Loop that creates j graphs with up to 9 sub-graphs each
    forval i = 1/`j' {
      scatter mpg weight if id>((`i'-1)*9) & id<=(`i'*9), by(id) name(g`i', replace)
    }
    If you want to save the graphs, add another command to the loop.
    Code:
    forval i = 1/`j' {
      scatter mpg weight if id>((`i'-1)*9) & id<=(`i'*9), by(id) name(g`i', replace)
      graph export "g`i'.png", replace
    }
    Last edited by Friedrich Huebler; 19 Aug 2015, 16:53.

    Comment


    • #3
      Sorry for being in the wrong forum.
      But, thank you very much for the response (and for the terrific page about how to integrate a text editor with Stata)!

      Comment


      • #4
        One question: I do not understand the g in the name(g`i', replace).
        I gather it somehow extracts the value label, but I've been unable to figure out just how.
        Thanks again!

        Comment


        • #5
          The name() option assigns a name to a graph in memory.
          Code:
          help name_option
          The "g" is a prefix for the counter i. I could also have spelled out "graph", which would have yielded a series of graphs with the names "graph1", "graph2" and so on.
          Code:
          name(graph`i', replace)

          Comment


          • #6
            Of course... Thanks again, very much.

            Comment

            Working...
            X