Dear R Users,

I have struggled with the following problem for days, which I thought was 
simple, although it would likely be basic to most of you.
I am working with time series data. 
In my script, my intention is to create first differences of the variables in 
the file so that I end up estimating an equation of the form:
DCred(t) =c + 
DCred(t-1)+DCred(t-2)+...+DBoB(t)+DBoB(t-1)+DBoB(t-2)+...+Drvr(t)+Drvr(t-1)+Drvr(t-2)+...+e(t)

Where D at the beginning of each variable represents 'change', for first 
difference and e(t) is the error term.
Now I am trying to use loops to calculate 5 lagged first-differences of each 
variable in the dataset - e.g., DCred(t-1), DCred(t-2), ..., DCred(t-5).
Example:
# Differences of Cred
DCred<- diff(Cred, difference=1)
DCred
for(i in 1:5){
print(DCred[i]<- diff(DCred, lag=i, difference=1))
}
After I calculated the contemporaneous first difference DCred, this loop is 
meant to compute the subsequent first differences of the same variable; i.e., 
DCred(t-1) and call it DCred1, DCred(t-2) and call it DCred2, ... and 
DCred(t-5) and call it DCred5.
The loop works, at least I think so. But now after the loop has executed, when 
I type DCred1[1] (which I thought would give me the first value in the series 
for DCred(t-1)), called DCred1, I get a message "object 'DCred1' not found". 
Similarly typing Dcred1[2] (which I thought would give the second value of 
DCred(t-1)), ie., the second value of DCred1, gives "object DCred1[2] not 
found", etc.
A copy of the commands and error messages is below:
> DCred1[1]
Error: object 'DCred1' not found
> DCred1[2]
Error: object 'DCred1' not found

How can I solve this problem? Thank you kindly for your time.
        [[alternative HTML version deleted]]

______________________________________________
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