Announcement

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

  • rangestat for sd with multiple intervals

    Hi

    I am working on replicating Amir et al.(2007)
    I would like to create a variable which is the SD of operating income of subsequent years.
    Using the command rangestat, the interval for SD is either one of the below, if there is enough data in year -1,0,1,2,3,4,5 (0 is current year):
    a. fyear -1 3
    b. fyear 1 5
    c. fyear 0 4

    My current code is
    rangestat (sd) OPIN (count) OPIN, interval(fyear -1 3) by(gvk)

    How can I tell stata to search to see if there are enough data for the scenarios a/b/c indicated above, and if there is enough data for a scenario, apply the according interval?
    Each observation can have a different interval (a,b, or c).

    Thank you very much

    SDFOPIN – Standard Deviation of Operating Income per Share over five subsequent years deflated by the beginning of the period stock price. We calculate
    standard deviations using operating income. If data are unavailable for the subsequent five years, we calculate
    the variable using current and subsequent four years. If this variable is still missing, we use lagged, current and subsequent three years of operating income.
    Last edited by Aberdeen Hugh; 29 Dec 2022, 10:55.

  • #2
    It is, in general, difficult to write code without having example data to see and work with. For complicated situations like yours it is more or less impossible. For a helpful response, please post back and use the -dataex- command to show example data. If you are running version 17, 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.

    Also, explain what you want to do if there is sufficient data for two or more of these intervals.

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

    Added: Never mind about the explanation. Re-reading your post I see that the final paragraph states that 1-5 is used if possible, 0-4 as backup if that fails, and -1 to 3 as backup if even that fails.
    Last edited by Clyde Schechter; 29 Dec 2022, 11:00.

    Comment


    • #3
      Clyde Schechter's general advice is naturally excellent. In this case the intervals 1 2 3 4 5, 0 1 2 3 4 and -1 0 1 2 3 are precisely the same intervals seen from different vantages, so the results differ only by lead or lag operators, modulo boundary conditions.

      Code:
      webuse grunfeld, clear
      
      tokenize `" "-1 3" "0 4" "1 5" "'
      
      forval j = 1/3 {
          rangestat (count) c`j'=invest (mean) m`j'=invest, int(year ``j'') by(company)
      }
      
      list year invest c1 m1 c2 m2 c3 m3 if company == 1
           +------------------------------------------------------------------+
           | year   invest   c1          m1   c2          m2   c3          m3 |
           |------------------------------------------------------------------|
        1. | 1935    317.6    4     344.425    5       341.7    5      370.42 |
        2. | 1936    391.8    5       341.7    5      370.42    5      394.46 |
        3. | 1937    410.6    5      370.42    5      394.46    5      401.94 |
        4. | 1938    257.7    5      394.46    5      401.94    5      450.32 |
        5. | 1939    330.8    5      401.94    5      450.32    5      493.66 |
           |------------------------------------------------------------------|
        6. | 1940    461.2    5      450.32    5      493.66    5      513.66 |
        7. | 1941      512    5      493.66    5      513.66    5      548.88 |
        8. | 1942      448    5      513.66    5      548.88    5      573.06 |
        9. | 1943    499.6    5      548.88    5      573.06    5      578.98 |
       10. | 1944    547.5    5      573.06    5      578.98    5       580.5 |
           |------------------------------------------------------------------|
       11. | 1945    561.2    5      578.98    5       580.5    5      596.84 |
       12. | 1946    688.1    5       580.5    5      596.84    5   610.40001 |
       13. | 1947    568.9    5      596.84    5   610.40001    5   674.86001 |
       14. | 1948    529.2    5   610.40001    5   674.86001    5   829.90001 |
       15. | 1949    555.1    5   674.86001    5   829.90001    5     1016.22 |
           |------------------------------------------------------------------|
       16. | 1950    642.9    5   829.90001    5     1016.22    4     1109.55 |
       17. | 1951    755.9    5     1016.22    4     1109.55    3   1227.4333 |
       18. | 1952    891.2    4     1109.55    3   1227.4333    2     1395.55 |
       19. | 1953   1304.4    3   1227.4333    2     1395.55    1      1486.7 |
       20. | 1954   1486.7    2     1395.55    1      1486.7    .           . |
           +------------------------------------------------------------------+
      
      .

      Comment

      Working...
      X