Announcement

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

  • Decile for a group

    Hey everybody,

    I’m really sad because I have a big problem with my master thesis and I don’t know how to handle it.
    Hopefully, you can help me.

    I have a dataset with fund returns over a specific time period. Every fund belongs to a segment.
    Now, I have to calculate the percentiles for the returns for each segment and time point if the fund is bigger than 1 Mio.$.

    As an example:
    Segment 1 and time point 1: I have 26 returns and then I have to create a variable that shows me to which decile every return belongs.

    Later, I have to compare how the funds below or above the median act…

    I found the command:

    bysort segment time: egen perc = pctile(ret) if tna>1000, p(10)

    But I generate just missing observation...


    Best wishes
    Sebastian

  • #2
    That code will at most calculate the 10th percentile of the observations selected. If the if qualifier excludes all observations, it will return missing.

    Consider

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . egen p10 = pctile(mpg), p(10)
    
    . l p10 in 1
    
         +-----+
         | p10 |
         |-----|
      1. |  14 |
         +-----+
    
    . su mpg, detail
    
                            Mileage (mpg)
    -------------------------------------------------------------
          Percentiles      Smallest
     1%           12             12
     5%           14             12
    10%           14             14       Obs                  74
    25%           18             14       Sum of Wgt.          74
    
    50%           20                      Mean            21.2973
                            Largest       Std. Dev.      5.785503
    75%           25             34
    90%           29             35       Variance       33.47205
    95%           34             35       Skewness       .9487176
    99%           41             41       Kurtosis       3.975005
    The 10th percentile (1st decile) is 14 miles per gallon.

    What you want is given by xtile() from egenmore (SSC).

    Comment


    • #3
      Thank you for the advice.

      I friend told me to calcualte percile rankings.

      Like:

      by segment time, sort: egen n=count(rret) if tag==1
      by segment time, sort: egen i=rank(rret)if tag==1, track
      gen dens_perc =(i-1)/(n-1)


      Then I should get the deciles, too.

      Is that right?

      Comment


      • #4
        Those would be more usually called percentile ranks. The method is documented more generally at

        http://www.stata.com/support/faqs/st...ons/index.html

        They could be used to calculate decile groups.

        Comment


        • #5
          Yeah, that seems the calculation I mean.

          The first decile would bei between 0 and 0.1 and so on.
          Right?

          Comment


          • #6
            Correct.

            But watch out: if you do it yourself, you need to take account of missing values.
            Last edited by Nick Cox; 03 Nov 2015, 02:08.

            Comment


            • #7
              I’m really sad because I have a big problem with my master thesis and I don’t know how to handle it.
              Hopefully, you can help me.
              If you still face problems in writing codes for mutual funds performance evaluation or performance persistence or any other aspect, this might be of help to you https://sites.google.com/site/imspes...ata-professors
              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


              • #8
                I have the same problem.

                I tried both methods. The percentile ranks and egen xtile you showed.

                The results are slighly different.

                Which method should I prefer?

                Comment


                • #9
                  Bene:

                  The method used by egen, xtile() from egenmore (SSC) is just based on the use of _pctile and that in turn can be called in different ways.

                  The FAQ mentioned in #4 has as a main theme the idea that percentile rank also can be calculated in several ways and that the researcher gets to choose.

                  I don't think we can choose for you. It's a key point that there are numerous slightly different ways to do this. Those who assess your research may well want to see reproducible code and for your exact rules to be explicit.

                  Comment

                  Working...
                  X