Hey Community,

for a paper at university I need a three year rolling standard deviation of returns. In the end I need firm year observations, so every firm should have one standard deviation per year.
The paper i use as a reference states the follwoing: "Our primary measure of corporate risk-taking is Volatility -volatility of monthly stock returns constructed over a window of three years" [...] " Our final sample consists of roughly 30.000 firm-year obserations"

With yearly returns I used the following code
Code:
rolling vola = r(sd), window(3) saving(3-Year Return Volatility): summarize annual_log_return
With daily returns I adapted the code with a rolling window of 759 days as there are approximateley 253 trading days per year
Code:
rolling vola = r(sd), window(759) saving(3-Year Return Volatility): summarize annual_log_return
However if I use this code i get one standard deviation per day and not per year. Can somebody help me out?

See an example of my data below
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(date company_code) float r_s_ int year
15582 1   .002399484 2002
15446 1     .0232559 2002
15488 1  -.009186814 2002
15349 1  -.003483082 2002
15564 1  -.004130152 2002
15629 1  -.015606005 2002
15369 1  -.017244903 2002
15546 1   .001918968 2002
15540 1   -.06892748 2002
15449 1   .009737544 2002
15348 1  -.005637663 2002
15565 1  -.013059427 2002
15558 1    .03874377 2002
15621 1    .02572878 2002
15370 1    .01116412 2002
15533 1  -.004375924 2002
15631 1  .0018404057 2002
15411 1   .006621597 2002
15662 1   -.01556447 2002
15392 1  -.009436125 2002
15587 1   .005150879 2002
15400 1   .020069323 2002
15594 1  -.010358914 2002
15431 1  .0021702978 2002
15455 1   .011486853 2002
15468 1   .015092998 2002
15433 1  -.018251505 2002
15652 1  -.002409909 2002
15537 1   -.02547316 2002
15593 1   .009069891 2002
15614 1    .05579595 2002
15384 1   .014257977 2002
15376 1  -.007514463 2002
15693 1 -.0046421625 2002
15368 1  -.006221036 2002
15398 1  -.002517924 2002
15459 1  -.014249854 2002
15393 1   .025527457 2002
15480 1  -.014173967 2002
15544 1    .02500148 2002
15379 1   .015405613 2002
15553 1   -.02984902 2002
15526 1    .02945707 2002
15497 1  -.017487248 2002
15679 1  -.016542573 2002
15669 1  -.008354846 2002
15648 1  .0019549874 2002
15453 1  -.005857047 2002
15586 1   -.04016614 2002
15439 1   .010381272 2002
15424 1  -.005940103 2002
15622 1   -.01282654 2002
15490 1  .0007979155 2002
15571 1    .02125892 2002
15651 1  -.014594428 2002
15357 1   .010093715 2002
15552 1  .0027046995 2002
15664 1   .010177162 2002
15454 1     .0097719 2002
15383 1   .001401126 2002
15489 1  -.014136853 2002
15670 1  -.025590213 2002
15692 1  -.005281798 2002
15438 1    .01384445 2002
15377 1   .009253282 2002
15684 1   .008428827 2002
15421 1   -.01628147 2002
15483 1   .007422936 2002
15701 1   -.01545622 2002
15502 1  -.004135068 2002
15656 1    .01140944 2002
15511 1  -.007386164 2002
15386 1  -.011878805 2002
15658 1   .010208822 2002
15435 1   .066193506 2002
15375 1   -.03385313 2002
15432 1  -.002347395 2002
15607 1   -.03781525 2002
15515 1  .0009676528 2002
15403 1    .02210995 2002
15445 1   -.00549482 2002
15575 1  -.007491405 2002
15505 1  .0019871185 2002
15538 1   .013368674 2002
15524 1   .002618329 2002
15343 1 -.0033331455 2002
15608 1  .0015075208 2002
15685 1  -.003127726 2002
15413 1   .009076586 2002
15475 1  -.003779376 2002
15418 1 -.0041044606 2002
15666 1  -.009589176 2002
15501 1   .012456857 2002
15613 1  -.023192476 2002
15477 1   .005089684 2002
15397 1  -.009599154 2002
15466 1   -.02213284 2002
15595 1  -.012754117 2002
15680 1  .0015870344 2002
15414 1   .006694098 2002
end
format %tdnn/dd/CCYY date