I run the below code on appended dataset to calculate monthly idiosyncratic skewness as skewness of residuals obtaining by regressing previous one years of daily returns (rt) data on daily market returns (mkt) and square of daily market returns (mkt2). The code however gets hanged and does not produce any results. I can't figure out the issue. Need help.

Code:
xtset mdate stock_id

capture program drop one_regression
program define one_regression
    regress rt mkt mkt2
    predict resid, resid
    summ resid, detail
    gen double skewness = r(skewness)
    gen obs  = r(N)
    gen double mean = r(mean)
end

bysort stock_id mdate (date): gen high = cond(_n==1., mdate, -11)
rangerun one_regression, by(stock_id) interval(mdate -11 0)

collapse(mean) mdate reg_nobs stock_id b_mkt2  , by (stock year month)
order stock year month mdate reg_nobs stock_id b_mkt2
replace b_mkt2 =. if reg_nobs<200

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float stock_id str52 stock float(date mdate) byte month int year float(rt mkt mkt2)
1 "3M India Ltd." 15886 521 6 2003  .009533716  .007865   .0000619
1 "3M India Ltd." 15883 521 6 2003 -.012074256  .009992   .0000998
1 "3M India Ltd." 15882 521 6 2003  .011034168  .003893   .0000152
1 "3M India Ltd." 15881 521 6 2003 -.013975303  .016005 .000256166
1 "3M India Ltd." 15880 521 6 2003 -.003102842  .002033   4.13e-06
1 "3M India Ltd." 15879 521 6 2003  .004186865 -.013336 .000177845
1 "3M India Ltd." 15876 521 6 2003  .004656811  .008685   .0000754
1 "3M India Ltd." 15875 521 6 2003  .001214485  .006526   .0000426
1 "3M India Ltd." 15874 521 6 2003  .031898383  .006009   .0000361
1 "3M India Ltd." 15873 521 6 2003 -.007203266  .021803 .000475352
1 "3M India Ltd." 15872 521 6 2003 -.004266642 -.001889   3.57e-06
1 "3M India Ltd." 15869 521 6 2003  -.01446385   .00344   .0000118
1 "3M India Ltd." 15868 521 6 2003 -.007322823  .010436 .000108913
1 "3M India Ltd." 15867 521 6 2003  .019095726  .008985   .0000807
1 "3M India Ltd." 15866 521 6 2003  -.02163825 -.018968 .000359791
1 "3M India Ltd." 15865 521 6 2003   .09973572  .006161    .000038
1 "3M India Ltd." 15862 521 6 2003 -.017246207  .006592   .0000435
1 "3M India Ltd." 15861 521 6 2003  .004897146  .000296   8.74e-08
1 "3M India Ltd." 15860 521 6 2003 -.006100614  .014723 .000216768
1 "3M India Ltd." 15859 521 6 2003 -.031379614  .001928   3.72e-06
1 "3M India Ltd." 15858 521 6 2003    .0157434    .0028   7.84e-06
1 "3M India Ltd." 15855 520 5 2003  .015344273  .016388 .000268563
1 "3M India Ltd." 15854 520 5 2003 -.007012919  .009597   .0000921
1 "3M India Ltd." 15853 520 5 2003 -.005384392  .010709 .000114693
1 "3M India Ltd." 15852 520 5 2003  -.03143467  -.00696   .0000484
1 "3M India Ltd." 15851 520 5 2003  .009376593  .019336 .000373887
1 "3M India Ltd." 15848 520 5 2003   .02838536  .009681   .0000937
1 "3M India Ltd." 15847 520 5 2003  .006974769  .003643   .0000133
1 "3M India Ltd." 15846 520 5 2003  .009649982  .003658   .0000134
1 "3M India Ltd." 15845 520 5 2003  .006767674  .012953 .000167783
1 "3M India Ltd." 15844 520 5 2003  .008480898 -.007435   .0000553
1 "3M India Ltd." 15841 520 5 2003  -.02464387  .015005 .000225152
1 "3M India Ltd." 15840 520 5 2003  .029448276  .013856 .000191978
1 "3M India Ltd." 15839 520 5 2003 -.010313845  .010457 .000109344
1 "3M India Ltd." 15838 520 5 2003  .015578233  .008679   .0000753
1 "3M India Ltd." 15837 520 5 2003 -.001125183  .007556   .0000571
1 "3M India Ltd." 15834 520 5 2003 -.008068571 -.001759   3.09e-06
1 "3M India Ltd." 15833 520 5 2003  .006875818  -.00786   .0000618
1 "3M India Ltd." 15832 520 5 2003 -.000124182 -.000197   3.88e-08
1 "3M India Ltd." 15831 520 5 2003 -.018608289  .006877   .0000473
1 "3M India Ltd." 15830 520 5 2003   .02503203  .012248  .00015002
1 "3M India Ltd." 15827 520 5 2003   .04601726  .007976   .0000636
1 "3M India Ltd." 15825 519 4 2003  .036240544  .004647   .0000216
1 "3M India Ltd." 15824 519 4 2003   .03760189  .000261   6.83e-08
1 "3M India Ltd." 15823 519 4 2003  .003653921  .006984   .0000488
1 "3M India Ltd." 15820 519 4 2003 -.017259795 -.004785   .0000229
1 "3M India Ltd." 15819 519 4 2003 -.033946905 -.002703   7.31e-06
1 "3M India Ltd." 15818 519 4 2003  .010775134 -.009299   .0000865
1 "3M India Ltd." 15817 519 4 2003   .06061496 -.002435   5.93e-06
1 "3M India Ltd." 15816 519 4 2003  .004707749  .008126    .000066
1 "3M India Ltd." 15812 519 4 2003  -.02267936 -.013345  .00017808
1 "3M India Ltd." 15811 519 4 2003  .016032182  .005756   .0000331
1 "3M India Ltd." 15810 519 4 2003   .06006362  .002192   4.81e-06
1 "3M India Ltd." 15806 519 4 2003   .02069287 -.007982   .0000637
1 "3M India Ltd." 15805 519 4 2003  -.05525858 -.033738 .001138256
1 "3M India Ltd." 15804 519 4 2003  -.02321739 -.009597   .0000921
1 "3M India Ltd." 15803 519 4 2003  .003712956 -.008123    .000066
1 "3M India Ltd." 15802 519 4 2003   .03585195  .015533 .000241275
1 "3M India Ltd." 15799 519 4 2003   .03719635  .009709   .0000943
1 "3M India Ltd." 15798 519 4 2003  .014588794  .010645 .000113306
1 "3M India Ltd." 15797 519 4 2003  .011566542  .013855 .000191964
1 "3M India Ltd." 15796 519 4 2003  -.02304087  .009605   .0000923
1 "3M India Ltd." 15795 518 3 2003  -.07255269 -.021219 .000450234
1 "3M India Ltd." 15792 518 3 2003   .03068691 -.001764   3.11e-06
1 "3M India Ltd." 15791 518 3 2003  .008472209 -.005611   .0000315
1 "3M India Ltd." 15790 518 3 2003 -.003758863 -.000948   8.98e-07
1 "3M India Ltd." 15789 518 3 2003 -.000158863 -.001227   1.51e-06
1 "3M India Ltd." 15788 518 3 2003 -.016294243 -.019509 .000380588
1 "3M India Ltd." 15786 518 3 2003  .005381303  .005288    .000028
1 "3M India Ltd." 15785 518 3 2003 -.013049488  .004289   .0000184
1 "3M India Ltd." 15784 518 3 2003  .023841137  .015823  .00025036
1 "3M India Ltd." 15783 518 3 2003 -.019766705  .006066   .0000368
1 "3M India Ltd." 15781 518 3 2003           . -.007097   .0000504
1 "3M India Ltd." 15777 518 3 2003           . -.001023   1.05e-06
1 "3M India Ltd." 15776 518 3 2003  -.00558522 -.009575   .0000917
1 "3M India Ltd." 15775 518 3 2003  -.01541847  .005431   .0000295
1 "3M India Ltd." 15774 518 3 2003  .007541014 -.009745    .000095
1 "3M India Ltd." 15771 518 3 2003  -.03000204 -.014516 .000210729
1 "3M India Ltd." 15770 518 3 2003   .02274947 -.011087 .000122929
1 "3M India Ltd." 15769 518 3 2003 -.013333968 -.005572   .0000311
1 "3M India Ltd." 15768 518 3 2003   .02991119 -.011461 .000131357
1 "3M India Ltd." 15767 518 3 2003  -.06965129  .000489   2.39e-07
1 "3M India Ltd." 15764 517 2 2003 -.004470147  .001888   3.56e-06
1 "3M India Ltd." 15763 517 2 2003   -.0729779  .008887    .000079
1 "3M India Ltd." 15762 517 2 2003 -.004800923 -.006453   .0000416
1 "3M India Ltd." 15761 517 2 2003  .002670975 -.011124 .000123735
1 "3M India Ltd." 15760 517 2 2003 -.010527073   .00276   7.62e-06
1 "3M India Ltd." 15757 517 2 2003  .012343297  .000805   6.48e-07
1 "3M India Ltd." 15756 517 2 2003 -.000156703 -.000028   7.77e-10
1 "3M India Ltd." 15755 517 2 2003  .006554706  .005188   .0000269
1 "3M India Ltd." 15754 517 2 2003  .023021424  .002122   4.50e-06
1 "3M India Ltd." 15753 517 2 2003  .003809609  .021327  .00045486
1 "3M India Ltd." 15750 517 2 2003 -.023386864 -.009117   .0000831
1 "3M India Ltd." 15748 517 2 2003   .00662512  -.00495   .0000245
1 "3M India Ltd." 15747 517 2 2003   .00925954 -.000978   9.56e-07
1 "3M India Ltd." 15746 517 2 2003  -.01114852 -.008573   .0000735
1 "3M India Ltd." 15743 517 2 2003  .006835646 -.006041   .0000365
1 "3M India Ltd." 15742 517 2 2003  -.00540445  .011588 .000134277
1 "3M India Ltd." 15741 517 2 2003 -.007051407 -.004897    .000024
1 "3M India Ltd." 15740 517 2 2003  .008163984  .000116   1.34e-08
end
format %td date
format %tm mdate
.