Hello,
Sorry, am new to stata and my question might seem too simple but just know am helpless and guide accordingly.
My study is on institutional investor horizon and stock returns, I need to calculate the institutional investor change in their stock position to group them as either short-term or long-term using these formulas which i need to code into stata and am failing to do that.




[IMG]file:///C:/Users/user/AppData/Local/Temp/msohtmlclip1/01/clip_image004.png[/IMG]
[IMG]file:///C:/Users/user/AppData/Local/Temp/msohtmlclip1/01/clip_image006.png[/IMG]




Here, Ni,s,t is the number of shares institutional investor i hold in stock s at quarter t and ps,t is the price of stock s.
Also when try to xtset, get repeated time variable
Code:
 xtset o_id date
see the data sample
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long date float o_id long(sharesheld changeinshares PRC) float c_id
20190329 1    100     100 44725 4556
20120629 2   2338    2004 27859  427
20120928 2   2113    -225 22559 6114
20121231 2      0   -2113 25763 6114
20120330 2    334     334 26311  428
20120629 3    148     148 27859  427
20120928 3    244      96 22559 6114
20121231 3      0    -244 25763 6114
20150630 4      0   -3200 46009 4556
20131231 4   4000    4000 50977 4556
20150331 4   3200    3200 46188 4556
20140331 4      0   -4000 50945 4556
20100630 5  20300       0 15280  428
20100331 5  20300   -3500 17501  428
20080930 5 100804    1663 50839 4556
20100630 5 180519  -21070 41115 4556
20100630 5   9000    1200 27593  464
20140331 5      0  -30265 50945 4556
20030331 5  15280   15280 25038  464
20110630 5 771256  697210 48558 4556
20100930 5  10200    1200 32357  464
20190329 5      0  -56726 44725 4556
20110630 5      0   -4700 31428  464
20100930 5  20300       0 18540  428
20110930 5 258275 -512981 41637 4556
20090331 5      0 -193762 42063 4556
20130930 5  10594   10594 48973 4556
20090930 5   7200    -300 32853  464
20091231 5      0 -100000 44783 4556
20070629 5  13785     300 43133 4556
20101231 5  61991 -154410 48852 4556
20100331 5 201589  201589 45195 4556
20181231 5  56726   56726 36736 4556
20100930 5 216401   35882 43207 4556
20090930 5 100000  100000 41878 4556
20030930 5      0  -15280 22967  464
20090930 5  23800    1200 16712  428
20131231 5  30265   19671 50977 4556
20110331 5   4700   -5500 31292  464
20081231 5 193762   92958 41922 4556
20070330 5  13485   13485 42350 4556
20090331 5   7500    7500 28832  464
20100331 5   7800     600 33488  464
20111230 5      0 -258275 42644 4556
20090331 5  22600   22600 52963  428
20070928 5      0  -13785 45949 4556
20110331 5  74046   12055 51279 4556
20110331 5      0  -20300 25108  428
20080630 5  99141   99141 11580 4556
20000630 6  58469  -60210 50285  464
20000929 6      0  -58469  7128  464
20091231 7  10309    -300 44783 4556
20130930 7  84350  -69711 48973 4556
20051230 7    269       0 24575  236
20180329 7     33       0 12925 7212
20080331 7      0   -3500 51676 4556
20060929 7      0   -5718 37067 4556
20170929 7   4640    -258 38798 4556
20190329 7   3981   -1991 44725 4556
20160630 7   6838    -300 44693 4556
20101231 7 136680     681 48852 4556
20150630 7     33       0 48329 7212
20180928 7   4153       3 48022 4556
20120928 7 161876    3654 41932 4556
20090630 7    225       0 33710  464
20100630 7   9799    -580 41115 4556
20150930 7     33       0 48066 7212
20170630 7     33       0 53963 7212
20161230 7   6088    -625 45143 4556
20140930 7     33       0 42523  464
20091231 7    700     700 34709  464
20150331 7  25280   -2410 46188 4556
20140930 7  33115  -56574 53535 4556
20180629 7     33       0     1 7212
20130930 7     33       0 37538  464
20150331 7     33       0 48863 7212
20160331 7   7138   -1200 41678 4556
20130328 7 155440     625 48026 4556
20100331 7    700       0 33488  464
20100930 7 135999  126200 43207 4556
20131231 7  91147    6797 50977 4556
20090930 7      0    -225 32853  464
20060630 7   5718    5718 41728 4556
20141231 7  27690   -5425 48390 4556
20131231 7     33       0 41903  464
20120330 7 160724    1338 43131 4556
20100630 7    700       0 27593  464
20181231 7   5972    1819 36736 4556
20130628 7 154061   -1379 45944 4556
20160630 7      0   -5631 51268 7212
20170331 7     33       0 53933 7212
20111230 7 159386    6425 42644 4556
20130930 7      0    -103 26878 6114
20171229 7   4643       3 38967 4556
20121231 7 154815   -7061 41751 4556
20050630 7    269     269 22541  236
20170331 7   5620    -468 39188 4556
20100331 7  10379      70 45195 4556
20140630 7     33       0 43132  464
20180629 7   4150       3 46010 4556
end
label values PRC PRC
label def PRC 1 "#DIV/0!", modify
label def PRC 7128 "10.71179678", modify
label def PRC 11580 "126.19", modify
label def PRC 12925 "132.61", modify
label def PRC 15280 "15.59904688", modify
label def PRC 16712 "16.80904682", modify
label def PRC 17501 "17.31190394", modify
label def PRC 18540 "18.24952294", modify
label def PRC 22541 "20.88", modify
label def PRC 22559 "20.91", modify
label def PRC 22967 "21.15212849", modify
label def PRC 24575 "23", modify
label def PRC 25038 "23.7757848", modify
label def PRC 25108 "23.91190362", modify
label def PRC 25763 "24.72", modify
label def PRC 26311 "25.37857022", modify
label def PRC 26878 "26.23", modify
label def PRC 27593 "27.31948166", modify
label def PRC 27859 "27.89285581", modify
label def PRC 28832 "29.48531875", modify
label def PRC 31292 "31.10969657", modify
label def PRC 31428 "31.40023569", modify
label def PRC 32357 "33.19189361", modify
label def PRC 32853 "34.27041004", modify
label def PRC 33488 "35.78913727", modify
label def PRC 33710 "36.25576071", modify
label def PRC 34709 "38.85740648", modify
label def PRC 36736 "40.5", modify
label def PRC 37067 "41.42", modify
label def PRC 37538 "42.94696472", modify
label def PRC 38798 "46.89", modify
label def PRC 38967 "47.47", modify
label def PRC 39188 "48.21", modify
label def PRC 41115 "50.34", modify
label def PRC 41637 "52.46", modify
label def PRC 41678 "52.65", modify
label def PRC 41728 "52.85", modify
label def PRC 41751 "52.96", modify
label def PRC 41878 "53.46", modify
label def PRC 41903 "53.56484899", modify
label def PRC 41922 "53.64", modify
label def PRC 41932 "53.72", modify
label def PRC 42063 "54.2", modify
label def PRC 42350 "55.47", modify
label def PRC 42523 "56.1885053", modify
label def PRC 42644 "56.8", modify
label def PRC 43131 "58.95", modify
label def PRC 43132 "58.95302907", modify
label def PRC 43133 "58.96", modify
label def PRC 43207 "59.12", modify
label def PRC 44693 "60.1", modify
label def PRC 44725 "60.23", modify
label def PRC 44783 "60.5", modify
label def PRC 45143 "62.29", modify
label def PRC 45195 "62.55", modify
label def PRC 45944 "66.49", modify
label def PRC 45949 "66.53", modify
label def PRC 46009 "66.88", modify
label def PRC 46010 "66.89", modify
label def PRC 46188 "67.87", modify
label def PRC 48022 "71.58", modify
label def PRC 48026 "71.61", modify
label def PRC 48066 "71.87", modify
label def PRC 48329 "73.36", modify
label def PRC 48390 "73.82", modify
label def PRC 48558 "74.76", modify
label def PRC 48852 "76.54", modify
label def PRC 48863 "76.63", modify
label def PRC 48973 "77.34", modify
label def PRC 50285 "8.796064476", modify
label def PRC 50839 "82.08", modify
label def PRC 50945 "82.88", modify
label def PRC 50977 "83", modify
label def PRC 51268 "85.14", modify
label def PRC 51279 "85.21", modify
label def PRC 51676 "88.18", modify
label def PRC 52963 "9.968094763", modify
label def PRC 53535 "94.32", modify
label def PRC 53933 "98", modify
label def PRC 53963 "98.36", modify