Announcement

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

  • Computing Standard Deviation of annual returns over three years.

    Hello everyone,

    For my Replication Study, I am replicating a study for which I need the variable 'Return Volatility'. This is measured as the 'standard deviation of monthly stock returns over three years prior to t'. I am new to STATA, and I have no clue how to calculate the standard deviation over 3 preceding years. My data looks like this:

    Cusip Permno Permco Companyname fyear month........date ......vwreturn
    30710 .................................................. 2007 .....1......29/01/2007.......x ..........
    30710 .................................................. 2007 .....2......29/02/2007.......x ..........
    30710 .................................................. 2007..3/4/5 etc......x...............x ..........
    30710 .................................................. 2007 .....12....29/12/2007.......x ..........
    30710 .................................................. 2008 .....1......29/01/2008.......x ..........
    30710 .................................................. 2007 .....2......29/02/2008.......x ..........

    et cetera. I have data from 2007 till 2019, and thousands of unique companies.

    From the monthly returns, I already calculated the annual returns (using by cusip fyear: egen yearendret = total(vwreturn). (Then using collapse function) Then my data looks like this:
    Cusip Permno Permco Companyname fyear yearendret
    30710 .................................................. 2007......x.........
    30710 .................................................. 2008......x .........
    30710 .................................................. 2009......x..........
    30710 .................................................. 2010......x..........
    30710 .................................................. 2011......x ..........


    Now my question is, how do I calculate the SD for this yearendret?
    I already tried: egen sd_yearendret= sd(yearendret), by(cusip fyear)
    However, I only get values of 0.

    In addition, how do I get the standard deviation of the three preceding years all together? Is it even useful to calculate the SD per year, or is there another way to calculate the SD of yearendret three years prior to t?

    Kind regards,
    Laura Banken

  • #2
    If you have groups defining single observations, then there is no variability to summarize. Contrary to your report, the SD based on single observations is returned by egen as missing, not zero, as Stata uses a formula for SD with (sample size MINUS 1) in the denominator.

    Otherwise, good news. This kind of question has arisen dozens of times on Statalist. Dedicated commands that have often been used include rangestat and asrol -- either of which must be installed from SSC before it can be used.

    So that gives you several search terms for finding posts in this forum.

    Comment

    Working...
    X