Announcement

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

  • Monthly standard deviation in time series dataset

    Hello

    I am trying to find the standard deviation (i.e. volatility) of the monthly stock market returns.
    Below is my data where date2 is basically date in %tm format - I dont know why it's not displaying it here properly but 336 = 1988m1, 337=1988m2, 338 = 1988m3 ... etc.
    lsp is the log of the s&p 500 index
    lret is the returns calculated from lsp by:
    Code:
     gen lret = D.lsp
    I have declared the data to be time series by
    Code:
    tsset date2
    Whenever I enter the code
    Code:
    egen monsd= sd(lret), by(date2)
    I get basically no values and the entire comes up as "348 missing values generated". What am I doing wrong here?

    I was replicating someone else's code who converted the daily returns to monthly and then calculated the volatility by the same codes and this problem does not seem to be coming up there.

    Thank you!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double date2 float(lsp lret)
    336 5.508376           .
    337 5.585299   .07692337
    338 5.602045  .016746044
    339 5.570784 -.031260967
    340 5.539615  -.03116894
    341 5.633396   .09378052
    342  5.59326  -.04013538
    343 5.573294 -.019966125
    344 5.624053   .05075932
    345 5.676309   .05225515
    346 5.627945  -.04836369
    347 5.663551  .035605907
    348 5.688466   .02491474
    349 5.719295   .03082943
    350 5.710824 -.008470535
    351 5.781792  .070967674
    352  5.81434  .032547474
    353 5.846554   .03221464
    354 5.872231   .02567625
    355  5.90206  .029829025
    end
    format %tm date2

  • #2
    Your command
    Code:
    egen monsd= sd(lret), by(date2)
    instructs Stata to calculate the standard deviation of lret for each group of observations with the same value of date2. But your data have only 1 observation for each distinct value of date2, and there is no such thing as the standard deviation of a single number.

    I suspect that the work you are replicating first calucated the volatility by month using the daily observations and second reduced the daily observations to a single monthly observation.

    Comment

    Working...
    X