Announcement

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

  • #16
    Code:
    rangestat (sd) ROA, by(gvkey) interval(fyear -2 0)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC

    Note that I have interpreted "the last three years" to mean the current year and the two preceding. If you mean the three preceding years (and exclude the current) change the interval() option to -interval(fyear -3 -1)-.

    This question is unrelated to the original topic of the thread, except insofar as both pertain to the same person and the same project. It is easy to think that the Forum threads are dialogs between a questioner and a responder. But they are not. They are also searched by other Forum members who have similar problems and seek answers. When a thread contains off-topic material, those who seek the original topic have their time wasted. And those who seek information about the off-topic material will not find it in their searches. So for the good of the community Statalist serves, it is important to keep threads on topic. In the future, if you have an unrelated question (even if it is about the same project) please start a new thread with it.

    Comment


    • #17
      Thank you so much for your endless support.

      Regarding the tenure code, is there a way that counts the tenure for each year by its self gradually.

      For example, the first year tenure is 1, the second year tenure is 2, etc?

      Thanks a lot again,

      Comment


      • #18
        Yes, change the last line of code in #13 to:
        Code:
         
        by gvkey spell_num (fyear), sort: gen tenure = _n

        Comment


        • #19
          Thank you very much.

          When I ran first line of code in #13, I got the following message:

          "by gvkey (fyear), sort: assert fyear == fyear[_n-1] + 1 if _n > 1
          40 contradictions in 11,187 observations"


          What does that mean?


          Thank you very much again,

          Comment


          • #20
            You have gaps. The assertion is that, when sensibly sorted,

            within panels each observation has a value of fyear 1 more than in the previous observation (except for the first observation).

            The assertion is incorrect in some cases. So you have gaps.

            Comment


            • #21
              Thank you very much.

              Comment


              • #22
                Originally posted by Clyde Schechter View Post
                Code:
                rangestat (sd) ROA, by(gvkey) interval(fyear -2 0)
                -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC

                Note that I have interpreted "the last three years" to mean the current year and the two preceding. If you mean the three preceding years (and exclude the current) change the interval() option to -interval(fyear -3 -1)-.

                This question is unrelated to the original topic of the thread, except insofar as both pertain to the same person and the same project. It is easy to think that the Forum threads are dialogs between a questioner and a responder. But they are not. They are also searched by other Forum members who have similar problems and seek answers. When a thread contains off-topic material, those who seek the original topic have their time wasted. And those who seek information about the off-topic material will not find it in their searches. So for the good of the community Statalist serves, it is important to keep threads on topic. In the future, if you have an unrelated question (even if it is about the same project) please start a new thread with it.
                Sorry about that, but since I have already asked this question here and next time I will create a new thread. I have a follow up question, when I ran the following syntax I notice that the new variable leave sometimes only two years gap where I want three previous years:

                Code:
                rangestat(sd) ROA, by(gvkey) interval(fyear -3 -1)

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str6 gvkey double fyear float ROA double ROA_sd
                "001000" 1974   .07142529                    .
                "001000" 1975    .0890865                    .
                "001000" 1976   .14365195   .01248836936322503
                "001000" 1977   .04996631  .037651905355892266
                "001001" 1983           .                    .
                "001001" 1984   .08082386                    .
                "001001" 1985    .1583574                    .
                "001003" 1982           .                    .
                "001003" 1983   .18643466                    .
                "001003" 1984    .0453746                    .
                "001003" 1985    .0286373   .09974452095163926
                "001003" 1986   .05668335   .08667764174503585
                "001003" 1987 -.035993416  .014110313074199257
                "001003" 1988  -.48859245    .0475266461338694
                "001003" 1989   -.1568796    .2917649036799396
                "001004" 1974   .05908055                    .
                "001004" 1975   .04290361                    .
                "001004" 1976   .04136521  .011438825907428715
                "001004" 1977    .0442371  .009814049117672573
                "001004" 1978   .05318396 .0014371643822420068
                "001004" 1979   .05796492  .006164100130646461
                "001004" 1980   .04888961  .006968460565287137
                "001004" 1981  .014745712 .0045398269782846905
                "001004" 1982    .0245924  .022789130009985784
                "001004" 1983   .04031881  .017574211898306196
                "001004" 1984   .06610167  .012898713272432251
                "001004" 1985    .0740388   .02095668292433658
                "001004" 1986   .07746851  .017629480790678942
                "001004" 1987   .09031822  .005830468082745331
                "001004" 1988   .08708256  .008581929898642857
                "001004" 1989   .07198554  .006683489591340846
                "001004" 1990   .03809575   .00978499127185178
                "001004" 1991  .026371336   .02508699729031512
                "001004" 1992 .0007158196  .023687674997905795
                "001004" 1993  .025972817  .019117735872621167
                "001004" 1994  .025053516  .014698527373359834
                "001004" 1995   .03760327  .014324131764558275
                "001004" 1996   .05258698  .006995344485357015
                "001004" 1997   .06733021  .013784650417353302
                "001004" 1998   .06214367  .014863630815136692
                "001004" 1999   .04839189  .007478785767790555
                "001004" 2000  .025008164  .009786655330673294
                "001004" 2001  -.08397616  .018774788433477133
                "001004" 2002 -.017473977   .07064663323858389
                "001004" 2003  .005103252   .05493155525733467
                "001004" 2004  .026183857   .04630948858962507
                "001004" 2005    .0480218  .021833191894491535
                "001004" 2006    .0607334  .021460385991466834
                "001004" 2007   .07094666   .01747451053971266
                "001004" 2008   .05917725  .011485099697442313
                "001004" 2009  .032397565  .006393377056347066
                "001004" 2010   .04872549  .019755604999565125
                "001004" 2011   .03974991  .013496861625050555
                "001004" 2012  .025049495  .008177397200605938
                "001004" 2013   .03411484  .011952794431091658
                "001004" 2014  -.02477836  .007416612469198328
                "001004" 2015  .026732674   .03171068294275927
                "001004" 2016  .034810346  .032083983216941676
                "001004" 2017    .0489994  .032325039123497115
                "001005" 1974           .                    .
                "001005" 1975   .08962985                    .
                "001005" 1976   .09095172                    .
                "001005" 1977   .06142402 .0009347011961382247
                "001005" 1978   .04109024  .016679336392849076
                "001005" 1979  .063093245   .02507161526010638
                "001005" 1980   .10009728  .012250043888086275
                "001005" 1981   .09642673   .02981963310223779
                "001006" 1974           .                    .
                "001006" 1975  .001901864                    .
                "001006" 1976   .11314879                    .
                "001006" 1977   .12686816   .07866345313472421
                "001006" 1978  .030352304   .06853305007931507
                "001006" 1979  -.11266832   .05221556106650735
                "001006" 1980   -.2410489   .12051827941056147
                "001006" 1981   .04044944    .1357664043436755
                "001006" 1982 .0032928064   .14093021422750485
                "001007" 1974           .                    .
                "001007" 1975  .002716256                    .
                "001007" 1976  -.05278198                    .
                "001007" 1977  -.04134367    .0392431792490452
                "001007" 1978 .0036381676   .02930348747443685
                "001007" 1979   -.0110595   .02982569865027531
                "001007" 1980  .002647604  .022936572490067204
                "001007" 1981  -.14349215  .008214695799282565
                "001007" 1982   .02333523   .08070844398803681
                "001007" 1983    -.213861   .09093603899523106
                "001007" 1984    -.156769   .12182309233929339
                "001008" 1983           .                    .
                "001008" 1984   -.3525974                    .
                "001008" 1985   -.8160329                    .
                "001009" 1981           .                    .
                "001009" 1982  -.20010307                    .
                "001009" 1983   .04811398                    .
                "001009" 1984    .1658416   .17551596188548657
                "001009" 1985   .19551244   .18680961037542615
                "001009" 1986    .1619111   .07795987782581934
                "001009" 1987   .05988701  .018370539235088558
                "001009" 1988   .07299355   .07063075698919502
                "001009" 1989   .08121108  .055508291589188734
                "001009" 1990    .0548507  .010755041377221778
                end
                format %ty fyear

                Comment


                • #23
                  Well, for example in observation 3 of your data set (gvkey 0010000 fyear 1976) there are only 2 years worth of data among the preceding 3 years, so it calculates the sd based on those 2. The same occurs in observation 11 (gvkey 001003 fyear = 1985), this time because of a missing value in ROA.

                  -rangestat- calculates the statistic based upon all observations that meet the conditions specified with -by()- and -interval()-. If you only want to keep the results when all three previous years are actually included, you can do it this way:

                  Code:
                  rangestat(sd) ROA (count) ROA, by(gvkey) interval(fyear -3 -1)
                  replace ROA_sd = . if ROA_count < 3

                  Comment

                  Working...
                  X