Dear,
Does anyone know if it is possible to optimize the code below. I have a lot of data and Stata has been running for two days.
Any help is much appreciated.
Does anyone know if it is possible to optimize the code below. I have a lot of data and Stata has been running for two days.
Any help is much appreciated.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(priceclose refdate) double(b_market_return R_sd volume) 15 20802 .29066793476086383 .013988015330073225 3544055 14.8 20803 .28276543984284264 .01219491750502958 3593659 14.78 20804 .34550501471407213 .016951893952404908 3948176 14.5 20807 .3569666121632186 .014193321115454396 7608092 14.42 20808 .41033263291208183 .008289172247704618 7331540 14.24 20809 .4071867581801756 .005880452306285766 4892042 14.2 20810 .47975600582660327 .005141142125564504 1852394 13.95 20811 .4804865948130846 .006039682463614134 3722272 14.15 20814 .39432355608943237 .008581557936344957 760866 14 20815 .34805042305693157 .012661447309070867 2335769 14.2 20816 .19647173339067603 .012782552419999496 3512804 14.65 20817 .20951045672745083 .014454574234970602 5375545 14.6 20821 .17536064993683237 .020627551147663712 523505 14.9 20822 .27468024199285185 .015254865212670707 5314402 14.9 20823 .326094447993363 .015279074757932377 1746750 15.35 20824 .32414281099897674 .012214255774921074 1885899 15.45 20825 .37876834954690003 .0144741707788485 2292524 15.21 20828 .3696024330726629 .01126381340351348 2641429 14.89 20829 .3803754556939234 .01563032157358425 3740701 14.9 20830 .3636342129930175 .020275975822514974 1985513 15 20831 .4995529260898174 .020255300592497492 5064840 15 20832 .5228324917715168 .012812688541158305 3188433 14.8 20835 .5282910537358131 .010943169527778355 1567721 14.8 20836 .21849080185365488 .010779988312457908 3445879 15.02 20837 .2470317201273872 .006596140333483685 2452963 14.75 20838 .21585794824774904 .011105348633794884 2526647 14.45 20839 .29785596263358194 .01346103352206779 5036959 14.48 20842 .26666250730532176 .015474810594547268 2334028 14.39 20843 .26853212173472246 .01514563437012279 2359199 14.29 20845 .3009824758101083 .01496600425340675 2455622 14.25 20846 .458598816941453 .008330564912019193 1881958 14.03 20849 .46040219898273765 .00861741341790695 2063672 13.94 20850 .48438349193270486 .0032341649457775135 3116406 13.8 20851 .4810116789118811 .0032872887735649666 2282779 13.67 20852 .4841844382791233 .00410631357757996 1284404 12.95 20853 .4609813225140847 .004011783740343337 7398656 12.85 20856 .44062785200119414 .022084958315610418 4600558 13.45 20857 .4189429545939568 .02244714485552819 6689002 13.4 20858 .42565707758719556 .035910562760638094 2083157 13.25 20859 .45798107893776363 .03582941971629399 3097053 13.47 20860 .4360804898303578 .0359444920718639 1990205 13.5 20863 .47225593518480435 .02262615238617526 7073517 13.61 20864 .43957437408510136 .022866778355754874 1572580 13.48 20865 .38561266079730666 .009895090200511152 2121924 13.27 20866 .35474529661402987 .012021590384909013 3676864 13.05 20867 .2475333361802396 .012598893445692993 2080454 13.12 20870 .2756558026936728 .011544083046168132 1948521 12.99 20871 .2465977879596939 .01240292595681369 1518766 12.91 20872 .2867390681398278 .0079187115973458 460138 13.07 20873 .2703304225583192 .007832551972041423 2037568 12.74 20874 .16312888837085368 .013045883689830742 3077805 12.89 20879 .23250438762069464 .015161504908064333 790201 12.7 20880 .2027122831601531 .016446748863171136 4098878 12.51 20881 .2455137892085358 .016386651044092877 3096044 12.09 20884 .203903012870287 .017958870989684843 7934645 12.67 20885 .25272492787782963 .01636070043962157 9292211 12.99 20886 .12881707645885598 .03191853380059886 2841846 13 20887 -.013394209947376914 .03411067605385401 884407 12.98 20888 .02098943898773726 .03328388354685598 3247345 13.02 20891 -.005830506705509646 .031077878443743386 907428 13.21 20892 .01925243163016297 .02198950022114325 5383624 13.3 20893 -.03108240309517214 .011954869733385066 2974842 13.25 20894 .022206566738478636 .00643802863109005 313879 12.99 20895 -.06832031590323122 .007367853834598363 1288304 12.98 20898 .047244783594704395 .013774439789180616 485879 13.01 20899 .05415162542812564 .01366754444275949 2340907 13 20900 .01720377785807472 .011229383358588415 1725872 13.99 20901 .08305654790054999 .009805650157792296 5796468 14.65 20902 .06949837501688363 .036378310112247944 6941832 14.88 20905 .08558179480112728 .03382277061661836 5517621 14.99 20906 .11799218437223138 .03146548813384615 929284 14.84 20907 .12779004317489584 .030952360243009472 5526250 14.8 20908 .046259784564860185 .0337378259890945 5236011 15.63 20909 .05421697126557225 .02203283991840497 3141709 15.45 20912 .019950690088320358 .025702592912042323 7168180 15.57 20913 .06793864376806422 .0277311690462081 8630483 15.6 20914 .06725122516873792 .027730525704845906 3154084 15.3 20915 .07599330100483266 .025936364570505546 4213237 15.39 20916 .11488235042274716 .0287798630848395 1731907 15.58 20919 .14896138991506042 .01151089703107813 963348 15.43 20920 .141187674563591 .011961288611298138 3976290 15.65 20921 .18084219321761702 .012313095251113848 6234636 16.37 20922 .09493844082407808 .014530736719363523 1438482 16.43 20926 -.04440737394030564 .02046961882292768 1372042 16.52 20927 -.13787526512463116 .02052817942830347 1282754 16.46 20928 -.0657022258280206 .02093183081515904 1900364 16.39 20929 -.08505886641246499 .019824364346061253 2531215 16.54 20933 -.04134260137488695 .02116934468628189 1982606 16.49 20934 .016320933415600557 .006079998589964183 4337906 16.25 20935 -.01424003957297813 .006290710277880814 3446965 16.85 20936 .009625391430747608 .008602491710380687 3714977 18.58 20937 .007101379351991996 .019580786521099413 6444929 17.89 20941 .2416158033485712 .04478107104782573 8166194 18 20942 .04972343915172623 .05434769975143652 2074505 17.98 20943 .03538985597489168 .05371224230420924 889059 18 20944 -.08797672552168076 .05197616842929916 5331210 18 20947 -.08799829050509456 .051458006762289975 1902268 17.99 20948 -.1780883343860402 .0201472988525531 3068821 18 20949 -.18455008004814724 .0032341649457775135 5064161 17.94 20950 -.1825259697624504 .0032341649457775135 10171311 end format %td refdate *1) Volume_5 levelsof refdate, local(refdate) tempvar temp_quintile gen int q_volume = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 4 { xtile `temp_quintile' = volume if refdate == `y', nq(5) replace q_volume = `temp_quintile' if refdate == `y' drop `temp_quintile' } else { display "Insufficient data to compute quintiles for refdate `y'" } } *2) Volume_4 levelsof refdate, local(refdate) tempvar temp_quartil gen int q4_volume = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 3 { xtile `temp_quartil' = volume if refdate == `y', nq(4) replace q4_volume = `temp_quartil' if refdate == `y' drop `temp_quartil' } else { display "Insufficient data to compute quartil for refdate `y'" } } *3) b_market_return_5 levelsof refdate, local(refdate) tempvar temp_quintile gen int q_b = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 4 { xtile `temp_quintile' = b_market_return if refdate == `y', nq(5) replace q_b = `temp_quintile' if refdate == `y' drop `temp_quintile' } else { display "Insufficient data to compute quintiles for refdate `y'" } } *4) b_market_return_4 levelsof refdate, local(refdate) tempvar temp_quartil gen int q4_b = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 3 { xtile `temp_quartil' = b_market_return if refdate == `y', nq(4) replace q4_b = `temp_quartil' if refdate == `y' drop `temp_quartil' } else { display "Insufficient data to compute quartil for refdate `y'" } } *5) R_sd_5 levelsof refdate, local(refdate) tempvar temp_quintile gen int q_R_sd = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 4 { xtile `temp_quintile' = R_sd if refdate == `y', nq(5) replace q_R_sd = `temp_quintile' if refdate == `y' drop `temp_quintile' } else { display "Insufficient data to compute quintiles for refdate `y'" } } *6) R_sd_4 levelsof refdate, local(refdate) tempvar temp_quartil gen int q4_R_sd = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 3 { xtile `temp_quartil' = R_sd if refdate == `y', nq(4) replace q4_R_sd = `temp_quartil' if refdate == `y' drop `temp_quartil' } else { display "Insufficient data to compute quartil for refdate `y'" } } *7) priceclose_5 levelsof refdate, local(refdate) tempvar temp_quintile gen int q_priceclose = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 4 { xtile `temp_quintile' = priceclose if refdate == `y', nq(5) replace q_priceclose = `temp_quintile' if refdate == `y' drop `temp_quintile' } else { display "Insufficient data to compute quintiles for year `y'" } } *8) priceclose_4 levelsof refdate, local(refdate) tempvar temp_quartil gen int q4_priceclose = . foreach y of local refdate { quietly count if refdate == `y' if `r(N)' >= 3 { xtile `temp_quartil' = priceclose if refdate == `y', nq(4) replace q4_priceclose = `temp_quartil' if refdate == `y' drop `temp_quartil' } else { display "Insufficient data to compute quartil for refdate `y'" } }
Comment