[R] obtaining the sum of lagged variables
T.Riedle
tr206 at kent.ac.uk
Fri Apr 24 21:17:47 CEST 2015
Hi everybody,
I am trying to replicate the formula shown in the attachment. I want to estimate tau using a macroeconomic variable X at month t using k lags of the variable X.
My code so far looks as follows:
psi <- fn(...)
k <- 1:K
ltau <- m + theta*sum(psi*X[t-k])
Unfortunately, if I run the code as shown the result I get is NA but I want to obtain a list of ltaus at month t.
ltau <- m + theta*sum(psi*X[t-k])
> ltau
[1] NA
Hence I defined t and ran X[t-k] and get following results. That is, X[t-k] provides every third element in my data table three times instead of calculating the sum of the lagged observations multiplied with psi
t<-1:15
> t
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
> X[t-k]
[1] -0.25 -0.25 -0.25 0.50 0.50 0.50 -0.44 -0.44 -0.44 0.15 0.15 0.15
How do I get the list of taus at month t based on the sum of lagged observations as shown in the attachment?
Thanks in advance
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tau.png
Type: image/png
Size: 8142 bytes
Desc: tau.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150424/f6171af4/attachment.png>
More information about the R-help
mailing list