Hard to know where to start here.....
. I believe what you're trying to do is find the observation number of the 95th quantile of X, and find the observation number of the next observation of X (which is, surely, just 1 plus the number you just found).
First of all, with only 21 observations, the 95% quantile is just going to be the maximum value, isn't it (in which case you could just use @max and @imax).
Secondly you've closed your for loop before you've closed your if statement, even though you opened the if statement after the for loop. Thus I think you meant to have endif followed by next, and not the other way round.
Thirdly your for loop only runs from 1-11. It is possible that the 95th quantile is after observation 11. I think you meant to run the loop until 21.
Fourthly, you've created a matrix with only 2 rows in it, but you're assigning the 95th quantile to the !ath row, even though !a could be equal to 21.
Fifthly you had a space between results and (!a+1,1).
Sixthly, you're assigning @elem(y,@otod(!a+1)) to the matrix. But If you run !a from 1 to 21 (as I presume you meant to?), then !a+1 could equal 22, and there aren't 22 observations in Y.
Now assuming I've interpreted what you were trying to do correctly, I think this is a corrected version:
Code: Select all
wf a 1990 2010
series x=nrnd
series y=@trend
frml z=x>@quantile(x,0.95)
matrix(2,1) results
for !a = 1 to 21
if @elem(z,@otod(!a))=1 then
results(1,1)=@elem(y,@otod(!a))
results(2,1)=@elem(y,@otod(!a+1))
endif
next
I haven't corrected point 6, since I'm not sure what you intended to do in that case.
Now having fixed the errors, there are some pointers... You appear to be assigning the !ath value of Y, even though you've set Y equal to @trend. Given that Y is equal to @trend, the !ath value of Y is simply equal to (!a-1) (since @trend starts at 0). Thus you could do:
Code: Select all
wf a 1990 2010
rndseed 3
series x=nrnd
frml z=x>@quantile(x,0.95)
matrix(2,1) results
for !a = 1 to 21
if @elem(z,@otod(!a))=1 then
results(1,1)=!a-1
results(2,1)=!a
endif
next
Finally, if you want to be really smart, you could probably write this program using samples and the @convert function instead...
Code: Select all
wf a 1990 2010
series x=nrnd
series y=@trend
smpl if x>@quantile(x,0.95) or x(-1)>@quantile(x,0.95)
matrix results = @convert(y)
Note I set the sample to be the observation of X that is in the 95th quantile, and the observation after that.