Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(date id) float price double calc 1 1 60 5.5 1 2 4 6.4 2 1 5.5 4 2 2 6.4 5 2 3 0 6 3 1 4 7 3 2 5 8 3 3 6 9 end
I have a date, an id, and a price variable.
The date variable is for 20 years (daily). In each date the ids increases or decreases. The price variable is only available for date 1. So, initially the price variable has missing values for date 2 onwards.
Now on date 1, I will perform some calculations and will generate the calc variable for date 1.
After that, the value of calc on date 1 have to be carried forward to the price variable of Date 2 (2nd observation of date variable) and so on.
Basically, I need a loop that will first perform a calculation on Date 1, then based on the answers of date 1, it will perform a calculation on date 2, then based on the answers of date 2, it will perform a calculation on date 3 and so on.
any help would be greatly appreciated.
Thanks
0 Response to For loop for each observation in a variable
Post a Comment