Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Problem with foreach in Stata 10.1


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Problem with foreach in Stata 10.1
Date   Mon, 17 Nov 2008 17:44:00 -0000

Your problem report is very clear and I can reproduce it. 

But this is nothing to do with -foreach- (mentioned in your title) or
-forvalues- (used in your example). The same behaviour is seen if you
just do your example the slow way

	webuse air2
	dfuller air, lags(1)
	estat ic
	dfuller air, lags(2)
	estat ic
	dfuller air, lags(3)
	estat ic

I don't why you get the same results, but the problem if there is one
lies between -dfuller- and -estat ic-. 

Nick 
[email protected] 

Joao Ricardo F. Lima

I`m with one problem using foreach with Stata 10.1. I was teaching
unit root test, I was demonstrating how to use the foreach command
too. The, the surprise:

***begin example****
webuse air2
forvalues i=1/3 {
	dfuller air, lags(`i')
	estat ic
}
***end example****

This works fine with Stata 9.2, but don't with 10.1. With Stata 9.2:

. webuse air2
(TIMESLAB: Airline passengers)

. forvalues i=1/3 {
  2.         dfuller air, lags(`i')
  3.         estat ic
  4. }

Augmented Dickey-Fuller test for unit root         Number of obs   =
142

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -2.345            -3.496            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.1579

------------------------------------------------------------------------
------
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
------
           . |    142   -701.1962   -691.5394      3     1389.079
1397.946
------------------------------------------------------------------------
------

Augmented Dickey-Fuller test for unit root         Number of obs   =
141

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -1.811            -3.496            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.3751

------------------------------------------------------------------------
------
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
------
           . |    141   -696.6955   -684.4298      4      1376.86
1388.655
------------------------------------------------------------------------
------

Augmented Dickey-Fuller test for unit root         Number of obs   =
140

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -1.536            -3.497            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.5158

------------------------------------------------------------------------
------
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
------
           . |    140   -692.2411   -678.5628      5     1367.126
1381.834
------------------------------------------------------------------------
------

.
end of do-file

.

With Stata 10.1:

. webuse air2
(TIMESLAB: Airline passengers)

. forvalues i=1/3 {
  2.         dfuller air, lags(`i')
  3.         estat ic
  4. }

Augmented Dickey-Fuller test for unit root         Number of obs   =
142

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -2.345            -3.496            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.1579

------------------------------------------------------------------------
-----
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
-----
           . |    142   -701.1962   -691.5394      3     1389.079
1397.946
------------------------------------------------------------------------
-----
               Note:  N=Obs used in calculating BIC; see [R] BIC note

Augmented Dickey-Fuller test for unit root         Number of obs   =
141

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -1.811            -3.496            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.3751

------------------------------------------------------------------------
-----
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
-----
           . |    142   -701.1962   -691.5394      3     1389.079
1397.946
------------------------------------------------------------------------
-----
               Note:  N=Obs used in calculating BIC; see [R] BIC note

Augmented Dickey-Fuller test for unit root         Number of obs   =
140

                               ---------- Interpolated Dickey-Fuller
---------
                  Test         1% Critical       5% Critical      10%
Critical
               Statistic           Value             Value
Value
------------------------------------------------------------------------
------
 Z(t)             -1.536            -3.497            -2.887
-2.577
------------------------------------------------------------------------
------
MacKinnon approximate p-value for Z(t) = 0.5158

------------------------------------------------------------------------
-----
       Model |    Obs    ll(null)   ll(model)     df          AIC
BIC
-------------+----------------------------------------------------------
-----
           . |    142   -701.1962   -691.5394      3     1389.079
1397.946
------------------------------------------------------------------------
-----
               Note:  N=Obs used in calculating BIC; see [R] BIC note

.
end of do-file


How you can see, the estat ic is repeated in each looping...

Can someone reproduce my problem and explain what am I doing wrong?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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