Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: looping with augmented dickey fuller test


From   "Dev Vencappa" <[email protected]>
To   <[email protected]>
Subject   Re: st: looping with augmented dickey fuller test
Date   Wed, 15 Oct 2003 14:23:14 +0100

Ernest, Nick
 many thanks to you both for your solutions which work finely. I have rewritten the command to accomodate my dataset based on what one of you suggested as follows:

local z "netprem disclm elr solv"
foreach k of local z{
forvalues x=1/19{
preserve
keep if comcode==`x'
tsset year
postfile myhandledf  comcode dfstat`k' using "c:\unitroot\dfunitrootlag`k'comp`x'", replace
summ AICoptlag`k' if comcode==`x', mean
dfuller `k', lags(`r(mean)') reg
scalar DFSTAT`k'=r(Zt)
post myhandledf (`x') (DFSTAT`k') 
postclose myhandledf
restore
}
postutil clear
}


 Above seems to be doing exactly what I wanted it to do. 

Many thanks

Dev



Dev Vencappa
School of Economics
University of Nottingham
University Park
Nottingham
NG7 2RD
U.K.
Tel : +44 (0)115 951 5608
Fax: +44 (0) 115 951 4159
>>> [email protected] 10/15/03 12:59 PM >>>
At 13:19 15-10-2003, Dev Vencappa wrote:
>I have a data set that looks like the following
>
>company  year      var1 var2 var3 var4 optlagvar1 optlagvar2 optlagvar3 
>optlagvar4
>1             1980                                        1
>1             1981                                        1
>1             1982                                        1
>..            ..
>1             2002                                        1
>2             1980                                        3
>2             1981                                        3
>2             1982                                        3
>..            ..
>2             2002
>...           ...
>...           ...
>20           1980                                        6
>20           1981                                        6
>20           1982                                        6
>..            ..
>20           2002
>
>
>The variable optlagvar1 for instance is the optimal lag value from an 
>Akaike Information criteriaon exercise for each company. My problem is I 
>now want to implement the DF test for each company and each variable, 
>writing something like:
>
>local z "var1 var2 var3 var4"
>foreach k of local z{
>forvalues x=1/20{
>dfuller `k', lags(optlag`k')
>}
>}
>
>My problem is I cannot get stata to read the optimal lags value for the 
>option lags, as this has to be specified as a numeric variable. Is there a 
>way I can ask stata to do this loop and correctly specify the values in 
>the lags option for the dfuller test?

You need to parrallel loops, one over company and one over optlag`k', and 
that block within a loop over your k variables. So your first two lines are 
OK, although they might be telescoped into one line, check if there are no 
other variables starting with "var": (foreach k of varlist var*) or 
(foreach k of varlist var1-var4) or (foreach k of varlist var?).

But then, you want to loop over companies (forvalues x=1/20) as well as 
over the accompanying optlag`x'. The problem howver is that specifying 
"dfuller `k', lags(optlag`k')" does not work, as the number of lags cannot 
be specified as a varname but should be an integer value. So you only have 
to create a routine that translates the respective values of optlag`k' to a 
scalar.

Note that this variable optlag`x' is a constant within the variable company.
Following your approach, I would probably come up with something like:

foreach var of varlist var1-var4 {
         forvalues x=1/20  {
                 summ optlag`var' if company==`x' , mean
                 dfuller `var', lags(`r(mean)') if company==`x'
         }
}


It might even be worth the effort to look at the command dfgls. If that 
produces the optimal number of lags for you, you can acces that number 
directly as well, in `r(optlag)' or `r(maiclag)' for instance.


Ernest Berkhout
SEO Amsterdam Economics
University of Amsterdam

Room 3.08
Roetersstraat 29
1018 WB Amsterdam
The Netherlands

tel.:+ 31 20 525 1657
fax:+ 31 20 525 1686
http://www.seo.nl
===========================
A statistician: someone who insists
on being certain about uncertainty
===========================

*
*   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/


*
*   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