Gretl Manual: Gnu Regression, Econometrics and Time-series Library | ||
---|---|---|
Prev | Chapter 5. Special functions in genr | Next |
The genr command provides a means of retrieving various values calculated by the program in the course of estimating models or testing hypotheses. The variables that can be retrieved in this way are listed in the genr reference; here we say a bit more about the special variables $test and $pvalue.
These variables hold, respectively, the value of the last test statistic calculated using an explicit testing command and the p-value for that test statistic. If no such test has been performed at the time when these variables are referenced, they will produce the missing value code. The "explicit testing commands" that work in this way are as follows: add (joint test for the significance of variables added to a model); adf (Augmented Dickey–Fuller test, see below); arch (test for ARCH); chow (Chow test for a structural break); coeffsum (test for the sum of specified coefficients); cusum (the Harvey–Collier t-statistic); kpss (KPSS stationarity test, no p-value available); lmtest (see below); meantest (test for difference of means); omit (joint test for the significance of variables omitted from a model); reset (Ramsey's RESET); restrict (general linear restriction); runs (runs test for randomness); testuhat (test for normality of residual); and vartest (test for difference of variances). In most cases both a $test and a $pvalue are stored; the exception is the KPSS test, for which a p-value is not currently available.
An important point to notice about this mechanism is that the internal variables $test and $pvalue are over-written each time one of the tests listed above is performed. If you want to reference these values, you must do so at the correct point in the sequence of gretl commands.
A related point is that some of the test commands generate, by default, more than one test statistic and p-value; in these cases only the last values are stored. To get proper control over the retrieval of values via $test and $pvalue you should formulate the test command in such a way that the result is unambiguous. This comment applies in particular to the adf and lmtest commands.
By default, the adf command generates three variants of the Dickey–Fuller test: one based on a regression including a constant, one using a constant and linear trend, and one using a constant and a quadratic trend. When you wish to reference $test or $pvalue in connection with this command, you can control the variant that is recorded by using one of the flags --nc, --c, --ct or --ctt with adf.
By default, the lmtest command (which must follow an OLS regression) performs several diagnostic tests on the regression in question. To control what is recorded in $test and $pvalue you should limit the test using one of the flags --logs, --autocorr, --squares or --white.
As an aid in working with values retrieved using $test and $pvalue, the nature of the test to which these values relate is written into the descriptive label for the generated variable. You can read the label for the variable using the label command (with just one argument, the name of the variable), to check that you have retrieved the right value. The following interactive session illustrates this point.
? adf 4 x1 --c Augmented Dickey-Fuller tests, order 4, for x1 sample size 59 unit-root null hypothesis: a = 1 test with constant model: (1 - L)y = b0 + (a-1)*y(-1) + ... + e estimated value of (a - 1): -0.216889 test statistic: t = -1.83491 asymptotic p-value 0.3638 P-values based on MacKinnon (JAE, 1996) ? genr pv = $pvalue Generated scalar pv (ID 13) = 0.363844 ? label pv pv=Dickey-Fuller pvalue (scalar)