This is a question about Mathematica's behavior. I give some background -- but you can skip to the code block below, which illustrates the behavior.
I am using Mathematica ("WL") to work through the time series examples in Stock and Watson's "Introductory Econometrics" and also to replicate the solutions for those examples in Hanck et al "Using R for 'Introductory Econometrics'". It's fun and I'm learning my way around the WL time series modules.
But a puzzle. I import a spreadsheet via SemanticImport[]
into a DataSet
and then extract the quarterly dates and GDP levels (via Normal[]
) into a TimeSeries
object.
I transform this TS object into a "GDP Percentage Growth" object by applying 400 Differences[Log[gdplogts]]
to the GDP level series.
After imposing a 1962-2012 window on the percentage growth series, I estimate Stock and Watson's AR(1) model (their results: GDPGGsubT = 1.991 + 0.344 GDPGRsubT-1
) two different ways:
1: gdpgr6212AR1 = TimeSeriesModelFit[gdpgrpctts6212, {"AR", {1}}]
. The intercept, coefficient, and error variance returned are ARProcess[2.023891, {0.3371512}, 9.924687]
, which are close to the Stock and Watson values, but quite distinguishable from them.
2: I extracted the GDP Growth for 1962:2012 into a list, create level and lag versions of the lists, combine them into a coordinate array with MapThread[]
, and then submit this array to LinearModelFit[]
. Here the Normal[]
reduction of the FittedModel
returns 1.990784 + 0.3436466 x
, which rounds exactly to the Stock and Watson textbook result.
My question is, why do these methods produce different results? There are analogous approaches in R to what I did above (none of which match the Stock & Watson result as well as WL LinearModelFit[]
), but all of them ultimately seem to be wrappers for the core R lm()
("linear model") estimator and they all return the same results.
In WL, I can't tell whether I am inadvertently introducing the variability, or whether different estimators are used by LinearModelFit[]
and EstimateProcess[]
(which seems to be what TimeSeriesModelFit[]
is pointing to, so I go right to it in the code snippet below).
The code below replicates my actions with a small snippet of the GDP Percentage Growth value list.
Code
(* 10 obs of base series*)
basetestdata = {2845.453, 2873.169, 2843.718, 2770., 2788.278,
2852.741, 2919.47, 2973.782, 3046.096, 3040.235};
(* 10 obs at Lag 1*)
lagtestdata = {2851.778, 2845.453, 2873.169, 2843.718, 2770.,
2788.278, 2852.741, 2919.47, 2973.782, 3046.096} ;
(* Calculate percentage growth*)
tdgrowthpct = 400 Log[basetestdata/lagtestdata] (* 10 obs*)
(* Method 1: Submit to Estimateprocess[] *)
tdgrowthpctEProc =
EstimatedProcess[tdgrowthpct,
ARProcess[1]] (* Lag will reduce to 9 obs *)
(* Output is : ARProcess[1.537332, {0.3994062}, 33.70502] *)
(* Method 2: form pairs and submit to LinearModelFit[] R *)
basetdgrowthpct = Take[tdgrowthpct, {2, 10}] (* Get down to 9 obs *)
lagtdgrowthpct = Take[tdgrowthpct, {1, 9}] (* Get down to 9 obs *)
data2 = MapThread[
List, {lagtdgrowthpct, basetdgrowthpct}] (* Create nine pairs *)
tdgrowthpctLM1 =
LinearModelFit[data2, x, x] // Normal (* Submit nine pairs *)
(* Output is 1.745164 + 0.408785 x *)
```