Announcement

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

  • Rolling sd over same quarters

    Dear all, I would really appreciate your help over the following issue that I've been struggling with:

    I have the following dataset - please, see at the end - and I have to compute the standard deviation of earnings for the previous five years of the same quarter as the observation with a minimum of 3 observations.
    For example, for AAA EPS of 2022Q1 I have to compute the sd of EPS of 2021Q1, 2020Q1,2019Q1,2018Q1,2017Q1.

    Thank you,
    Julia

    ****
    Code:
    input str6 ibtic float(fyear qrt EPS)    
    "AAA" 2020 1    0
    "AAA" 2021 1 -.06
    "AAA" 2022 1  .01
    "AAA" 2023 1 -.05
    "AAA" 2024 1 -.18
    "AAA" 2025 1  .33
    "BBB" 2020 2 -.08
    "BBB" 2021 2  .13
    "BBB" 2022 2  -.1
    "BBB" 2023 2 -.01
    end

  • #2
    I guess your earnings variable is the one called EPS.
    Code:
    rangestat (count) nobs = EPS (sd) wanted = EPS, by(ibtic qrt) interval(fyear -5 -1)
    replace wanted = . if nobs < 3
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Comment


    • #3
      Thank you so much Clyde Schechter ! It worked so smoothly.

      Comment

      Working...
      X