Announcement

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

  • Standard deviation of industry-adjusted return on assets over five years

    Dear STATA experts,

    My sample consists of firm-year observations panel with unbalanced data over the period 2008 to 2016. I would like to measure the standard deviation of the industry-ajusted return on assets known as σ(ROA) for each firm in my sample over five-year overlapping periods (2008-2012 , 2009-2013 ,..., 2012-2016).
    First, I have computed the industry-adjusted return on assets for each year by using the following codes:
    egen average_roa=mean(roa), by(years industry)
    gen adjusted_roa=roa-average_roa

    However, I am very confused regarding the computation of the standard deviation over the five-year overlapping periods. I would really appreciate any help regarding a specific code.
    Many thanks,
    Nour

  • #2
    There are a couple of ways to do this. Here is one:

    Code:
    rangestat (count) adjusted_roa (sd) adjusted_roa, by(firm) interval(year 0 4)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer, and is available from SSC.

    Notes:
    1. Replace firm and year by the actual names of the variables that identify firm and year in your data.
    2. After this code runs, the value of adjusted_roa_sd in an observation will be the standard deviation of that firm's adjusted_roa over the period starting with (and including) the year in that observation as well as the subsequent four years (hence a total of five years).
    3. The variable adjusted_roa_count will tell you how many years actually contributed data to that five-year interval. For example, since your data ends in 2016, any observation in year 2013 will only be able to include 4 years. Any observation in 2015 will only include 2, etc. Moreover, if there are gaps in the years, or missing values for adjusted_roa, there may be other years where the number of actual years in the five year interval is less than 5.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      You can also try asrol for rolling window statistics
      Code:
      ssc install asrol 
       bys firm : asrol adjusted_roa,  stat(count sd ) window(year 5)
      You can read more on asrol here
      https://fintechprofessor.com/stata-p...tics-in-stata/
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        Dear Clyde,
        Thank you for your detailed response. I will make sure to include the dataex next time.

        Comment


        • #5
          Dear Attaullah,
          Thank you for your reply. I will try the code.

          Comment


          • #6
            Hello professors i want to find standard deviations
            (1) in the past three years,so how can i adjust the above commonds, i think it means not including the current year,but just considering t-1,t-2 and t-3.

            (2) and also want to calculate SD from year t-5 to year t-1.

            (3) I have also tried the above codes, but found one thing more in rangestat commond, i think if we replace interval(-4 0) ,with interval(0 4) then both commonds asrol and rangestat give us the same results for the last 5 years window.
            Last edited by Ayub UOM; 04 Nov 2019, 03:19.

            Comment


            • #7
              Clyde Schechter Attaullah Shah Hello professors, could you please reply to my questions.sorry for asking again.thank you
              Last edited by Ayub UOM; 06 Nov 2019, 00:00.

              Comment


              • #8
                If you want to exclude the current observation, you can use the xfocal option, ie exclude focal observation.

                Code:
                webuse grunfeld
                bys company: asrol invest, stat(sd) window(year 4) xf(focal) min(3)
                
                 list company year invest sd4_invest in 1/10
                
                     +-------------------------------------+
                     | company   year   invest   sd4_inv~t |
                     |-------------------------------------|
                  1. |       1   1935    317.6           . |
                  2. |       1   1936    391.8           . |
                  3. |       1   1937    410.6           . |
                  4. |       1   1938    257.7   49.173296 |
                  5. |       1   1939    330.8   83.381305 |
                     |-------------------------------------|
                  6. |       1   1940    461.2   76.474459 |
                  7. |       1   1941      512   103.08574 |
                  8. |       1   1942      448   93.468577 |
                  9. |       1   1943    499.6   33.790726 |
                 10. |       1   1944    547.5   33.941912 |
                     +-------------------------------------+
                Regards
                --------------------------------------------------
                Attaullah Shah, PhD.
                Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                FinTechProfessor.com
                https://asdocx.com
                Check out my asdoc program, which sends outputs to MS Word.
                For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                Comment


                • #9
                  thank you so much sir.

                  Comment

                  Working...
                  X