help for cycleplot

Cycle plot (month plot or seasonal subseries plot)

cycleplot responsevars month year [if exp] [in range] [, length(#) start(#) summary(egen_function) mylabels(labels_list) line_options ]


cycleplot produces a graph of one or more responsevars by month and year. responsevars may be raw data or the seasonal components of such data. The descriptors month and year are used for concreteness. For month and year, read strictly shorter period and longer period. That is, the plot may be useful whenever periods (e.g. years) are divided into a fixed number of shorter periods (e.g. months, quarters). month should be a variable taking on values 1,...,length. The graph shows a fixed number of subseries, one for each distinct month. The data are also sorted so that there are no connections between subseries.

Terminology for this plot is not stable. See notes with References.


Note that you can get close to this kind of plot with no more than official Stata, as in

. twoway line air year, by(month, row(1))

The advantages of cycleplot include more space being used to show data on the plot; the flexibility of different starts to the cycle; and the possibility of comparison with a subseries summary.


length(#) indicates that data are for # shorter periods within each longer period. The default is 12, for months within a year.

start(#) indicates the first value of month plotted on the x axis. Default 1. This option may be used whenever there is some better natural start to the year than (say) January. For example, rainfall in climates with a wet season either side of December is best plotted starting in (say) July.

summary(egen_function) calculates a summary function to be shown for each month. The summary function may be any function acceptable to egen that has syntax like egen newvar = mean(response), by(month). mean and median are the most obvious possibilities. Know that whenever summaries are plotted the order of variables on the graph is all the response variables followed by all the corresponding summary variables.

mylabels(labels_list) specifies text labels to use on the time axis, instead of default labels such as 1/12. The number of labels specified should be precisely the same as the argument of length(), or by default 12. Labels consisting of two or more words should be bound in " ". Labels including " should be bound in `" "'. Note that mylabels(`c(Mons)') specifies Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec and that mylabels(`c(Months)') specifies January February ... November December. Do not rotate the list to reflect a start() choice other than 1. This will be done automatically.

line_options refers to options of graph twoway line. connect(L ..) is wired in. Note the possibility of using recast() to get a different twoway type.

Examples . cycleplot rainfall month year, xla(1/12) . cycleplot rainfall month year, xla(1/12) start(7)

. cycleplot GDP quarter year, length(4)

. webuse air2, clear . egen month = seq(), to(12) . gen year = floor(time) . cycleplot air month year, xla(1/12) start(2) yscale(log) su(median) . cycleplot air month year, xla(1/12) start(2) yscale(log) su(median) myla(`c(Mons)') . cycleplot air month year, xla(1/12) start(2) yscale(log) su(median) myla(J F M A M J J A S O N D)

. cycleplot males females month year, start(8) recast(connected) ysc(log) yla(3000 2000 1000 500 300) yla(, ang(h)) legend(col(1) pos(11) ring(0)) mylabels(`c(Mons)') subtitle("UK deaths from bronchitis, emphysema and asthma 1974-79") msize(*0.8 ..)


A question from Aurelio Tobias led to the mylabels() option.


Nicholas J. Cox, Durham University n.j.cox@durham.ac.uk


Original references:

Becker, R.A., Chambers, J.M. and Wilks, A.R. 1988. The new S language: a programming environment for data analysis and graphics. Pacific Grove, CA: Wadsworth & Brooks/Cole, pp.508-509. [month plot]

Cleveland, R.B., Cleveland, W.S., McRae, J.E. and Terpenning, I. 1990. STL: a seasonal-trend decomposition procedure based on loess. Journal of Official Statistics 6: 3-73. [cycle-subseries plot]

Cleveland, W.S. 1993. Visualizing data. Summit, NJ: Hobart Press, pp.164-165. [cycle plot]

Cleveland, W.S. 1994. The elements of graphing data. Summit, NJ: Hobart Press, pp.186-187. [cycle plot]

Cleveland, W.S. and Devlin, S.J. 1980. Calendar effects in monthly time series: detection by spectrum analysis and graphical methods. Journal, American Statistical Association 75: 487-496. [seasonal-by-month plot]

Cleveland, W.S., Freeny, A.E. and Graedel, T.E. 1983. The seasonal component of atmospheric CO2: information from new approaches to the decomposition of seasonal time series. Journal of Geophysical Research 88: 10934-10946. [seasonal subseries plot]

Cleveland, W.S. and Terpenning, I.J. 1982. Graphical methods for seasonal adjustment. Journal, American Statistical Association 77: 52-62. [seasonal subseries plot]

Robbins, N.M. 2005. Creating more effective graphs. Hoboken, NJ: John Wiley. [month plot, cycle plot]

More on c() lists:

Cox, N.J. 2004. Following special sequences. Stata Journal 4(2): 223.

Also see

On-line: help for graph twoway line, egen, creturn