Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to calculate Sigma (standard deviation of weekly stock return)

    Hello all Statalist members.
    I would like to calculate SIGMA (denotes standard deviation of weekly stock returns in year T) i mean base on weekly stock return data, when i am using weekly dates then i get missing values, but when i am using year date command then i am getting weekReturnVolatility_yearlynwe values.Therefore i need some suggestions how can i get sigma variable from the following data.
    Code:
    by code week_start year , sort : egen float weekReturn1_sd= sd(wretwd)


    Code:
    by code year, sort : egen float weekReturnVolatility_yearlynwe= sd(wretwd)


    also one friend of mine recommended me this command

    weekReturn1_sd is missing value in below data,
    as well as weekReturnVolatility_yearlynwe is sigma i.e .0355006 for 2002-01
    Code:
     by code week_start: gen sigma = sd(wretwd) 
    but it give me this message "not sorted" error
    Code:
    code    trdwnt    wretwd    week_start    week_end    count    weekReturn1_sd    weekReturnVolatility_yearlynwe
    2    2002-01    -.026966    31dec2001    04jan2002    50        .0355006
    2    2002-02    -.052348    07jan2002    11jan2002    50        .0355006
    2    2002-03    -.083672    14jan2002    18jan2002    50        .0355006
    2    2002-04    .06383    21jan2002    25jan2002    50        .0355006
    2    2002-05    .040833    28jan2002    01feb2002    50        .0355006
    2    2002-06    .000801    04feb2002    08feb2002    50        .0355006
    2    2002-09    -.0024    25feb2002    01mar2002    50        .0355006
    2    2002-10    .074579    04mar2002    08mar2002    50        .0355006
    2    2002-11    -.029104    11mar2002    15mar2002    50        .0355006
    2    2002-12    .008455    18mar2002    22mar2002    50        .0355006
    2    2002-13    -.033537    25mar2002    29mar2002    50        .0355006
    2    2002-14    -.001577    01apr2002    05apr2002    50        .0355006
    2    2002-15    .004739    08apr2002    12apr2002    50        .0355006
    2    2002-16    -.019654    15apr2002    19apr2002    50        .0355006
    2    2002-17    -.011227    22apr2002    26apr2002    50        .0355006
    2    2002-18    .007299    29apr2002    03may2002    50        .0355006
    2    2002-19    -.022544    06may2002    10may2002    50        .0355006
    2    2002-20    -.054366    13may2002    17may2002    50        .0355006
    2    2002-21    .029617    20may2002    24may2002    50        .0355006
    2    2002-22    -.043993    27may2002    31may2002    50        .0355006
    2    2002-23    .010619    03jun2002    07jun2002    50        .0355006
    2    2002-24    .000876    10jun2002    14jun2002    50        .0355006
    2    2002-25    .04112    17jun2002    21jun2002    50        .0355006
    2    2002-26    .110084    24jun2002    28jun2002    50        .0355006
    2    2002-27    -.028766    01jul2002    05jul2002    50        .0355006
    2    2002-28    -.018706    08jul2002    12jul2002    50        .0355006
    2    2002-29    .010504    15jul2002    19jul2002    50        .0355006
    2    2002-30    -.040735    22jul2002    26jul2002    50        .0355006
    2    2002-31    .009992    29jul2002    02aug2002    50        .0355006
    2    2002-32    -.018961    05aug2002    09aug2002    50        .0355006
    2    2002-33    -.009244    12aug2002    16aug2002    50        .0355006
    2    2002-34    .029686    19aug2002    23aug2002    50        .0355006
    2    2002-35    -.022241    26aug2002    30aug2002    50        .0355006
    2    2002-36    -.012637    02sep2002    06sep2002    50        .0355006
    2    2002-37    -.011945    09sep2002    13sep2002    50        .0355006
    2    2002-38    -.002591    16sep2002    20sep2002    50        .0355006
    2    2002-39    -.01039    23sep2002    27sep2002    50        .0355006
    2    2002-41    -.028871    07oct2002    11oct2002    50        .0355006
    2    2002-42    0    14oct2002    18oct2002    50        .0355006
    2    2002-43    0    21oct2002    25oct2002    50        .0355006
    2    2002-44    -.004505    28oct2002    01nov2002    50        .0355006
    2    2002-45    .017195    04nov2002    08nov2002    50        .0355006
    2    2002-46    -.102313    11nov2002    15nov2002    50        .0355006
    2    2002-47    .012884    18nov2002    22nov2002    50        .0355006
    2    2002-48    -.008806    25nov2002    29nov2002    50        .0355006
    2    2002-49    -.026654    02dec2002    06dec2002    50        .0355006
    2    2002-50    -.009128    09dec2002    13dec2002    50        .0355006
    2    2002-51    .0174    16dec2002    20dec2002    50        .0355006
    2    2002-52    -.015091    23dec2002    27dec2002    50        .0355006
    2    2002-53    -.0143    30dec2002    03jan2003    50        .0355006
    2    2003-02    .049505    06jan2003    10jan2003    50        .0421453
    2    2003-03    .06499    13jan2003    17jan2003    50        .0421453
    2    2003-04    -.019685    20jan2003    24jan2003    50        .0421453
    2    2003-05    .011044    27jan2003    31jan2003    50        .0421453
    2    2003-07    .018868    10feb2003    14feb2003    50        .0421453
    2    2003-08    -.031189    17feb2003    21feb2003    50        .0421453
    2    2003-09    .039235    24feb2003    28feb2003    50        .0421453
    2    2003-10    .055179    03mar2003    07mar2003    50        .0421453
    2    2003-11    .037615    10mar2003    14mar2003    50        .0421453
    2    2003-12    .009726    17mar2003    21mar2003    50        .0421453
    2    2003-13    .011384    24mar2003    28mar2003    50        .0421453
    2    2003-14    .037229    31mar2003    04apr2003    50        .0421453
    2    2003-15    .065109    07apr2003    11apr2003    50        .0421453
    2    2003-16    .088558    14apr2003    18apr2003    50        .0421453
    2    2003-17    -.12095    21apr2003    25apr2003    50        .0421453
    2    2003-18    .051597    28apr2003    02may2003    50        .0421453
    2    2003-20    .080997    12may2003    16may2003    50        .0421453
    2    2003-21    -.007205    19may2003    23may2003    50        .0421453
    2    2003-22    .050074    26may2003    30may2003    50        .0421453
    2    2003-23    -.049088    02jun2003    06jun2003    50        .0421453
    2    2003-24    .0059    09jun2003    13jun2003    50        .0421453
    2    2003-25    -.060117    16jun2003    20jun2003    50        .0421453
    2    2003-26    -.090484    23jun2003    27jun2003    50        .0421453
    2    2003-27    .02916    30jun2003    04jul2003    50        .0421453
    2    2003-28    .035    07jul2003    11jul2003    50        .0421453
    2    2003-29    .006441    14jul2003    18jul2003    50        .0421453
    2    2003-30    -.0144    21jul2003    25jul2003    50        .0421453
    2    2003-31    .037338    28jul2003    01aug2003    50        .0421453
    2    2003-32    .015649    04aug2003    08aug2003    50        .0421453
    2    2003-33    .001541    11aug2003    15aug2003    50        .0421453
    2    2003-34    .021538    18aug2003    22aug2003    50        .0421453
    2    2003-35    -.027108    25aug2003    29aug2003    50        .0421453
    2    2003-36    -.018576    01sep2003    05sep2003    50        .0421453
    2    2003-37    -.047319    08sep2003    12sep2003    50        .0421453
    2    2003-38    -.038079    15sep2003    19sep2003    50        .0421453
    2    2003-39    .017212    22sep2003    26sep2003    50        .0421453
    2    2003-40    -.00846    29sep2003    03oct2003    50        .0421453
    2    2003-41    .032423    06oct2003    10oct2003    50        .0421453
    2    2003-42    -.024793    13oct2003    17oct2003    50        .0421453
    2    2003-43    .027119    20oct2003    24oct2003    50        .0421453
    2    2003-44    -.019802    27oct2003    31oct2003    50        .0421453
    2    2003-45    .001684    03nov2003    07nov2003    50        .0421453
    2    2003-46    -.023529    10nov2003    14nov2003    50        .0421453
    2    2003-47    .010327    17nov2003    21nov2003    50        .0421453
    2    2003-48    .006814    24nov2003    28nov2003    50        .0421453
    2    2003-49    .018613    01dec2003    05dec2003    50        .0421453
    2    2003-50    .01495    08dec2003    12dec2003    50        .0421453
    2    2003-51    -.018003    15dec2003    19dec2003    50        .0421453
    2    2003-52    .088333    22dec2003    26dec2003    50        .0421453
    2    2003-53    .001531    29dec2003    02jan2004    50        .0421453
    2    2004-02    .049491    05jan2004    09jan2004    50        .0493958
    2    2004-03    .101248    12jan2004    16jan2004    50        .0493958
    2    2004-05    -.011335    26jan2004    30jan2004    50        .0493958
    2    2004-06    .003822    02feb2004    06feb2004    50        .0493958
    2    2004-07    .063452    09feb2004    13feb2004    50        .0493958
    2    2004-08    .004773    16feb2004    20feb2004    50        .0493958
    2    2004-09    -.030879    23feb2004    27feb2004    50        .0493958
    2    2004-10    .002451    01mar2004    05mar2004    50        .0493958
    2    2004-11    .025672    08mar2004    12mar2004    50        .0493958
    2    2004-12    0    15mar2004    19mar2004    50        .0493958
    2    2004-13    .059595    22mar2004    26mar2004    50        .0493958
    2    2004-14    .051744    29mar2004    02apr2004    50        .0493958
    2    2004-15    -.04385    05apr2004    09apr2004    50        .0493958
    2    2004-16    -.008949    12apr2004    16apr2004    50        .0493958
    2    2004-17    -.037246    19apr2004    23apr2004    50        .0493958
    2    2004-18    -.098476    26apr2004    30apr2004    50        .0493958
    2    2004-20    -.011704    10may2004    14may2004    50        .0493958
    2    2004-21    .007895    17may2004    21may2004    50        .0493958
    2    2004-22    -.008367    24may2004    28may2004    50        .0493958
    2    2004-23    -.007952    31may2004    04jun2004    50        .0493958
    2    2004-24    -.02004    07jun2004    11jun2004    50        .0493958
    2    2004-25    -.063395    14jun2004    18jun2004    50        .0493958
    2    2004-26    .021834    21jun2004    25jun2004    50        .0493958
    2    2004-27    .089744    28jun2004    02jul2004    50        .0493958
    2    2004-28    -.003922    05jul2004    09jul2004    50        .0493958
    2    2004-29    .061024    12jul2004    16jul2004    50        .0493958
    2    2004-30    -.040816    19jul2004    23jul2004    50        .0493958
    2    2004-31    .034816    26jul2004    30jul2004    50        .0493958
    2    2004-32    -.009346    02aug2004    06aug2004    50        .0493958
    2    2004-33    .037736    09aug2004    13aug2004    50        .0493958
    2    2004-34    .016364    16aug2004    20aug2004    50        .0493958
    2    2004-35    -.125224    23aug2004    27aug2004    50        .0493958
    2    2004-36    .02045    30aug2004    03sep2004    50        .0493958
    2    2004-37    -.034068    06sep2004    10sep2004    50        .0493958
    2    2004-38    .139004    13sep2004    17sep2004    50        .0493958
    2    2004-39    -.020036    20sep2004    24sep2004    50        .0493958
    2    2004-40    .007435    27sep2004    01oct2004    50        .0493958
    2    2004-41    .02583    04oct2004    08oct2004    50        .0493958
    2    2004-42    .001799    11oct2004    15oct2004    50        .0493958
    2    2004-43    .039497    18oct2004    22oct2004    50        .0493958
    2    2004-44    -.136442    25oct2004    29oct2004    50        .0493958
    2    2004-45    -.006    01nov2004    05nov2004    50        .0493958
    2    2004-46    .036217    08nov2004    12nov2004    50        .0493958
    2    2004-47    0    15nov2004    19nov2004    50        .0493958
    2    2004-48    0    22nov2004    26nov2004    50        .0493958
    2    2004-49    -.013592    29nov2004    03dec2004    50        .0493958
    2    2004-50    -.005906    06dec2004    10dec2004    50        .0493958
    2    2004-51    .005941    13dec2004    17dec2004    50        .0493958
    2    2004-52    -.001969    20dec2004    24dec2004    50        .0493958
    2    2004-53    .037475    27dec2004    31dec2004    50        .0493958
    Please guide me which command in Stata i can use for sigma calculation.

  • #2
    Clyde Schechter Hi, i just want to repost my question, Sorry for that, but i need your guidance ,could you please help me out how to calculate standard deviation of weekly stock return, in year T. regards

    Comment


    • #3
      Originally posted by Ayub UOM View Post
      could you please help me out how to calculate standard deviation of weekly stock return, in year T
      These quantities are given by the variable weekReturn1_sd.
      Code:
      gen year = substr(trdwnt,1,4)
      by code year, sort: egen weekReturn1_sd_copy = sd(wretwd)

      Comment


      • #4
        @ Øyvind Snilsberg Thank you so much for your reply,

        Comment

        Working...
        X