Introduction to Time Series Using Stata - Data Analysis and Statistical Software | to Time Series...

download Introduction to Time Series Using Stata - Data Analysis and Statistical Software | to Time Series Using Stata ... 4 A first pass at forecasting 141 ... Stata makes these tasks easy—at

of 27

  • date post

    20-Mar-2018
  • Category

    Documents

  • view

    519
  • download

    38

Embed Size (px)

Transcript of Introduction to Time Series Using Stata - Data Analysis and Statistical Software | to Time Series...

  • Introduction to Time Series Using

    Stata

    SEAN BECKETTI

    A Stata Press PublicationStataCorp LPCollege Station, Texas

  • Copyright c 2013 by StataCorp LPAll rights reserved. First edition 2013

    Published by Stata Press, 4905 Lakeway Drive, College Station, Texas 77845Typeset in LATEX2Printed in the United States of America

    10 9 8 7 6 5 4 3 2 1

    ISBN-10: 1-59718-132-3ISBN-13: 978-1-59718-132-7

    Library of Congress Control Number: 2012951897

    No part of this book may be reproduced, stored in a retrieval system, or transcribed, in anyform or by any meanselectronic, mechanical, photocopy, recording, or otherwisewithoutthe prior written permission of StataCorp LP.

    Stata, , Stata Press, Mata, , and NetCourse are registered trademarks ofStataCorp LP.

    Stata and Stata Press are registered trademarks with the World Intellectual Property Organi-zation of the United Nations.

    LATEX2 is a trademark of the American Mathematical Society.

  • Contents

    List of tables xiii

    List of figures xv

    Preface xxi

    Acknowledgments xxvii

    1 Just enough Stata 1

    1.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    1.1.1 Action first, explanation later . . . . . . . . . . . . . . . . . 2

    1.1.2 Now some explanation . . . . . . . . . . . . . . . . . . . . . 6

    1.1.3 Navigating the interface . . . . . . . . . . . . . . . . . . . . 7

    1.1.4 The gestalt of Stata . . . . . . . . . . . . . . . . . . . . . . . 13

    1.1.5 The parts of Stata speech . . . . . . . . . . . . . . . . . . . 15

    1.2 All about data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    1.3 Looking at data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    1.4 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    1.4.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    1.4.2 Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

    1.5 Odds and ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

    1.6 Making a date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

    1.6.1 How to look good . . . . . . . . . . . . . . . . . . . . . . . . 63

    1.6.2 Transformers . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    1.7 Typing dates and date variables . . . . . . . . . . . . . . . . . . . . . 68

    1.8 Looking ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

    2 Just enough statistics 71

    2.1 Random variables and their moments . . . . . . . . . . . . . . . . . . 72

  • vi Contents

    2.2 Hypothesis tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

    2.3 Linear regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

    2.3.1 Ordinary least squares . . . . . . . . . . . . . . . . . . . . . 74

    2.3.2 Instrumental variables . . . . . . . . . . . . . . . . . . . . . 77

    2.3.3 FGLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

    2.4 Multiple-equation models . . . . . . . . . . . . . . . . . . . . . . . . 78

    2.5 Time series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    2.5.1 White noise, autocorrelation, and stationarity . . . . . . . . 80

    2.5.2 ARMA models . . . . . . . . . . . . . . . . . . . . . . . . . 82

    3 Filtering time-series data 85

    3.1 Preparing to analyze a time series . . . . . . . . . . . . . . . . . . . . 87

    3.1.1 Questions for all types of data . . . . . . . . . . . . . . . . . 87

    How are the variables defined? . . . . . . . . . . . . . . . . . 87

    What is the relationship between the data and the phe-nomenon of interest? . . . . . . . . . . . . . . . . . 88

    Who compiled the data? . . . . . . . . . . . . . . . . . . . . 90

    What processes generated the data? . . . . . . . . . . . . . 90

    3.1.2 Questions specifically for time-series data . . . . . . . . . . . 91

    What is the frequency of measurement? . . . . . . . . . . . 91

    Are the data seasonally adjusted? . . . . . . . . . . . . . . . 91

    Are the data revised? . . . . . . . . . . . . . . . . . . . . . . 91

    3.2 The four components of a time series . . . . . . . . . . . . . . . . . . 92

    Trend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

    Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

    Seasonal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

    3.3 Some simple filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

    3.3.1 Smoothing a trend . . . . . . . . . . . . . . . . . . . . . . . 103

    3.3.2 Smoothing a cycle . . . . . . . . . . . . . . . . . . . . . . . . 109

    3.3.3 Smoothing a seasonal pattern . . . . . . . . . . . . . . . . . 114

    3.3.4 Smoothing real data . . . . . . . . . . . . . . . . . . . . . . 115

  • Contents vii

    3.4 Additional filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

    3.4.1 ma: Weighted moving averages . . . . . . . . . . . . . . . . 123

    3.4.2 EWMAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

    exponential: EWMAs . . . . . . . . . . . . . . . . . . . . . . 126

    dexponential: Double-exponential moving averages . . . . . 130

    3.4.3 HoltWinters smoothers . . . . . . . . . . . . . . . . . . . . 131

    hwinters: HoltWinters smoothers without a seasonalcomponent . . . . . . . . . . . . . . . . . . . . . . 131

    shwinters: HoltWinters smoothers including a seasonalcomponent . . . . . . . . . . . . . . . . . . . . . . 137

    3.5 Points to remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

    4 A first pass at forecasting 141

    4.1 Forecast fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . 141

    4.1.1 Types of forecasts . . . . . . . . . . . . . . . . . . . . . . . . 142

    4.1.2 Measuring the quality of a forecast . . . . . . . . . . . . . . 144

    4.1.3 Elements of a forecast . . . . . . . . . . . . . . . . . . . . . 144

    4.2 Filters that forecast . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

    4.2.1 Forecasts based on EWMAs . . . . . . . . . . . . . . . . . . 148

    4.2.2 Forecasting a trending series with a seasonal component . . 159

    4.3 Points to remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

    4.4 Looking ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

    5 Autocorrelated disturbances 167

    5.1 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

    5.1.1 Example: Mortgage rates . . . . . . . . . . . . . . . . . . . 169

    5.2 Regression models with autocorrelated disturbances . . . . . . . . . 172

    5.2.1 First-order autocorrelation . . . . . . . . . . . . . . . . . . . 173

    5.2.2 Example: Mortgage rates (cont.) . . . . . . . . . . . . . . . 175

    5.3 Testing for autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . 176

    5.3.1 Other tests . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

    5.4 Estimation with first-order autocorrelated data . . . . . . . . . . . . 178

  • viii Contents

    5.4.1 Model 1: Strictly exogenous regressors and autocorre-lated disturbances . . . . . . . . . . . . . . . . . . . . . . . . 179

    The OLS strategy . . . . . . . . . . . . . . . . . . . . . . . . 181

    The transformation strategy . . . . . . . . . . . . . . . . . . 183

    The FGLS strategy . . . . . . . . . . . . . . . . . . . . . . . 185

    Comparison of estimates of model 1 . . . . . . . . . . . . . . 188

    5.4.2 Model 2: A lagged dependent variable and i.i.d. errors . . . 189

    5.4.3 Model 3: A lagged dependent variable with AR(1) errors . . 192

    The transformation strategy . . . . . . . . . . . . . . . . . . 193

    The IV strategy . . . . . . . . . . . . . . . . . . . . . . . . . 195

    5.5 Estimating the mortgage rate equation . . . . . . . . . . . . . . . . . 196

    5.6 Points to remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

    6 Univariate time-series models 201

    6.1 The general linear process . . . . . . . . . . . . . . . . . . . . . . . . 202

    6.2 Lag polynomials: Notation or prestidigitation? . . . . . . . . . . . . 203

    6.3 The ARMA model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

    6.4 Stationarity and invertibility . . . . . . . . . . . . . . . . . . . . . . 208

    6.5 What can ARMA models do? . . . . . . . . . . . . . . . . . . . . . . 210

    6.6 Points to remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

    6.7 Looking ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

    7 Modeling a real-world time series 217

    7.1 Getting ready to model a time series . . . . . . . . . . . . . . . . . . 218

    7.2 The BoxJenkins approach . . . . . . . . . . . . . . . . . . . . . . . 226

    7.3 Specifying an ARMA model . . . . . . . . . . . . . . . . . . . . . . . 228

    7.3.1 Step 1: Induce stationarity (ARMA becomes ARIMA) . . . 228

    7.3.2 Step 2: Mind your ps and qs . . . . . . . . . . . . . . . . . 233

    7.4 Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

    7.5 Looking for trouble: Model diagnostic checking . . . . . . . . . . . . 253

    7.5.1 Overfitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

    7.5.2 Tests of the residuals . . . . . . . . . . . . . . . . . . . . . . 254

  • Contents ix

    7.6 Forecasting with ARIMA models . . . . . . . . . . . . . . . . . . . . 257

    7.7 Comparing forecasts . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

    7.8 Points to remember . . . . . . . . . .