1. Trang chủ
  2. » Thể loại khác

SEPERATING SEASONAL TIME SERIES WITH STATA

8 9 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 228,09 KB
File đính kèm 86. SEPERATING SEASONAL TIME SERIES WITH STATA.rar (210 KB)

Nội dung

The Stata Journal Editor H Joseph Newton Department of Statistics Texas A&M University College Station, Texas 77843 979-845-8817; fax 979-845-6077 jnewton@stata-journal.com Editor Nicholas J Cox Department of Geography Durham University South Road Durham City DH1 3LE UK n.j.cox@stata-journal.com Associate Editors Christopher F Baum Boston College Jens Lauritsen Odense University Hospital Nathaniel Beck New York University Stanley Lemeshow Ohio State University Rino Bellocco Karolinska Institutet, Sweden, and University of Milano-Bicocca, Italy J Scott Long Indiana University Maarten L Buis Vrije Universiteit, Amsterdam Thomas Lumley University of Washington–Seattle A Colin Cameron University of California–Davis Roger Newson Imperial College, London Mario A Cleves Univ of Arkansas for Medical Sciences Austin Nichols Urban Institute, Washington DC William D Dupont Vanderbilt University Marcello Pagano Harvard School of Public Health David Epstein Columbia University Sophia Rabe-Hesketh University of California–Berkeley Allan Gregory Queen’s University J Patrick Royston MRC Clinical Trials Unit, London James Hardin University of South Carolina Philip Ryan University of Adelaide Ben Jann ETH Ză urich, Switzerland Mark E Schaffer Heriot-Watt University, Edinburgh Stephen Jenkins University of Essex Jeroen Weesie Utrecht University Ulrich Kohler WZB, Berlin Nicholas J G Winter University of Virginia Frauke Kreuter University of Maryland–College Park Jeffrey Wooldridge Michigan State University Stata Press Editorial Manager Stata Press Copy Editors Lisa Gilmore Jennifer Neve and Deirdre Patterson The Stata Journal publishes reviewed papers together with shorter notes or comments, regular columns, book reviews, and other material of interest to Stata users Examples of the types of papers include 1) expository papers that link the use of Stata commands or programs to associated principles, such as those that will serve as tutorials for users first encountering a new field of statistics or a major new technique; 2) papers that go “beyond the Stata manual” in explaining key features or uses of Stata that are of interest to intermediate or advanced users of Stata; 3) papers that discuss new commands or Stata programs of interest either to a wide spectrum of users (e.g., in data management or graphics) or to some large segment of Stata users (e.g., in survey statistics, survival analysis, panel analysis, or limited dependent variable modeling); 4) papers analyzing the statistical properties of new or existing estimators and tests in Stata; 5) papers that could be of interest or usefulness to researchers, especially in fields that are of practical importance but are not often included in texts or other journals, such as the use of Stata in managing datasets, especially large datasets, with advice from hard-won experience; and 6) papers of interest to those who teach, including Stata with topics such as extended examples of techniques and interpretation of results, simulations of statistical concepts, and overviews of subject areas For more information on the Stata Journal, including information for authors, see the web page http://www.stata-journal.com The Stata Journal is indexed and abstracted in the following: • CompuMath Citation Index R • RePEc: Research Papers in Economics • Science Citation Index Expanded (also known as SciSearch R ) Copyright Statement: The Stata Journal and the contents of the supporting files (programs, datasets, and help files) are copyright c by StataCorp LP The contents of the supporting files (programs, datasets, and help files) may be copied or reproduced by any means whatsoever, in whole or in part, as long as any copy or reproduction includes attribution to both (1) the author and (2) the Stata Journal The articles appearing in the Stata Journal may be copied or reproduced as printed copies, in whole or in part, as long as any copy or reproduction includes attribution to both (1) the author and (2) the Stata Journal Written permission must be obtained from StataCorp if you wish to make electronic copies of the insertions This precludes placing electronic copies of the Stata Journal, in whole or in part, on publicly accessible web sites, fileservers, or other locations where the copy may be accessed by anyone other than the subscriber Users of any of the software, ideas, data, or other materials published in the Stata Journal or the supporting files understand that such use is made without warranty of any kind, by either the Stata Journal, the author, or StataCorp In particular, there is no warranty of fitness of purpose or merchantability, nor for special, incidental, or consequential damages such as loss of profits The purpose of the Stata Journal is to promote free communication among Stata users The Stata Journal, electronic version (ISSN 1536-8734) is a publication of Stata Press Stata and Mata are registered trademarks of StataCorp LP The Stata Journal (2009) 9, Number 2, pp 321–326 Stata tip 76: Separating seasonal time series Nicholas J Cox Department of Geography Durham University Durham, UK n.j.cox@durham.ac.uk Many researchers in various sciences deal with seasonally varying time series The part rhythmic, part random character of much seasonal variation poses several graphical challenges for them People usually want to see both the broad pattern and the fine structure of trends, seasonality, and any other components of variation The very common practice of using just one plot versus date typically yields a saw-tooth or rollercoaster pattern as the seasons repeat That method is often good for showing broad trends, but not so good for showing the details of seasonality I reviewed several alternative graphical methods in a Speaking Stata column (Cox 2006) Here is yet another method, which is widely used in economics Examples of this method can be found in Hylleberg (1986, 1992), Ghysels and Osborn (2001), and Franses and Paap (2004) The main idea is remarkably simple: plot separate traces for each part of the year Thus, for each series, there would be traces for half-yearly data, traces for quarterly data, 12 traces for monthly data, and so on The idea seems unlikely to work well for finer subdivisions of the year, because there would be too many traces to compare However, quarterly and monthly series in particular are so common in many fields that the idea deserves some exploration One of the examples in Franses and Paap (2004) concerns variations in an index of food and tobacco production for the United States for 1947–2000 I downloaded the data from http://people.few.eur.nl/paap/pbook.htm (this URL evidently supersedes those specified by Franses and Paap [2004, 12]) and named it ftp For what follows, year and quarter variables are required, as well as a variable holding quarterly dates egen year = seq(), from(1947) to(2000) block(4) egen quarter = seq(), to(4) gen date = yq(year, quarter) format date %tq tsset date gen growth = D1.ftp/ftp Although a line plot is clearly possible, a scatterplot with marker labels is often worth trying first (figure 1) See an earlier tip by Cox (2005) for more examples c 2009 StataCorp LP gr0037 322 Stata tip 76 scatter growth year, ms(none) mla(quarter) mlabpos(0) 3 growth 2 2 3333 33 2222 22 2 −.1 333 333 3 3 2 233 333 323 33323223 23 33 2323 3 2 22 2332 33 232322 2 2 22 2 2 1 1 1 111 14 114 44 141 1 1111 11 11 441 44 414444 11 1414 11 44 4 11 141 4 44 4 4 4 1 4 4 4 4 41 4 4 41 44 4 11 11 −.2 1950 1960 1970 1980 1990 2000 Figure Year-on-year growth by quarter for food and tobacco production in the United States: separate series Immediately, we see some intriguing features in the data There seems to be a discontinuity in the early 1960s, which may reflect some change in the basis of calculating the index, rather than a structural shift in the economy or the climate Note also that the style and the magnitude of seasonality change: look in detail at traces for quarters and No legend is needed for the graph, because the marker labels are self-explanatory Compare this graph with the corresponding line plot given by Franses and Paap (2004, 15) In contrast, only some of the same features are evident in more standard graphs The traditional all-in-one line plot (figure 2) puts seasonality in context but is useless for studying detailed changes in its nature N J Cox 323 20 Food and tobacco production 40 60 80 100 120 tsline ftp 1950q1 1960q1 1970q1 date 1980q1 1990q1 2000q1 Figure Quarterly food and tobacco production in the United States The apparent discontinuity in the early 1960s is, however, clear in a plot of growth rate versus date (figure 3) −.2 −.1 growth tsline growth 1950q1 1960q1 1970q1 date 1980q1 1990q1 2000q1 Figure Year-on-year growth by quarter for food and tobacco production in the United States: combined series 324 Stata tip 76 An example with monthly data will push harder at the limits of this device Grubb and Mason (2001) examined monthly data on air passengers in the United Kingdom for 1947–1999 The data can be found at http://people.bath.ac.uk/mascc/Grubb.TS; also see Chatfield (2004, 289–290) We will look at seasonality as expressed in monthly shares of annual totals (figure 4) The graph clearly shows how seasonality is steadily becoming more subdued > egen total = total(passengers), by(year) gen percent = 100 * passengers / total gen symbol = substr("123456789OND", month, 1) scatter percent year, ms(none) mla(symbol) mlabpos(0) mlabsize(*.8) xtitle("") ytitle(% in each month) yla(5(5)15) 15 8 % in each month 10 8 8 8 8 8 7 7 8 8 8 7 9 9 9 9 9 9 9 9 9 8 6 9 8 9 7 8 8 8 7 7 7 6 6 6 9 8 6 7 9 8 8 6 9 9 7 8 8 7 6 9 9 6 6 9 9 7 7 6 6 6 9 9 6 6 6 6 6 6 6 6 6O 6 6O O O OO OO OOOO O OO 5 O O O O 5 O 5O 5 5 5 5 5 5 5O 5 5O O O5 5O5 5 5O 5 5 O O 5 5 O 5 O5 O 4 4 4 OOOO 5 4 4 O OO OOO O OO O4 4 4 4 4 O4 4 4 4 3 4 4 O4O O 3 4 4 N 3 3N O4 3 DNNN NN3 3 3 D N D DD N 3DDN N N N N D N D N N 3 N D D D N 3DD 1N DD1 DNN1N NNN 1 DD DN D 2 D DDDD 1N 3N 1 DD1 1 1 2 1 D 3D 2 2 D 3N D3 3N 2 D 3 D D 3D3 3D 3DD D3DND D3 2 2 2 D N D D N D 2 N NNN 3N N 3N3D N N 1N D N3ND 1N1 1 N N 3D 1 N 1 N 2 2 2 1 2 2 2 2 1 2 2 2 7 8 1950 7 7 7 1960 1970 1980 1990 2000 Figure Monthly shares of UK air passengers, 1947–1999 (digits 1–9 indicate January– September; O, N, and D indicate October–December) Because some users will undoubtedly want line plots, how is that to be done? The separate command is useful here: see Cox (2005), [D] separate, or the online help Once we have separate variables, they can be used with the line command (figure 5) N J Cox 325 15 separate percent, by(month) veryshortlabel line percent1-percent12 year, xtitle("") ytitle(% in each month) yla(5(5)15) > legend(pos(3) col(1)) % in each month 10 10 11 12 1950 1960 1970 1980 1990 2000 Figure Monthly shares of UK air passengers, 1947–1999 You may think that the graph needs more work on the line patterns (and thus the legend), although perhaps now the scatterplot with marker labels seems a better possibility If graphs with 12 monthly traces seem too busy, one trick worth exploring is subdividing the year into two, three, or four parts and using separate panels in a by() option Then each panel would have only six, four, or three traces References Chatfield, C 2004 The Analysis of Time Series: An Introduction 6th ed Boca Raton, FL: Chapman & Hall/CRC Cox, N J 2005 Stata tip 27: Classifying data points on scatter plots Stata Journal 5: 604–606 ——— 2006 Speaking Stata: Graphs for all seasons Stata Journal 6: 397–419 Franses, P H., and R Paap 2004 Periodic Time Series Models Oxford: Oxford University Press Ghysels, E., and D R Osborn 2001 The Econometric Analysis of Seasonal Time Series Cambridge: Cambridge University Press 326 Stata tip 76 Grubb, H., and A Mason 2001 Long lead-time forecasting of UK air passengers by Holt–Winters methods with damped trend International Journal of Forecasting 17: 71–82 Hylleberg, S 1986 Seasonality in Regression Orlando, FL: Academic Press Hylleberg, S., ed 1992 Modelling Seasonality Oxford: Oxford University Press ... Stata and Mata are registered trademarks of StataCorp LP The Stata Journal (2009) 9, Number 2, pp 321–326 Stata tip 76: Separating seasonal time series Nicholas J Cox Department of Geography... The purpose of the Stata Journal is to promote free communication among Stata users The Stata Journal, electronic version (ISSN 1536-8734) is a publication of Stata Press Stata and Mata are registered... n.j.cox@durham.ac.uk Many researchers in various sciences deal with seasonally varying time series The part rhythmic, part random character of much seasonal variation poses several graphical challenges

Ngày đăng: 02/09/2021, 10:13

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w