On Tue, Apr 5, 2011 at 8:35 AM, Ravi Kulkarni <ravi.k...@gmail.com> wrote:
> I am trying to reproduce the output of a time series example in Koop's book
> "Analysis of Financial Data". Koop does the example in Excel and I used the
> ts function followed by the lm function.
> I am unable to get the exact coefficients that Koop gives - my coefficients
> are slightly different.
> After loading the data file and attaching the frame, my code reads:
>
>> y = ts(m.cap)
>> x = ts(oil.price)
>> d = ts.union(y,x,x1=lag(x,-1),x2=lag(x,-2),x3=lag(x,-3),x4=lag(x,-4))
>> mod1 = lm(y~x+x1+x2+x3+x4, data=d)
>> summary(mod1)
>
> Koop gives an intercept of 92001.51, while the code above gives 91173.32.
> The other coefficients are also  slightly off.
>
> This is the example in Table 8.3 of Koop. I also attach a plain text version
> of the tab separated file "badnews.txt".
> http://r.789695.n4.nabble.com/file/n3427897/badnews.txt badnews.txt
>
> Any light on why I do not get Koop's coefficients is most welcome...
>

It looks like he erroneously left out the first point.

> URL <- "http://r.789695.n4.nabble.com/file/n3427897/badnews.txt";
> BAD <- read.table(URL, header = TRUE)
> library(dyn)
> dyn$lm(m.cap ~ lag(oil.price, -(0:4)), as.zoo(BAD))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = as.zoo(BAD))

Coefficients:
            (Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
               91173.32                  -131.99                  -449.86
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
                -422.52                  -187.10                   -27.77

>
> # without first point
> dyn$lm(m.cap ~ lag(oil.price, -(0:4)), tail(as.zoo(BAD), -1))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = tail(as.zoo(BAD),
    -1))

Coefficients:
            (Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
                92001.5                   -145.0                   -462.1
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
                 -424.5                   -199.5                    -36.9

>


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to