I have a very big data set (50 million) hourly observations. This data set has ids, dates, prices and many other variables. Now I want to perform certain analysis on the data. For example, I want to find the rolling SD of price. The problem is because of large number of observations, it takes ages to complete.
A probable solution is that I create frames based on ids.
Therefore, what I want is to create a loop that takes an observation from variable id (e.g., all observation if id == 100) and puts them into a different frame where I can run some analysis on that.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int(id date_stata) double price 100 13880 5 100 13881 4 100 13882 6 100 13883 7 100 13884 9 100 13885 8 101 13880 12 101 13881 55 101 13882 77 101 13883 99 101 13884 77 101 13885 88 102 13880 4 102 13881 9 102 13882 7 102 13883 8 102 13884 6 102 13885 9 103 13880 4 103 13881 5 103 13882 8 103 13883 9 103 13884 6 103 13885 4 end format %tdMonth_dd,_CCYY date_stata
In the above data set, I first want to create a frame for ID 100, move all the observations of that ID in a different frame and then perfom my code.
I know how I will perform the code in the loop and how I will merge it back with the default frame after the analysis. I just want to know how I will pick each id individually.
There are more than 1000 ids so doing them manually is out of the question.
Any help would be greatly appreciated.
0 Response to Loop for creating different frames based on different ids
Post a Comment