Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: aic and adftest -- error


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: aic and adftest -- error
Date   Thu, 31 Aug 2006 21:34:21 +0100

If you 

. set trace on

you can see where the problem occurs. 

In this posting, the line 

local list storage[`i'] 

should occur as a separate line. It 
is puzzling because the result is never used
and in at least one other way. 

The line 

qui estimates stats `storage(`i')'

looks buggy in about five separate ways. 

1. `i' is referred to, but outside the loop in which
it was defined. 

2, 3, 4. `storage(`i')' should perhaps be `=storage[`i']'

5. The presumption is that the user has a variable 
called -storage-. If you don't have such a variable,
you have a problem. 

As a matter of style alone, the programmer sets 
up a loop to cycle over ... a single variable name. 
That's legal, but it's puzzling. Similarly the 
application of -tokenize- to ... a single variable 
name. 

The default of -lags()- is -1. If you don't specify
lags, what do you expect the program to do for you? 

All in all, this looks like untested code written 
at speed and offered in the sprit of a zeroth draft 
that might be helpful. But I would be surprised if it 
ever worked. 

Caveat utor! (or as the economists insist, caveat emptor!) 

A good rule of thumb, paraphrasing a line in Harry Potter, 
is never to trust a program until you can see its help 
file. 

The reason is that a programmer only writes a help file
when they are confident that they have a program that 
is rather stable and consistently producing useful 
results. That means that they have actually used it 
several times and removed most of the bugs. Writing help 
files is tedious and not nearly so much fun as writing 
programs, so the programmer tends to procrastinate like 
billy-oh on that job. 

Nick 
[email protected] 

Olga Gorbachev Melloni
 
> I liked very much the -adftest- routine that Rodrigo Martell  
> posted a few 
> weeksa ago. So i copied it hoping ot use it. But for whatever 
> reason I get 
> an error messge that the "varlist is not allowed" and of 
> course if I don't 
> give any varlist, the error message says "requires varlist"
> 
> does that make any sense?
> 
> adftest dfood, lag(5)
> 
> *****************
> Here is the repreduction of the code I used:
> *********************
> 
> program define adftest, rclass
> >version 9.2
> >syntax varlist(max=1) [if] [in] [, Lags(int-1) bic ]
> >estimates clear
> >tokenize `varlist'
> >foreach var of local varlist{
> >	forvalues i=1/`lags'{
> >		//display "ADF(`i') of `var'"
> >		qui dfuller `var', constant lags(`i') 		
> local list storage(`i')
> >		estimates store adf_`i'_`var'
> >	}
> >	qui estimates stats `storage(`i')'
> >	matrix s=r(S)
> >	matrix criteria=J(`lags',2,.)
> >	forvalues i=1/`lags' {
> >		matrix criteria[`i',1]=s[`i',5]
> >		matrix criteria[`i',2]=s[`i',6]
> >	}
> >if "`bic'" != "" {
> >	matrix criteria = criteria[1...,2]
> >	local crit  "BIC"
> >	}
> >else {
> >	matrix criteria = criteria[1...,1]
> >	local crit  "AIC"
> >	}
> >}
> >
> >mata: min_row(st_matrix("criteria"))
> >local min = min[1,1]
> >display " "
> >display in gr "Optimal lag by `crit' criteria = " `min'
> >dfuller `varlist', lag(`min') constant
> >
> >end
> >
> >mata:
> >	matrix function min_row(matrix A)
> >	{
> >	B = colmin(A)
> >  	C = B:==A
> >  	A2 = (0, 0)
> >  	maxindex(C, 1, C, A2)
> >  	st_matrix("min",C)
> >
> >  	}
> >end
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index