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

SEPERATING SEASONAL TIME SERIES WITH STATA

8 10 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)

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Winter University of Virginia Jeffrey Wooldridge Michigan State University Stata Press Editorial Manager Stata Press Copy Editors Lisa Gilmore Jennifer Neve and Deirdre Patterson... The S

Trang 1

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

Nathaniel Beck

New York University

Rino Bellocco

Karolinska Institutet, Sweden, and

University of Milano-Bicocca, Italy

Maarten L Buis

Vrije Universiteit, Amsterdam

A Colin Cameron

University of California–Davis

Mario A Cleves

Univ of Arkansas for Medical Sciences

William D Dupont

Vanderbilt University

David Epstein

Columbia University

Allan Gregory

Queen’s University

James Hardin

University of South Carolina

Ben Jann

ETHZ¨urich, Switzerland

Stephen Jenkins

University of Essex

Ulrich Kohler

WZB, Berlin

Frauke Kreuter

University of Maryland–College Park

Jens Lauritsen Odense University Hospital Stanley Lemeshow

Ohio State University

J Scott Long Indiana University

Thomas Lumley University of Washington–Seattle Roger Newson

Imperial College, London Austin Nichols

Urban Institute, WashingtonDC Marcello Pagano

Harvard School of Public Health Sophia Rabe-Hesketh

University of California–Berkeley

J Patrick Royston MRCClinical Trials Unit, London Philip Ryan

University of Adelaide Mark E Schaffer

Heriot-Watt University, Edinburgh Jeroen Weesie

Utrecht University Nicholas J G Winter University of Virginia Jeffrey Wooldridge Michigan State University

Stata Press Editorial Manager

Stata Press Copy Editors

Lisa Gilmore Jennifer Neve and Deirdre Patterson

Trang 2

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:

• RePEc: Research Papers in Economics

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.

Trang 3

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

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 graph-ical 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 roller-coaster 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

method, which is widely used in economics Examples of this method can be found in

Hylleberg(1986,1992),Ghysels and Osborn(2001), andFranses 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 2 traces for half-yearly data, 4 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

of food and tobacco production for the United States for 1947–2000 I downloaded

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

c

Trang 4

322 Stata tip 76

scatter growth year, ms(none) mla(quarter) mlabpos(0)

2 3

4

1

2 3

4

1

2 3

4

1

2 3

4 2 3

4

1

2 3

4

1

2 3

4

1

2 3

4 1 2

4 1

2 3

4 1

2 3

4 1

2 3

4 1

2 3

4 1 2

4 1 2

4 1 2

4 1 2

4 1 2

4 1

2 3

4 1 2

4

2

3

4 1 2

4 1 2 3

4 1 2

4 2

4

2 3

4 1 2

4 1 2

4

2

4 1 2 3

4 2

4 2

4 1

2

4 2 3

4 1

2 3

4 1 2 3

4 1

2 3

4 1 2

4 1 2

4 1 2

4 2

4 1

2 3

4

2 3

4 2 3

4 1 2

4 1

2 3

4 1 2 3

4 1 2

4 1 2

4 1

2 3

4 1 2 3

4 1 2 3

4 1 2 3

4 1 2 3

4

1950 1960 1970 1980 1990 2000

Figure 1 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 1 and 4 No legend is needed for the graph, because the marker labels are self-explanatory

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

Trang 5

N J Cox 323

tsline ftp

1950q1 1960q1 1970q1 1980q1 1990q1 2000q1

date

Figure 2 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)

tsline growth

1950q1 1960q1 1970q1 1980q1 1990q1 2000q1

date

Figure 3 Year-on-year growth by quarter for food and tobacco production in the United States: combined series

Trang 6

324 Stata tip 76

An example with monthly data will push harder at the limits of this device Grubb

for 1947–1999 The data can be found at http://people.bath.ac.uk/mascc/Grubb.TS;

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)

1 3 4 5 6

7 8

9

O

N 1 3 4 5 6

7 8

9

O

N 1 3 5 6

7 8

9

O

N 1

4 5 6

7 8

9

O

N

1 3 4 5 6

7 8

9

O

N 1 2 3

4 5 6

7 8

9

O

N D

1 3 4 5 6

7

9

O

N D

1 3 4 5 6

7 8

9

O

N 1 3 4 5 6 7 8

9

O

N 1 3 4 5 6

7 8

9

O

N 1 2 3 4 5 6

7 8

9

O

N D

1 3

4 5 6

7

9

O

N 1 3 4 5 6

7 8

9

O

N 1 3

4 5

6

7 8

9

O

N 1 3 4 5 6 7 8

9

O

N 1 3 4 5 6

7 8

9

O

N1 3

4 5 6

7

9

O

N 1 3 4 5 6

7 8

9

O

N D 1 2 3 4 5 6

7

9

O

N1 3 4 5 6

7

9

O

N 1 2 3 4 5 6

7 8

9

O

N 1 2 3 4 5 6

7 8

9

O

N 1 3 4 5 6

7

9

O

N 1 2 3 4 5 6 7

O

N 1 2 3 4 6

7 9

O

N

D 1 2 3 4 6 7

O

N 1 2 3 5 6

7 9

O

N 1 2 3 4 5 6

7 9

O

N

D 1 2 3 5 6

7 8 9

O

N 1 2 3 5 6

7 9

O

N

1 3 4 5 6

7 9

O

N

D 1 2 3 5 6 7 8 9

O

N

D 1 2 3 4 5 6 7 8 9

O

N1 3 4 5 6

7 9

O

N

D 1 2 3 5 6

7 9

O

N 1 3 4 5 6 7

O

N 1 3 5 6 7

O

N 1 3 5 6 7 8 9

O

N 1 3 4 5 6

7 9

O

N 1 3 5 6 7

O

N 1 3 5 6 7

O

N

D 1 2 3 4 5 6 7

O

N

D 1 2 3 5 6 7

O

N 1 3 4 5 6 7

O

N 1 3 4 5 6 7

O

N 1 3 5 6 7

O

N 1 3 4 5 6 7

O

N 1 3 5 6 7 O

N 1 3 5 6 7 O

N 1 3 5 6 7 O

N 1 3 5 6 7 O

N D

1950 1960 1970 1980 1990 2000

September; O, N, and D indicate October–December)

Because some users will undoubtedly want line plots, how is that to be done? The

Once we have separate variables, they can be used with the line command (figure 5)

Trang 7

N J Cox 325

separate percent, by(month) veryshortlabel

line percent1-percent12 year, xtitle("") ytitle(% in each month) yla(5(5)15)

> legend(pos(3) col(1))

1950 1960 1970 1980 1990 2000

1 2 3 4 5 6 7 8 9 10 11 12

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 subdi-viding 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,

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.

Trang 8

326 Stata tip 76

Holt–Winters methods with damped trend International Journal of Forecasting 17:

71–82

Hylleberg, S., ed 1992 Modelling Seasonality Oxford: Oxford University Press.

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