Menu

#194 durbin watson test

v1.0_(example)
closed
nobody
None
5
2015-10-20
2015-08-08
KTTK
No

I get different durbin watson statistics with gretl compared to R (package lmtest and package car):
gretl (dw is 0,127663):
open abdata.gdt
ols WAGE 0 EMP CAP

In R I get 0.4219348 with both tests:
lm1 <- lm(WAGE ~ EMP + CAP, gretldata)
require(lmtest)
dwtest(lm1)
require(car)
durbinWatsonTest(lm1)

Discussion

  • Riccardo "Jack" Lucchetti

    On Sat, 8 Aug 2015, KTTK wrote:

    I get different durbin watson statistics with gretl compared to R
    (package lmtest and package car):

    Easy: R doesn't know that abdata is a panel dataset, so lags of residuals
    are not computed correctly. If you force gretl to do the wrong thing,
    dicrepancies disappear. For example:

    <hansl>
    open abdata.gdt</hansl>

    foreign language=R --send-data
    attach(gretldata)
    lm1 <- lm(WAGE ~ EMP + CAP, gretldata)
    require(lmtest)
    dwtest(lm1)
    require(car)
    durbinWatsonTest(lm1)
    end foreign

    smpl --no-missing
    setobs 1 1 --time-series
    ols WAGE 0 EMP CAP


    Riccardo (Jack) Lucchetti
    Dipartimento di Scienze Economiche e Sociali (DiSES)

    Università Politecnica delle Marche
    (formerly known as Università di Ancona)

    r.lucchetti@univpm.it
    http://www2.econ.univpm.it/servizi/hpp/lucchetti


     
    • Sven Schreiber

      Sven Schreiber - 2015-08-08

      Am 08.08.2015 um 15:50 schrieb Riccardo Jack Lucchetti:

      On Sat, 8 Aug 2015, KTTK wrote:

      I get different durbin watson statistics with gretl compared to R
      (package lmtest and package car):
      

      Easy: R doesn't know that abdata is a panel dataset, so lags of residuals

      Yep, I was also getting suspicious when I saw the "abdata.gdt" file name...

      are not computed correctly. If you force gretl to do the wrong thing,
      dicrepancies disappear. For example:

      <hansl>
      open abdata.gdt</hansl>

      foreign language=R --send-data

      Of course it would be nice in the future if the --send-data option also
      conveyed the information about the structure of the dataset to R. Don't
      know how easy it is from the R side to define that. And it's not a bug
      but a feature request obviously.

      thanks,
      sven

       
  • KTTK

    KTTK - 2015-08-08

    Uh, I see the ording of the observations is different, depending if the panel property is set in gretl! Thanks!

     
  • KTTK

    KTTK - 2015-08-08

    Mhh, I tried the right order for the data (and residuals) in R with a fixed effects model, but do not get the same durbin watson statistic.

    gretl (dw 0.928223):
    open abdata.gdt
    panel WAGE 0 EMP CAP

    R (via plm's pdwtest 1.3527):
    require(plm)
    pgdata <- pdata.frame(gretldata, index=c("unit", "YEAR"), drop.index=F)
    pdwtest(plm(WAGE ~ EMP + CAP, data=pgdata, model="within"))
    residuals(plm(WAGE ~ EMP + CAP, data=pgdata, model="within"))[1:10] # to check order of residuals. Is the same as in gretl

     
  • KTTK

    KTTK - 2015-08-08

    Sorry about posting so frequently. It could well be the case that there is something wrong with plm's pdwtest() in R, see http://stackoverflow.com/questions/31894055/pdwtest-from-plm-with-wrong-p-value-for-pooled-ols-durbin-watson-test-for-autoc

    For a fixed effect model, the clustering of the obervations by unit is not respected. Differences of residuals are just taken one after another, computing one difference between two different units. Could well be the case that this should be changed in R's pdwtest() yielding this (?):
    sum(diff(residuals(plm_fe))^2, na.rm = T) / sum(residuals(plm_fe)^2)

    Then I get the same dw statistic as gretl (0.928223)

     
  • Allin Cottrell

    Allin Cottrell - 2015-08-08

    OK, it seems time to close this one.

    The order of the residuals is not the issue (or shouldn't be, unless R
    is doing something really weird). The issue is whether it's OK to lag
    residuals across the boundaries of units/individuals in a panel model,
    and the answer to that is No. Gretl doesn't do it. For reference, we
    use the method of Bhargava, Franzini and Narendranathan, "Serial
    Correlation and the Fixed Effects Model", Review of Economic Studies
    49, 1982.

     
  • KTTK

    KTTK - 2015-08-10

    Yes, I think you can close this issue.
    It seems like plm's durbin watson test does not use a durbin watson test that it tailored to panel models, but gretl does - hence the difference. BTW: STATA has a modified version of Bhargava et al. for unbalanced and unequally spaced data (if you are interested see http://www.stata.com/manuals14/xtxtregar.pdf, also for references).

     
  • Allin Cottrell

    Allin Cottrell - 2015-10-20
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB