for a paper at university i need to calculate the annualized standard deviation of daily returns. Here is an example of my dataset.
For every company and every year i need to have one standard deviation in the end. I used this code but i am not sure if this i correct as i get one value per year but it is written in the cell for every day of the respective year.
Code:
bysort company_code year: egen sd = sd(r_s_)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(date company_code) float r_s_ int year float sd 15582 1 .002399484 2002 .01745268 15446 1 .0232559 2002 .01745268 15488 1 -.009186814 2002 .01745268 15349 1 -.003483082 2002 .01745268 15564 1 -.004130152 2002 .01745268 15629 1 -.015606005 2002 .01745268 15369 1 -.017244903 2002 .01745268 15546 1 .001918968 2002 .01745268 15540 1 -.06892748 2002 .01745268 15449 1 .009737544 2002 .01745268 15348 1 -.005637663 2002 .01745268 15565 1 -.013059427 2002 .01745268 15558 1 .03874377 2002 .01745268 15621 1 .02572878 2002 .01745268 15370 1 .01116412 2002 .01745268 15533 1 -.004375924 2002 .01745268 15631 1 .0018404057 2002 .01745268 15411 1 .006621597 2002 .01745268 15662 1 -.01556447 2002 .01745268 15392 1 -.009436125 2002 .01745268 15587 1 .005150879 2002 .01745268 15400 1 .020069323 2002 .01745268 15594 1 -.010358914 2002 .01745268 15431 1 .0021702978 2002 .01745268 15455 1 .011486853 2002 .01745268 15468 1 .015092998 2002 .01745268 15433 1 -.018251505 2002 .01745268 15652 1 -.002409909 2002 .01745268 15537 1 -.02547316 2002 .01745268 15593 1 .009069891 2002 .01745268 15614 1 .05579595 2002 .01745268 15384 1 .014257977 2002 .01745268 15376 1 -.007514463 2002 .01745268 15693 1 -.0046421625 2002 .01745268 15368 1 -.006221036 2002 .01745268 15398 1 -.002517924 2002 .01745268 15459 1 -.014249854 2002 .01745268 15393 1 .025527457 2002 .01745268 15480 1 -.014173967 2002 .01745268 15544 1 .02500148 2002 .01745268 15379 1 .015405613 2002 .01745268 15553 1 -.02984902 2002 .01745268 15526 1 .02945707 2002 .01745268 15497 1 -.017487248 2002 .01745268 15679 1 -.016542573 2002 .01745268 15669 1 -.008354846 2002 .01745268 15648 1 .0019549874 2002 .01745268 15453 1 -.005857047 2002 .01745268 15586 1 -.04016614 2002 .01745268 15439 1 .010381272 2002 .01745268 15424 1 -.005940103 2002 .01745268 15622 1 -.01282654 2002 .01745268 15490 1 .0007979155 2002 .01745268 15571 1 .02125892 2002 .01745268 15651 1 -.014594428 2002 .01745268 15357 1 .010093715 2002 .01745268 15552 1 .0027046995 2002 .01745268 15664 1 .010177162 2002 .01745268 15454 1 .0097719 2002 .01745268 15383 1 .001401126 2002 .01745268 15489 1 -.014136853 2002 .01745268 15670 1 -.025590213 2002 .01745268 15692 1 -.005281798 2002 .01745268 15438 1 .01384445 2002 .01745268 15377 1 .009253282 2002 .01745268 15684 1 .008428827 2002 .01745268 15421 1 -.01628147 2002 .01745268 15483 1 .007422936 2002 .01745268 15701 1 -.01545622 2002 .01745268 15502 1 -.004135068 2002 .01745268 15656 1 .01140944 2002 .01745268 15511 1 -.007386164 2002 .01745268 15386 1 -.011878805 2002 .01745268 15658 1 .010208822 2002 .01745268 15435 1 .066193506 2002 .01745268 15375 1 -.03385313 2002 .01745268 15432 1 -.002347395 2002 .01745268 15607 1 -.03781525 2002 .01745268 15515 1 .0009676528 2002 .01745268 15403 1 .02210995 2002 .01745268 15445 1 -.00549482 2002 .01745268 15575 1 -.007491405 2002 .01745268 15505 1 .0019871185 2002 .01745268 15538 1 .013368674 2002 .01745268 15524 1 .002618329 2002 .01745268 15343 1 -.0033331455 2002 .01745268 15608 1 .0015075208 2002 .01745268 15685 1 -.003127726 2002 .01745268 15413 1 .009076586 2002 .01745268 15475 1 -.003779376 2002 .01745268 15418 1 -.0041044606 2002 .01745268 15666 1 -.009589176 2002 .01745268 15501 1 .012456857 2002 .01745268 15613 1 -.023192476 2002 .01745268 15477 1 .005089684 2002 .01745268 15397 1 -.009599154 2002 .01745268 15466 1 -.02213284 2002 .01745268 15595 1 -.012754117 2002 .01745268 15680 1 .0015870344 2002 .01745268 15414 1 .006694098 2002 .01745268 end format %tdnn/dd/CCYY date
Best Wishes, Patrick
0 Response to Yearly standard deviation of daily returns
Post a Comment