Hello, I am writing codes for time series computation but encountering some problems
Given the quarterly data from 1983Q1 to 1984Q2 PI1<-ts(c(2.747365190,2.791594762, -0.009953715, -0.015059485, -1.190061246, -0.553031799, 0.686874720, 0.953911035), start=c(1983,1), frequency=4) > PI1 Qtr1 Qtr2 Qtr3 Qtr4 1983 2.747365190 2.791594762 -0.009953715 -0.015059485 1984 -1.190061246 -0.553031799 0.686874720 0.953911035 If I would like to create a time series vector containing the data in 4 quarters ahead > PI4<-lag(PI1,4)> PI4 Qtr1 Qtr2 Qtr3 Qtr4 1982 2.747365190 2.791594762 -0.009953715 -0.015059485 1983 -1.190061246 -0.553031799 0.686874720 0.953911035 Confusingly, PI1[1] and PI4[1] are exactly the same! I usually would like to calculate the difference between the vector of interest and the corresponding values 4 quarters ahead, but it is zero! > PI1[1][1] 2.747365> PI4[1][1] 2.747365 One remedy that comes into my mind is to use window,but a warning message emerges > PI4w<-window(PI4, start=start(PI1), end=end(PI1))Warning message:In > window.default(x, ...) : 'end' value not changed> PI4w Qtr1 > Qtr2 Qtr3 Qtr4 1983 -1.1900612 -0.5530318 0.6868747 0.9539110 Similar problems happen with the usage of the function "diff", which calculate the difference. I wonder if it is better to work with the dates (1983Q1, 1983Q2,.....) directly? If I want to write a loop, say, to conduct some computation from 1983Q1 to 2011Q4, the only way I know is to convert the dates to the ordinal indices, 1, 2, 3...... Can we work with the dates? Is there any built-in equality that provides the computation like 1983Q1 +1 equals 1983Q2? In EViews, it is easy to do that. We can let %s run from 1983Q1 to 2011Q4, and he knows that 1983Q1+1 is exactly 1983Q2. Thanks very much for your reply! miao [[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.