Dangers of Time Series Analysis

Time series statistical analysis is a very useful way of examining data over time to explain past events as well as forecast the future. For example, looking at airline ticket costs, past demand for air travel, economic growth and other factors, an airline may hope to forecast future demand. This ability to estimate the future would aid tremendously in projecting revenue and budgeting for staff, airplanes, and other investments. While this ability is clearly very useful, there are many peculiarities of time series analysis that must be considered before acting on the results of the analysis.

Below, I will walk through a recent time series analysis that I attempted, whose outcome seemed very promising at first but later proved to be unreliable. As always, the python script underlying this analysis can be found on my Github.


E-Commerce and Internet Penetration

I recently stumbled upon historical data for e-commerce sales. Inspired by my recent move to the tech-heavy Seattle, I was interested in seeing whether there was any relationship between the growth in e-commerce and the growth in broadband internet access in the United States. I included some macroeconomic data in order to paint a more complete picture. The econometric equation that I was hoping to arrive at was:  

E-Commerce Sales = Some constant + Broadband Internet Rates + GDP Growth + Inflation + some error term

The first problem I ran into was that I could only find data on internet usage dating back to 2002 on a semiannual basis (so n≅30). I would prefer a n>50, but roughly 30 is probably enough for this exercise. The small n would make it difficult to split the data into a training and testing blocks for the purpose of forecasting, but may be enough for simply explaining the past.

As always, my first step was to visualize the raw data. (Note: the raw data had already been seasonally adjusted).

Figure 1

Figure 2

Figure 3

It is pretty clear from the graphs that my dependent variable (e-commerce sales, blue) is strongly correlated with each of my explanatory variables (red). This is further confirmed through a series of scatter plots

Figure 4

An initial regression on the raw data produces an R-squared of 0.97, which further proves the strength of the trend.

Table 1

Dep. Variable: Sales R-squared: 0.970
Model: OLS Adj. R-squared: 0.967
Method: Least Squares F-statistic: 272.2
Date: Wed, 26 Jul 2017 Prob (F-statistic): 3.30e-19
Time: 12:01:18 Log-Likelihood: -304.70
No. Observations: 29 AIC: 617.4
Df Residuals: 25 BIC: 622.9
Df Model: 3
Covariance Type: nonrobust
coef std err t P>|t| [95.0% Conf. Int.]
Intercept -9.4e+05 7.35e+04 -12.793 0.000 -1.09e+06 -7.89e+05
Internet -5.235e+05 1.13e+05 -4.632 0.000 -7.56e+05 -2.91e+05
CPI 3118.9581 604.414 5.160 0.000 1874.145 4363.771
GDP 0.0163 0.003 5.903 0.000 0.011 0.022


I didn’t bother checking the suitability of the variables in this initial regression because it was clear to me that they would not meet the statistical requirements of OLS regression (namely normal distribution, stationarity, etc.). Furthermore, I was interested in growth of these variables over time, rather than the raw values. Examining the growth of these variables tells a more interesting story, but may also address the non-stationarity that is likely present in the raw data.

I next took the percent change of each variable from one period to the next and ran an OLS regression on that. I used ‘delta’ to represent the percent change in the data over time.

Table 2

Dep. Variable: deltaSales R-squared: 0.806
Model: OLS Adj. R-squared: 0.782
Method: Least Squares F-statistic: 33.28
Date: Thu, 27 Jul 2017 Prob (F-statistic): 1.02e-08
Time: 10:09:55 Log-Likelihood: 72.092
No. Observations: 28 AIC: -136.2
Df Residuals: 24 BIC: -130.9
Df Model: 3
Covariance Type: nonrobust
coef std err t P>|t| [95.0% Conf. Int.]
Intercept 0.0435 0.007 6.177 0.000 0.029 0.058
deltaInternet 0.2426 0.066 3.699 0.001 0.107 0.378
deltaCPI -0.9479 0.502 -1.889 0.071 -1.984 0.088
deltaGDP 3.2412 0.405 8.004 0.000 2.405 4.077

Table 3

Interestingly, all of my variables were significant, with the exception of the change in inflation (deltaCPI). I ran a third regression, dropping deltaCPI.

Dep. Variable: deltaSales R-squared: 0.777
Model: OLS Adj. R-squared: 0.760
Method: Least Squares F-statistic: 43.66
Date: Thu, 27 Jul 2017 Prob (F-statistic): 6.98e-09
Time: 10:10:18 Log-Likelihood: 70.152
No. Observations: 28 AIC: -134.3
Df Residuals: 25 BIC: -130.3
Df Model: 2
Covariance Type: nonrobust
coef std err t P>|t| [95.0% Conf. Int.]
Intercept 0.0362 0.006 5.856 0.000 0.023 0.049
deltaInternet 0.2140 0.067 3.192 0.004 0.076 0.352
deltaGDP 3.1549 0.423 7.467 0.000 2.285 4.025

Examining this third regression, both explanatory variables — internet growth (deltaInternet) and GDP growth (deltaGDP) — were statistically significant. Also, the direction of coefficients made practical sense, i.e. both GDP growth and greater broadband penetration had a positive effect on the growth of e-commerce sales. My resulting equation turned out to be:

ΔSales = 0.04 + 0.21ΔInternet + 3.15ΔGDP

Very promising, but the R-squared of 0.78 still seems pretty high to me, so I need to look a little more closely at whether my variables satisfy all of the necessary assumptions of OLS.

First, let’s take a look at whether they are stationary, that is whether the mean and variance are constant over time. For this, I employed an Augmented Dickey Fuller test, which has a null hypothesis of non-stationarity.

Table 4

Table 5

Table 6


All three transformed variables proved to be stationary at the 5% confidence level (i.e. rejected the null hypothesis)

Another primary assumption of OLS regressions is that the variables are normally distributed.

Figure 5

Figure 6

Figure 7

Here is my first sign of trouble. When compared to the raw values, the three transformed variables were closer to normal distribution, but still not quite there. The histogram plotted for each variable do not look particularly normal, but I decided to run a test just to make sure.

Table 7

Variable Test Statistic p-value
deltaSales 21.6775 0.00001962
deltaInternet 4.9528 0.08404574
deltaGDP 32.8555 0.00000007

The above 2-tailed test has a null hypothesis of a normal distribution. The resulting p-values reject the null hypothesis for both the ΔSales and ΔGDP variables. The ΔInternet variable, however, failed to do so, suggesting that ΔInternet is in fact normally distributed. It is possible that because my n is so small (n<50) that this test for normality isn’t fully reliable. I therefore decided to continue with other tests to see how my variables fared on other metrics.

I next tested for Granger Causality, which checks whether the past of one variable has the ability to predict the other variable.

Table 8

Table 9

In this instance, I only used 2 lags, but I ran the test with various lag times and the results were all the same. Interestingly, the only pairing that exhibited Granger Causality was deltaSales on deltaInternet (the low p-value led to a rejection of the null hypothesis), but there was no Granger causality in the reverse. I suppose that it’s possible that as there are more e-Commerce options, more people decide to invest in broadband internet, but that seems unlikely to me. 

Moving on from causality, I went onto testing for cointegration, which occurs when x and y have the same stochastic trend. In other words, while each of two variables may be randomly distributed on their own, there is some linear relationship that can be found between the two. In statistical terms, the residuals of the regression of one variable on the other are stationary.  Given the high correlation among the raw data points and the high R-squared for the growth regression, I suspected that there may be some cointegration. I ran an Engle-Granger Two-Step approach for cointegration, which has as its null hypothesis that the residuals are non-stationary, i.e. no cointegration exists.

Table 10

Table 11

As suspected, both ΔGDP and ΔInternet rejected the null hypothesis of no cointegration.

Given the presence of cointegration, the next step would be to develop an error correction model that takes lagged data into consideration to correct for the presence of cointegration. But in this instance, the consideration of other factors led me to believe that this analysis has come to its natural end. First, the low number of observations (n30) gave me pause from the very beginning. Secondly, the non-normal distribution of two of my three variables (ΔSales and ΔGDP), called into question the accuracy of an OLS regression. Thirdly, the direction of theGranger Causality between ΔSales and ΔInternet doesn’t make logical sense. And lastly, the presence of cointegration was the nail in the coffin.



Although, I’m calling it quits on this dataset, there are a few things that could possibly save it, if I really wanted to:

First, I could increase the number of observations: while increasing n doesn’t necessarily bring a variable closer to normal distribution, it can help in many ways. Ideally, a data set contains at least 50 observations. This data set only had roughly 30. Some tests or normal distribution and other aspects don’t work very well with small data sets. So increasing the number of observations could potentially increase the accuracy of the tests and the model that they are based on. In this case, however, I was not able to locate additional data on internet penetration. So although there is plenty of available data on the other variables, I was limited by that one variable.

A second option would be further variable transformations. I took the percent change from one period to the next for each variable. While this moved the distribution closer to normal, it didn’t fully get there. I also tried transformations, such as taking the difference from one period to the next or the log of each variable, but they alone also didn’t exactly do the trick. (Also none of the growth in the variables was exponential, so taking the log may not have been appropriate.) Had I had access to more data (a higher n), perhaps there were other variable transformations that I could have considered

In closing, the statistical requirements of time series analysis can make make it difficult to arrive at strong conclusions in the real world. Even in the instance of data that produces a result that seems logical (such as my original regression  equation above), the statistical rigor that is required can call even seemingly obvious results into question.



Trade has been on the forefront of the economic conversation in the US since the 2016 presidential election. Having already scrapped the TPP during its first days in power, the Trump Administration has set its sights on NAFTA calling it a “catastrophe” and “unfair for the American worker.”

Entering into force in 1994, the North American Free Trade Agreement facilitated the increased movement of goods across the Mexico-US and US-Canada borders. In light of manufacturing jobs moving to Mexico and persistent US trade deficits with both Canada and Mexico, the question remains whether it has actually been a net positive for the US economy and labor force. A dive into the data sheds some light on the issue, but is far from offering a definitive answer.

Long story short, the following charts and analysis argue that although the US has imported more than it has exported under NAFTA, the US economy nevertheless may have been the ultimate winner in this arrangement. And as it relates to our southern neighbors, it is hard to argue that Mexico has won out at the expense of the US.

The Data

The US Census Bureau, oddly enough, tracks trading activity specifically tied to NAFTA. It publishes monthly data of the value of goods imported into the US from Canada and Mexico and the value of goods the US exports to the two countries. This was the data that I was primarily interested in. To add a bit more color to the picture, I grabbed information on Total Factor Productivity in all three countries from the Federal Reserve and unemployment and GDP figures from the World Bank.

The Results

Economic theory maintains that trade is a positive sum game, in that free trade increases the size of the economic pie for everyone. When Country A and Country B liberalize trade, there will necessarily be winners and losers in each country, but the gains to the winners will be more than enough to offset the losses suffered by the losers. This seems to hold true in the NAFTA context.

Figure 1

Looking at trade from the perspective of the US, trade with both countries has flourished under NAFTA. Interestingly, while Mexico bears the brunt of the criticism in today’s political climate, as the above graph demonstrates, total trade with Canada has consistently dwarfed that of Mexico.

Breaking trade into its constituent parts, both exports from the US and imports into the US have risen fairly steadily. And while imports have consistently outpaced exports, the rate of change (the slope of each line) has been roughly equal.

Figure 2

Looking specifically at the difference between imports and exports, however, draws a more negative picture.

Figure 3

The above certainly lends credence to the argument that NAFTA has been bad for the US. Trade was roughly in balance prior to NAFTA, but it began to steadily decline once NAFTA was enacted (red line in figure above marks the first year of NAFTA). Interestingly, the 2008 financial crisis has been good for this balance. While both imports and exports declined during this period, the comparably fast rebound in the US led to a sharp strengthening of the trade balance, which still holds to this day.

However, when looking beyond just the trade figures, a more positive picture for the US begins to emerge. First, looking at US unemployment relative to its neighbors, the US has not fared too poorly.

Figure 4

The years following the institution of NAFTA saw falling unemployment in all three countries, with the most dramatic drop in Mexico. Unemployment then began to rise following the bursting of the dot com bubble and during the runup to the 2001 recession, illustrated by the first vertical red line. In subsequent years, unemployment resumed its decline in all three economies until the subprime mortgage crisis, which ushered in the the deeper, longer lasting recession of 2007, as marked by the second vertical red line. Prior to the Great Recession of 2007-2009, unemployment in the three nations rose and fell roughly in concert, with US unemployment lower than in Canada but higher than in Mexico. The aftermath of the Great Recession appears to have upended that pattern, with the US unemployment rising and then declining more sharply than that of Canada and Mexican unemployment somewhat plateauing at or near its height. While Mexican unemployment still stands below that of the US, the gap appears to the shrinking as the US enjoys a more robust recovery.

The next two graphs show an even starker contrast between the economic fates of US and Mexico following the adoption of NAFTA.

Figure 5

GDP per capita in the US greatly outpaces GDP per capita in Mexico, which is not surprising given the leading position of the US in the global economy. Nevertheless, the rate of growth of GDP per capita is strong across the region, with Canada leading the pack. The compound annual growth rate of GDP per capita in Canada starting from the adoption of NAFTA in 1994 clocked in at 4.7%, compared to 3.4% in the US and 3.0% in Mexico. While growth rates in GDP per capita were obviously affected by more than just NAFTA, it is interesting to note that during the NAFTA period, US and Canada both saw greater economic growth per inhabitant than in Mexico.

Similarly, Total Factor Productivity (TFP), which is an indirect measure of economic gains derived from efficiency and technological improvement, suggests that the Mexican economy may have gained the least through the NAFTA partnership.

Figure 6

Relative to the US, TFP in both Canada and Mexico have declined during the NAFTA period, with Mexico, which was already on the decline prior to NAFTA, declining from 0.78 in the pre-Nafta period to 0.60 in 2014, the latest period for which data is available. This represents a decline of 23.0% in Mexico, compared with just a 8.3% decline in Canada. It is important to note here that this measurement of TFP is relative to the US. It is completely possible that the efficiency of the Mexican economy has remained steady, or even grown, over the period, but has been consistently outpaced by efficiency growth in the US and thus this measure of TFP has declined. Nevertheless, the argument that the Mexican economy has grown at the expense of the US economy is not borne out by the data presented here.


The above data suggests that in the case of NAFTA, economic trade theory holds in that the size of the pie has increased for all three countries. One of the glaring problems in trade theory, however, is that while there are enough trade-derived resources to compensate the losers, in reality channeling those resources has proven difficult. A US corporation may benefit from moving manufacturing to Mexico, but transferring the correct portion of those gains to the factory labor who have lost their jobs as a result does not work out as cleanly as economists would have you believe. This disconnect between the winners and losers is sowing discord throughout the economy and the trade deal itself, rather than the lack of mechanism for wealth transfer, is named the primary culprit. As with everything else, it becomes more of a political question than an economic one.

The current political rhetoric of the benefits of NAFTA flowing first and foremost to Mexico do not seem to be supported by the economic data over the two decades of NAFTA’s existence.The ill effects of free trade are concentrated in the few while the benefits are diffused among the many. Those who have lost car manufacturing jobs to Mexico, for example, speak more loudly than those of us that enjoy a modest savings in the purchase of a new car as a result.  

Subsidies and Growth

Federal subsidies have long been a part of the US political and budgetary system, and they undoubtedly have a cumulative effect on US fiscal policy. Based on data from the US Bureau of Economic Analysis (BEA), federal subsidies have grown right alongside GDP.

Figure 1


As expected, the bulk of subsidy payments have been allocated to agriculture and housing, but other sectors of the economy have also benefited.

Figure 2

While many of these subsidies may be well-intentioned, I have been skeptical of the efficacy of subsidies ever since my Econ 101 class in college almost 2 decades ago. The notion of the deadweight loss to the economy that is necessarily the outcome of a subsidy has always stuck with me. In an overly simplified nutshell, the cost of the subsidy to the government is x; the recipient of the subsidy is paid y; and the difference between the two (x-y) is simply lost. Despite this loss, subsidies continue to flourish, partly because the benefit is concentrated while the cost is spread out among all taxpayers. In other words, an particular interest group has a clear incentive to push for a subsidy, while the cost to the individual taxpayer is so small that it’s not worth the fight.

But if we stand back and look at the effect on the economy as a whole, do subsidies in the aggregate help or hurt the economy? While each individual subsidies carries with it a deadweight loss, do the potential positive knock-on effects of the subsidy (increased employment, higher consumption, perhaps) eventually offset this loss? Those are the questions that I sought to answer by sifting through the data.

SPOILER ALERT: My overall conclusion is that by examining the period from 1960-2015, the rise of subsidies has had a negative effect on US economic growth. While subsidies buttressed economic growth in the early years of the period under review, the effect turned negative in the 1980s following an expansion of subsidies during that time. My complete analysis is detailed below and my data and calculations can be found here.

The Data

My primary areas of interests for this analysis were subsidies and economic growth. The BEA provided data on the level of subsidies each year since 1960. The dataset included data on subsidies overall and also provided data on the constituent parts of the overall subsidy level: agricultural, housing, maritime, aircraft carriers, and other.  

To represent economic growth, I obtained BEA data on nominal GDP, nominal GDP growth, real GDP, and real GDP growth over the same period.

As I built out my analysis, I realized that in order to more accurately explain the relationship between subsidies and growth, I also needed a few additional macroeconomic indicators. I therefore added unemployment, labor productivity and inflation data to the mix. Unemployment and labor productivity data were obtained from the US Bureau of Labor Statistics (BLS), and I sourced inflation data from the World Bank.


My original hypothesis was that while subsidies were great for the individual recipients, they represented a raw deal for the US taxpayer overall. To test this theory, I started very simply by considering the direct relationship between growth (nominal and real GDP and nominal and real GDP growth) and subsidies. I first began with the broad measure of subsidies, and then looked into its constituent parts

Figure 2

Given that housing and agricultural subsidies provided the bulk of subsidy outlays for much of the period since 1960, when analyzing the individual types of subsidies, I focused on those two forms and disregarded maritime, aircraft, and others. Just by glancing at the correlation (or rather lack thereof) among just these factors alone shows that there is more to the story than just GDP and subsidies.

Figure 3

Looking at the interplay of Real/Nominal GDP Growth and the various subsidies metrics, the scatter plots are all over the place. There is no obvious correlation. This is also reflected in an OLS regression of the same inputs. Both of the following regressions use subsidies as the independent variables, but the first sets nominal GDP growth as the dependent variable while the second employs real GDP growth. In the case of nominal GDP growth, none of the independent variables are statistically significant (as noted by a P<0.05). For real GDP growth, on the other hand, agricultural subsidies alone met the threshold of statistical significance, with a positive sign. However, that regression had an R-squared value of just 0.20, leaving four-fifths of the change in real GDP growth unexplained.

Table 1

Table 2

I next added unemployment data to the mix. I wanted to test whether there was a relationship between unemployment (as the dependent variable) and subsidies (as the independent variables). Again agricultural subsidies was the only variable to show any significance, but this time the effect was negative. (This was true when I included nominal GDP growth, but not with real GDP growth.) The R-squared in this case was just 0.18, so I clearly had much more work to do.

Table 3

With such low measurements of R-squared, I searched for additional variables that could help better explain the relationship between growth and subsidies. Looking again at the graph of Nominal GDP and subsidies over time, the two factors seem to rise in concert.

Figure 1

This relationship is even better illustrated by the following scattergram, which shows a near perfect correlation of 0.97.

Figure 4

I began to wonder how much of this relationship was just the effect of inflation. So I added inflation to my list of independent variables so that its effect could be explicitly considered. Likewise, I felt that it was likely that a sizeable portion of the real gains in GDP were due to increased labor productivity as businesses have invested in technology over the period under consideration. Similarly, I included population growth to account for simple demographic shifts, both in the labor force and in the number of consumers.


As you can see in the table below, when taking all of the abovementioned factors into consideration, subsidies has a negative coefficient that is statistically significant. This suggests that a rise in subsidies is associated with a decrease in economic growth.

Table 4

Labor Productivity, Unemployment and Inflation were also significant and all had the signs that one would expect: positive, negative, and positive, respectively. Population Growth, however, while significant, had the opposite sign from what I had expected. Not only was the coefficient negative, but at -4.15, it had a much greater effect on Nominal GDP Growth than the other independent variables combined.

Figure 5

The above graph of Nominal GDP and Population Growth over time, further illustrates the tendency of nominal GDP growth to weaken as the population grows at a faster rate. I expected that an expanding demography would have a positive effect on economic growth, but the data suggests otherwise.

Taking a closer look at subsidies over time, one sees that the level of subsidies in the US began to accelerate in the early 1980s.

Figure 6

I therefore segmented the data to examine the effect of subsidies prior to 1980 and from 1980 onward. First, prior to 1980, when subsidies were on a lower growth trajectory, Subsidies actually had a positive effect on Nominal GDP Growth, suggesting that higher subsidy levels was associated with higher levels of economic growth from the period of 1960 through 1979.

Table 5

In the years that followed, however, the subsidies reached a turning point and became a drag on economic growth, as evidenced by its negative coefficient during that period (see endnote).

Table 6

While the reason for the increase of subsidies is beyond the scope of this analysis, one possible narrative that could be worth exploring is the contrast from one period to the next. It is very possible that policy makers in the early 1980s began to more heavily rely on subsidies due to the economic accretive effect of subsidies in the 1960s and 1970s. Perhaps low-level subsidies are actually good for the economy, but at some point in the 1980s, the US reached a tipping point at which the economic gains from subsidies were replaced by economic headwinds.

In conclusion, a close examination of the data suggests that the US economy would be better off without subsidies, or at least with a much lower level of subsidies. The deadweight loss from subsidies that economic theorists claim appears to be supported by reality. While further study would be necessary to determine the optimal level of subsidies for the US economy, this analysis suggests that a lower subsidy levels would be expected to have a positive effect on economic growth. The question remains, however, how low can subsidies be cut before the pendulum begins to swing in the other direction?


In the segmented data, the Population Growth variable has been removed due to its statistical insignificance in the early years (P-value of 0.259) and it just barely reaching the level of significance in the latter year (P-value of 0.045). Additionally, the inclusion of Population Growth in the analysis of the segmented periods greatly reduced the significance of the other independent variables in the analysis during both periods.


Unemployment and Labor Productivity Data: US Bureau of Labor Statistics

GDP Data: Federal Reserve Economic Data (FRED)

Subsidy Data: US Bureau of Economic Analysis

Inflation and Population Data: World Bank World Development Indicators