TOPIC 6: BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Time Series Data: What’s Different? Lags, Differences, Autocorrelation Dynamic Causal Effects Classical Assumptions 1 Trend and seasonality TIME SERIES DATA: WHAT’S DIFFERENT? Time series data are data collected on the same observational unit at multiple time periods Aggregate consumption and GDP for a country (for example, 20 years of quarterly observations = 80 observations) Yen/$, pound/$ and Euro/$ exchange rates (daily data for 1 year = 365 observations) Cigarette consumption per capita in California, by year (annual data) 2 TIME SERIES DATA: WHAT’S DIFFERENT? Answer quantitative questions for which cross-sectional data are inadequate. dynamic causal effect: what is the causal effect on a variable of interest, Y, of a change in another variable, X, over time? If the Fed increases the Federal Funds rate now, what will be the effect on the rates of inflation and unemployment in 3 months? in 12 months? What is the effect over time on cigarette consumption of a hike in the cigarette tax? 3 TIME SERIES DATA: WHAT’S DIFFERENT? economic forecasting: what is your best forecast of the value of some variable at a future date? E.g., what is your best forecast of next month’s unemployment rate, interest rates, or stock prices? • Modeling risks used in financial markets (e.g., modeling changing variances and “volatility clustering”) • Applications outside of economics include environmental and climate modeling, engineering (system dynamics), computer science (network dynamics),… Time series data pose special challenges, and overcoming those challenges requires some new techniques. 4 TIME SERIES DATA: WHAT’S DIFFERENT? Unlike cross-section data, time series data has a temporal ordering: the past can affect the future, but not vice versa. Need to alter some of our assumptions since we no longer have a random sample of individuals. Instead, we have a stochastic (i.e. random) process, i.e. a sequence of random variables indexed by time. One realization of a stochastic (i.e. random) process is a time series data. 5 TIME SERIES DATA RAISES NEW TECHNICAL ISSUES Time lags • Correlation over time (serial correlation, a.k.a. autocorrelation – which we encountered in panel data) • Calculation of standard errors when the errors are serially correlated A good way to learn about time series data is to investigate it yourself! A great source for U.S. macro time series data, and some international data, is the Federal Reserve Bank of St. Louis’s FRED database. The following are some U.S. macro and financial time series, from FRED 6 https://fred.stlouisfed.org/series/GDPC1 • LOADING DATA IN STATA FROM FRED First install the freduse utility. . ssc install freduse If you know the name of the series you want, you can then directly import them into STATA using the freduse command. For example, quarterly real GDP is GDPC1, and quarterly real GDP percent change from previous period is A191RL1Q225SBEA. . freduse GDPC1 A191RL1Q225SBEA The exact spelling, including capitalization, is required. If the command is successful, the variables are now in the STATA file, with these names. Also two time indices are included, date and daten. The date formats are off creating a time index. 7 LOADING DATA IN STATA FROM FRED create a time index using the tsmktim . ssc install tsmktim Suppose the first observation is the 1st quarter of 1947. . generate time=tq(1947q1)+_n-1 . format time %tq . tsset time The format command formats the variable time with the time-series quarterly format. The “tq” refers to “time series quarterly”. The tsset command declares that the variable time is the time index. Alternatively . tsmktim time, start(1947q1) . tsset time 8 LOADING DATA IN STATA FROM FRED To learn the desired name of the series you want (you want a precise series, so do not guess!), go to FRED website. After loading the data into STATA, you should verify that the data loaded correctly. Examine the entries using the Data Editor. Make a time series plot. Also, change the variable names into something more convenient for use. 9 U.S. REAL GDP U.S. REAL GDP (PERCENTAGE CHANGE) SOME MONTHLY U.S. MACRO AND FINANCIAL TIME SERIES 12 SOME MONTHLY U.S. MACRO AND FINANCIAL TIME SERIES 13 SOME MONTHLY U.S. MACRO AND FINANCIAL TIME SERIES 14 A DAILY U.S. FINANCIAL TIME SERIES: 15 TIME SERIES BASICS Notation Lags, first differences, and growth rates, and first log diference approximation to growth rates Autocorrelation (serial correlation) 16 NOTATION Yt = value of Y in period t. Data set: {Y1,…,YT} are T observations on the time series variable Y We consider only consecutive, evenly-spaced observations (for example, monthly, 1960 to 1999, no missing months) (missing and unevenly spaced data introduce technical complications) 17 LAGS, FIRST DIFFERENCES, AND GROWTH RATES Lags, First Differences, Logarithms, and Growth Rates The first lag of a time series Yt is Yt–1; its jth lag is Yt–j. The first difference of a series, ΔYt, is its change between periods t – 1 and t, that is, ΔYt = Yt – Yt–1. The first difference of the logarithm of Yt is Δln(Yt) = ln(Yt) – ln(Yt–1). The percentage change of a time series Yt between periods t – 1 and t is approximately 100Δln(Yt), where the approximation is most accurate when the percentage change is small. 18 STATA COMMANDS FOR SOME TIME SERIES OPERATORS 19 EXAMPLE: QUARTERLY RATE OF GROWTH OF U.S. GDP AT AN ANNUAL RATE GDP = Real GDP in the US (Billions of $2009) GDP in the fourth quarter of 2016 (2016:Q4) = 16851 GDP in the first quarter of 2017 (2017:Q1) = 16903 Percentage change in GDP, 2016:Q4 to 2017:Q1 16903 − 16851 = 100 × 0.31% = 16851 Percentage change in GDP, 2012:Q1 to 2012:Q2, at an annual rate = 4 × 0.31% = 1.23% ≈ 1.2% (percent per year) Using the logarithmic approximation to percent changes yields 4 × 100 × [log(16903) – log(16851)] = 1.232% 20 EXAMPLE: GDP AND ITS RATE OF CHANGE 21 AUTOCORRELATION (SERIAL CORRELATION) The correlation of a series with its own lagged values is called autocorrelation or serial correlation. The first autocovariance of Yt is cov(Yt,Yt–1) The first autocorrelation of Yt is corr(Yt,Yt–1) Thus = corr(Yt , Yt −1 ) cov(Yt , Yt −1 ) = ρ1 var(Yt ) var(Yt −1 ) These are population correlations – they describe the 22 population joint distribution of (Yt, Yt–1) AUTOCORRELATION (SERIAL CORRELATION) AND AUTOCOVARIANCE The jth autocovariance of a series Yt is the covariance between Yt and its jth lag, Yt–j, and the jth autocorrelation coefficient is the correlation between Yt and Yt – j. That is, j th autocovariance = cov(Yt , Yt − j ) j autocorrelation = ρ= corr(Yt , Yt − = j j) th cov(Yt , Yt − j ) var(Yt ) var(Yt − j ) (14.3) . (14.4) The jth autocorrelation coefficient is sometimes called the jth serial correlation coefficient. 23 SAMPLE AUTOCORRELATIONS The jth sample autocorrelation is an estimate of the jth population autocorrelation: where cov(� 𝑌𝑌𝑡𝑡 , 𝑌𝑌𝑡𝑡−𝑗𝑗 ) 𝜌𝜌�𝑗𝑗 = � var( 𝑌𝑌𝑡𝑡 ) 𝑇𝑇 1 � cov( 𝑌𝑌𝑡𝑡 , 𝑌𝑌𝑡𝑡−𝑗𝑗 ) = � (𝑌𝑌𝑡𝑡 − 𝑌𝑌̄𝑗𝑗+1,𝑇𝑇 ) (𝑌𝑌𝑡𝑡−𝑗𝑗 − 𝑌𝑌̄1,𝑇𝑇−𝑗𝑗 ) 𝑇𝑇 𝑡𝑡=𝑗𝑗+1 where Y j +1,T is the sample average of Yt computed over observations t= j + 1, , T . NOTE : the summation is over t=j+1 to T The divisor is T, not T – j (this is the conventional definition used for time series data) 24 EXAMPLE Chinese real GDP, yearly, 1978-2013 Stata commands use gdp_china1.dta,clear tsset year *declare data to be time series tsline y,xlabel(1980(5)2010) tsline lny,xlabel(1980(5)2010) tsline dlny,xlabel(1980(5)2010) *tsline draws line plots for time-series data. gen grow=(y-l.y)/l.y tsline dlny grow,xlabel(1980(5)2010) lpattern("." "--") 25 0 20000 40000 gdp 60000 80000 100000 TIME SERIES PLOT OF GDP 1980 1985 1990 1995 Year 2000 2005 2010 26 8 9 lngdp 10 11 12 TIME SERIES PLOT OF LN(GDP) 1980 1985 1990 1995 Year 2000 2005 2010 27 .04 .06 dlngdp .08 .1 .12 .14 TIME SERIES PLOT OF DLN(GDP) 28 1980 1985 1990 1995 Year 2000 2005 2010 LOGARITHMIC APPROXIMATION TO .05 .1 .15 PERCENT CHANGES 1980 1985 1990 1995 Year dlngdp 2000 grow 2005 2010 29 AUTOCORRELATIONS A correlogram, also know n as Auto Correlation Function (ACF) plot, is a graphic w ay to demonstrate serial correlation in data 30 AUTOCORRELATIONS 31 AUTOCORRELATIONS 32 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Example: US inflation and unemployment rates 1948-2003 Time series analysis focuses on modeling the dependency of a variable on its own past, and on the present and past values of other variables. 33 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Examples of time series regression models Static models In static time series models, the current value of one variable is modeled as the result of the current values of explanatory variables Examples for static models There is a contemporaneous relationship between unemployment and inflation (= Phillips curve). The current murder rate is determined by the current conviction rate, unemployment rate, and the fraction of young males in the population. 34 DYNAMIC CAUSAL EFFECTS AND THE DISTRIBUTED LAG MODEL Dynamic effects necessarily occur over time. The econometric model used to estimate dynamic causal effects needs to incorporate lags. The distributed lag model is: yt =𝛼𝛼 0 +𝛿𝛿 0 zt +𝛿𝛿 1 zt-1 + … +𝛿𝛿 r zt–r + ut 𝛿𝛿 0 = impact effect of change in z = effect of change in zt on yt, holding past zt constant 𝛿𝛿 1 = 1-period dynamic multiplier = effect of change in zt–1 on yt, holding constant zt, zt–2, zt–3,… 𝛿𝛿 2 = 2-period dynamic multiplier (etc.) = effect of change in zt–2 on yt, holding constant zt, zt–1, zt–3,… 35 DISTRIBUTED LAG MODELS Cumulative dynamic multipliers The 2-period cumulative dynamic multiplier is 𝛿𝛿 0 +𝛿𝛿 1 +𝛿𝛿 2 = impact effect + 1-period effect + 2-period effect regress gfr l(0/2).pe, r *Stata command; l(0/2).pe: Example pet , pet-1 , pet-2 The fertility rate may depend on the tax value of a child, but for biological and behavioral reasons, the effect may have a lag Children born per 1,000 women in year t Tax exemption in year t Tax exemption in year t - 1 Tax exemption in year t - 2 36 Distributed Lag models yt =α 0 + δ 0 zt + δ1 zt −1 + δ 2 zt − 2 + ut How does one unit of a temporary change in z affect y? How does one unit of a permanent change in z affect y? 37 Distributed Lag models A temporary change: Impact propensity, dynamic multiplier 𝛼𝛼0 + 𝛿𝛿0 𝑐𝑐 + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 < 𝑡𝑡; 𝛼𝛼0 + 𝛿𝛿0 (𝑐𝑐 + 1) + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 = 𝑡𝑡; 𝑐𝑐, 𝑠𝑠 < 𝑡𝑡; 𝑧𝑧𝑠𝑠 = �𝑐𝑐 + 1, 𝑠𝑠 = 𝑡𝑡; ⇒ 𝑦𝑦𝑠𝑠 = 𝛼𝛼0 + 𝛿𝛿0 𝑐𝑐 + 𝛿𝛿1 (𝑐𝑐 + 1) + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 = 𝑡𝑡 + 1; ⇒ 𝑦𝑦𝑠𝑠 − 𝑦𝑦𝑡𝑡−1 = 𝑐𝑐, 𝑠𝑠 > 𝑡𝑡; 𝛼𝛼0 + 𝛿𝛿0 𝑐𝑐 + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 (𝑐𝑐 + 1), 𝑠𝑠 = 𝑡𝑡 + 2; 𝛼𝛼0 + 𝛿𝛿0 𝑐𝑐 + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 > 𝑡𝑡 + 2; ? 𝑠𝑠 = 𝑡𝑡; ? 𝑠𝑠 = 𝑡𝑡 + 1; ? 𝑠𝑠 = 𝑡𝑡 + 2; ? 𝑠𝑠 > 𝑡𝑡 + 2. A permanent change: cumulative dynamic multipliers and long-run propensity (LRP) or multiplier 𝛼𝛼0 + 𝛿𝛿0 𝑐𝑐 + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 < 𝑡𝑡; ? 𝑠𝑠 = 𝑡𝑡; 𝑠𝑠 = 𝑡𝑡; 𝛼𝛼0 + 𝛿𝛿0 (𝑐𝑐 + 1) + 𝛿𝛿1 𝑐𝑐 + 𝛿𝛿2 𝑐𝑐, 𝑐𝑐, 𝑠𝑠 < 𝑡𝑡; 𝑧𝑧𝑠𝑠 = � ⇒ 𝑦𝑦𝑠𝑠 = ⇒ 𝑦𝑦𝑠𝑠 − 𝑦𝑦𝑡𝑡−1 = �? 𝑠𝑠 = 𝑡𝑡 + 1; 𝑐𝑐 + 1, 𝑠𝑠 ≥ 𝑡𝑡; 𝛼𝛼0 + 𝛿𝛿0 (𝑐𝑐 + 1) + 𝛿𝛿1 (𝑐𝑐 + 1) + 𝛿𝛿2 𝑐𝑐, 𝑠𝑠 = 𝑡𝑡 + 1; ? 𝑠𝑠 ≥ 𝑡𝑡 + 2. 𝛼𝛼0 + 𝛿𝛿0 (𝑐𝑐 + 1) + 𝛿𝛿1 (𝑐𝑐 + 1) + 𝛿𝛿2 (𝑐𝑐 + 1), 𝑠𝑠 ≥ 𝑡𝑡 + 2. LRP: long run change in y given a permanent increase in z. 38 Distributed Lag models Suppose yt follows a second order DL model: yt =α 0 + δ 0 zt + δ1 zt −1 + δ 2 zt − 2 + ut Let z* denote the equilibrium value of zt and let y* be the equilibrium value of yt, such that y =α 0 + δ 0 z + δ1 z + δ 2 z * * * * The change in y*, due to a change in z*, equals the long-run propensity times the change in z* This gives an alternative way of interpreting the LRP 39 Distributed Lag Models yt =𝛼𝛼0 +𝛿𝛿 0 zt +𝛿𝛿 1 zt-1 + … +𝛿𝛿 r zt–r + ut In summary, for a temporary change in z, we call δ0 the impact propensity – it reflects the immediate change in y. For a permanent change in z, we can call δ0 + δ1 +…+ δr the long-run propensity (LRP) – it reflects the long-run change in y after a permanent change. Question: How to construct the 95% confidence interval for the LRP? (homework question) 40 DISTRIBUTED LAG MODELS Graphical illustration of lagged effects For example, the effect is biggest after a lag of one period. After that, the effect vanishes (if the initial shock was transitory). The long run effect of a permanent shock is the cumulated effect of all relevant lagged effects. It does not vanish (if the initial shock is a permanent one). 41 CLASSICAL ASSUMPTIONS Assumption TS.1 (Linear in parameters) The time series involved obey a linear relationship. The stochastic processes yt, xt1,…, xtk are observed, the error process ut is unobserved. The definition of the explanatory variables is general, e.g. they may be lags or functions of other explanatory variables. Assumption TS.2 (No perfect collinearity) In the sample (and therefore in the underlying time series process), no independent variable is constant nor a perfect linear combination of the others. 42 CLASSICAL ASSUMPTIONS Notation This matrix collects all the information on the complete time paths of all the explanatory variables The values of all the explanatory variables in period number t Assumption TS.3 (Zero conditional mean) The mean value of the unobserved factors is uncorrelated with the values of the explanatory variables in all periods 43 CLASSICAL ASSUMPTIONS Discussion of assumption TS.3 Exogeneity: Strict exogeneity: The mean of the error term is uncorrelated to the explanatory variables of the same period The mean of the error term is uncorrelated to the values of the explanatory variables of all periods Strict exogeneity is stronger than contemporaneous exogeneity TS.3 rules out feedback from the dep. variable on future values of the explanatory variables; this is often questionable esp. if explanatory variables “adjust” to past changes in the dependent variable If the error term is related to past values of the explanatory 44 variables, one should include these values as regressors CLASSICAL ASSUMPTIONS Unbiasedness of OLS Assumption TS.4 (Homoskedasticity) The volatility of the errors must not be related to the explanatory variables in any of the periods A sufficient condition is that the volatility of the error is independent of the explanatory variables and that it is constant over time In the time series context, homoskedasticity may also be easily violated, e.g. if the volatility of the dep. variable depends on regime changes 45 CLASSICAL ASSUMPTIONS Assumption TS.5 (No serial correlation) Conditional on the explanatory variables, the unobserved factors must not be correlated over time Discussion of assumption TS.5 Why was such an assumption not made in the crosssectional case? The assumption may easily be violated if, conditional on knowing the values of the indep. variables, omitted factors are correlated over time The assumption may also serve as substitute for the random sampling assumption if sampling a crosssection is not done completely randomly In this case, given the values of the explanatory variables, errors have to be uncorrelated across crosssectional units (e.g. states) 46 CLASSICAL ASSUMPTIONS OLS sampling variances Under assumptions TS.1 – TS.5: The same formula as in the cross-sectional case Unbiased estimation of the error variance 47 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Gauss-Markov Theorem Under assumptions TS.1 – TS.5, the OLS estimators have the minimal variance of all linear unbiased estimators of the regression coefficients This holds conditional as well as unconditional on the regressors Assumption TS.6 (Normality) This assumption implies TS.3 – TS.5 independently of Normal sampling distributions Under assumptions TS.1 – TS.6, the OLS estimators have the usual normal distribution (conditional on ). The usual F- and t-tests are valid. 48 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Example: Static Phillips curve Discussion of CLM assumptions TS.1: TS.2: Contrary to theory, the estimated Phillips Curve does not suggest a tradeoff between inflation and unemployment The error term contains factors such as monetary shocks, income/demand shocks, oil price shocks, supply shocks, or exchange rate shocks A linear relationship might be restrictive, but it should be a good approximation. Perfect collinearity is not a problem as long as unemployment varies over time. 49 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Discussion of CLM assumptions Easily violated TS.3: e.g., past unemployment shocks may lead to future demand shocks which may dampen inflation; an oil price shock means more inflation and may lead to future change in unemployment Assumption is violated if monetary policy is more “nervous” in times of high unemployment TS.4: TS.5: TS.6: Questionable Assumption is violated if exchange rate influences persist over time (they cannot be explained by unemployment) 50 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Example: Effects of inflation and deficits on interest rates Interest rate on 3-months T-bill Government deficit as percentage of GDP Discussion of CLM assumptions The error term represents other factors that determine interest rates in general, e.g. business cycle effects TS.1: A linear relationship might be restrictive, but it should be a good approximation. Perfect collinearity will seldomly be a TS.2: problem in practice. 51 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Discussion of CLM assumptions (cont.) TS.3: Easily violated e.g., past deficit spending may boost economic activity, which in turn may lead to general interest rate rises; unobserved demand shocks may increase interest rates and lead to a change in inflation in future periods Assumption is violated if higher deficits lead to more uncertainty about state finances and possibly more abrupt rate changes TS.4: TS.5: TS.6: Questionable Assumption is violated if business cylce effects persist across years (and they cannot be completely accounted for by inflation and the evolution of deficits) 52 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Using dummy explanatory variables in time series Children born per 1,000 women in year t Tax exemption in year t Dummy for World War II years (1941-45) Dummy for availabity of contraceptive pill (1963-present) Interpretation During World War II, the fertility rate was temporarily lower It has been permanently lower since the introduction of the pill in 1963 53 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Time series with trends Example for a time series with a linear upward trend 54 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Modelling a linear time trend Abstracting from random deviations, the dependent variable increases by a constant amount per time unit Alternatively, the expected value of the dependent variable is a linear function of time Modelling an exponential time trend Abstracting from random deviations, the dependent 55 vari-able increases by a constant percentage per time unit BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Example for a time series with an exponential trend Abstracting from random deviations, the time series has a constant growth rate 56 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Using trending variables in regression analysis If trending variables are regressed on each other, a spurious relationship may arise. Often both will be trending because of other unobserved factors. In this case, it is important to include a trend in the regression Example: Housing investment and prices Per capita housing investment Housing price index It looks as if investment and prices are positively related 57 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Example: Housing investment and prices (cont.) There is no significant relationship between price and investment anymore 58 DETRENDED SERIES Basically, the trend has been partialled out (Recall the partitioned regression) 59 Detrending An advantage to actually detrending the data (vs. adding a trend) involves the calculation of goodness of fit. Time-series regressions tend to have very high R2 𝑆𝑆𝑆𝑆𝑆𝑆/(𝑛𝑛 − 1) an unbiased estimator of Var(𝑦𝑦𝑡𝑡 )? The R2 from a regression on detrended data better reflects how well the xt’s explain yt. 60 Seasonality and Deseasonalizing the Data Often time-series data exhibits some periodicity, referred to seasonality. Example: Quarterly data on retail sales will tend to jump up in the 4th quarter. Seasonality can be dealt with by adding a set of seasonal dummies. As with trends, the series can be seasonally adjusted before running the regression. Deseasonalizing the variable can be obtained from the residuals from the regression of the variable on the seasonal dummies. 61 BASIC REGRESSION ANALYSIS WITH TIME SERIES DATA Modelling seasonality in time series A simple method is to include a set of seasonal dummies: = 1 if obs. from december = 0 otherwise The regression coefficients on the explanatory variables can be seen as the result of first deseasonalizing the dep. and the explanat. variables R2 based on first deseasonalizing the dep. var. may better reflect the explanatory power of the explanatory variables 62