Announcement

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

  • #16
    That's not a precise criterion so far as I can see. Suppose market growth has always been positive. Do you want the calculation to be based on the last 4, 5, 6, ... years?

    Comment


    • #17
      I would want the calculation to be based on all previous years, and it should show me a 1 for consecutive runs of positive values, if there have been more than 3 positive years. So if growth has always been positive, I'd have a 1 for each year starting in year 4. Is this something I can do using tsegen and rall?

      Comment


      • #18
        The criterion still looks ambiguous to me. What do you want if there have been 4 years of previous positive growth but not 5?

        What you can do is calculate the minimum over the last # years of growth. If that minimum is positive, then all growth in that interval was positive.

        Here's a sandbox example;

        Code:
        webuse grunfeld
        gen growth = D.invest
        tsegen min_4_prev_growth = rowmin(L(0/3).growth)
        You can map that last variable to an (0, 1) indicator if desired.

        Alternatively, identify spells of growth using tsspell (SSC).

        Comment


        • #19
          Dear all,

          As shown below, stake is the percentages of firm i investment. pe_id is the id of firms.
          How can I calculate the rolling window of stake during an one-year or two-year rolling window?

          Please kindly note that there some “gap”s in "stake".
          Thank you.
          investmentdate stake industry_id pe_id year
          1995-8 0 49 944 1995
          1995-1-1 0 67 1543 1995
          1995-9 8.4 89 1541 1995
          1995-10-1 0 181 1543 1995
          1995-10-19 30 187 1040 1995
          1995-6 0 198 1444 1995
          1995-6 0 198 1339 1995
          1996-1-18 0 25 1543 1996
          1996-10 0 102 1444 1996
          1996 18.9 148 1490 1996
          1996-9-1 36.7 153 1543 1996
          1996-12 0 187 1040 1996
          1997 0 93 1541 1997
          Last edited by Zhang Hui; 08 Apr 2018, 21:13.

          Comment


          • #20
            What does rolling window of stake mean? Do you mean the mean of stake over a rolling window? Or the standard deviation? Or some other statistic? And do you want this to be done separately by industry? Or by pe_id? Or just overall? Your question is completely unclear.

            Also, with 24 posts under your belt, it surprises me that you have not already been introduced to the -dataex- command for showing example data. In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it 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


            • #21
              Does this work also to compute 10-year centered rolling standard deviations? I have a panel with t=year and id=firm. Suppose I wanna compute the standard deviation of a firm-level variable x over a 10 year rolling window, centered. I cannot use mvsumm (with or without end option), so can I use tsegen? More specifically, suppose I wanna assign to each t, the standard deviation of the window {t-4,t-3,..,t+5}. I tried the following

              HTML Code:
                tsegen x_sd_10 = rowsd(L(1/4).x F(1/5).x), by(id)
              but it doesn't work as expected

              Comment


              • #22
                By specifying L(1/4).x F(1/5.x) you leave out x itself, which is probably why you didn't get what you expected. You can fix that with L(0/4).xF(1/5.x), which will then include x. (L0.x is just x itself.)

                Alternatively, you can do this with -rangestat-, by Robert Picard, Roberto Ferrer, and Nick Cox, or with -asrol-, by Attaullah Shah. Both are available from SSC. -rangestat- is a more general program from a math/stats perspective, whereas -asrol- is more tailored specifically to the kind of problems that come up frequently in finance and economics.

                Added: The code for this using -rangestat- would be
                Code:
                rangestat (sd) x_sd_10 = x, by(id) interval(time -4 5)
                where you replace time with the actual name of your time variable.
                Last edited by Clyde Schechter; 11 Feb 2019, 14:57.

                Comment


                • #23
                  Dear Clyde, thank you very much for your suggestion, it fixed the problem! Following up on your comment about rangestat, are these two codes equivalent?

                  Code:
                  tsegen `x'_sd10 = rowsd(L(0/4).`x' F(1/5).`x', 10)
                  rangestat (sd) `x'_sd_10_bis = `x', by(id) interval(t -4 5)
                  where x is the name of the variable and t is the time variable (year). In particular I would like to compute the rolling standard deviation only on companies that have at least 10 years of data (i.e. the window has to contain 10 non-missing values).

                  Comment


                  • #24
                    Just add (count) to the statistics calculated by rangestat and (if you must) drop what you don't want.

                    (I don't get these little rules: 10 values means that the SD is worthwhile, but 9 means it is useless?)

                    Comment

                    Working...
                    X