Announcement

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

  • Trecile calculation

    Hello everyone
    kindly I want to follow a paper regrading the analysis
    the author used trecile method to assign whether the media coverage is high or low. I have the raw data but I don’t know how to calculate the trecile of the media coverage please
    who can help to explain how to calculate the trecile of this variable?
    It is needed

  • #2
    There are a couple ways to do this.

    You could rank the variable using egen rank and then assign the terciles.
    Code:
    * create terciles of price
    sysuse auto // example dataset
    egen pricerank = rank(price) // add ', by(something )' here if you'd like to group by something
    egen pricecount = count(price) // add ', by(something )' here if you'd like to group by something
    generate pricepercent = pricerank/pricecount
    generate tercile = 3 if pricepercent > 2/3
    replace tercile = 2 if pricepercent <= 2/3
    replace tercile = 1 if pricepercent <= 1/3
    Last edited by Arthur Morris; 10 May 2020, 17:45.

    Comment


    • #3
      Another approach is to use the xtile function provided by egenmore:
      Code:
      ssc install egenmore
      sysuse auto
      egen tercile = xtile(price), nquantiles(3)


      After you install the function you can consult the help file for more information.

      Comment


      • #4
        Another approach is to use the xtile command built into Stata.
        Code:
        xtile tercile = price, nquantiles(3)
        Code:
        . sysuse auto
        (1978 Automobile Data)
        
        . egen tercile1 = xtile(price), nquantiles(3)
        
        . xtile tercile2 = price, nquantiles(3)
        
        . assert tercile1==tercile2
        
        .

        Comment


        • #5
          We're taking "trecile" to be a typo for tercile. Another term often met -- my impression is more often -- is tertile.

          For a list of similar terms, with further discussion, see https://www.stata-journal.com/articl...article=st0465 pp.1070-1071 -- and also https://stats.stackexchange.com/ques...half-a-percent for an extra term "trentile".

          Further contributions gratefully received.

          Comment


          • #6
            Originally posted by Arthur Morris View Post
            There are a couple ways to do this.

            You could rank the variable using egen rank and then assign the terciles.
            Code:
            * create terciles of price
            sysuse auto // example dataset
            egen pricerank = rank(price) // add ', by(something )' here if you'd like to group by something
            egen pricecount = count(price) // add ', by(something )' here if you'd like to group by something
            generate pricepercent = pricerank/pricecount
            generate tercile = 3 if pricepercent > 2/3
            replace tercile = 2 if pricepercent <= 2/3
            replace tercile = 1 if pricepercent <= 1/3
            Thank you so much, I got it, but i need to understand the meaning of
            nerate pricepercent = pricerank/pricecount
            generate tercile = 3 if pricepercent > 2/3
            replace tercile = 2 if pricepercent <= 2/3
            replace tercile = 1 if pricepercent <=1/3.
            other words what the meaning of tercile 3?
            because my data is not amount of money it’s just number of times ( May maximum value is 5)
            please explain it to be more clear to me?
            once again thanks

            Comment


            • #7
              Originally posted by Nick Cox View Post
              We're taking "trecile" to be a typo for tercile. Another term often met -- my impression is more often -- is tertile.

              For a list of similar terms, with further discussion, see https://www.stata-journal.com/articl...article=st0465 pp.1070-1071 -- and also https://stats.stackexchange.com/ques...half-a-percent for an extra term "trentile".

              Further contributions gratefully received.
              Gratitude

              Comment


              • #8
                Originally posted by William Lisowski View Post
                Another approach is to use the xtile command built into Stata.
                Code:
                xtile tercile = price, nquantiles(3)
                Code:
                . sysuse auto
                (1978 Automobile Data)
                
                . egen tercile1 = xtile(price), nquantiles(3)
                
                . xtile tercile2 = price, nquantiles(3)
                
                . assert tercile1==tercile2
                
                .
                Thanks a lot
                I will apply it to make sure whether it gives same results
                thanks

                Comment


                • #9
                  Originally posted by William Lisowski View Post
                  Another approach is to use the xtile command built into Stata.
                  Code:
                  xtile tercile = price, nquantiles(3)
                  Code:
                  . sysuse auto
                  (1978 Automobile Data)
                  
                  . egen tercile1 = xtile(price), nquantiles(3)
                  
                  . xtile tercile2 = price, nquantiles(3)
                  
                  . assert tercile1==tercile2
                  
                  .
                  Thanks a lot
                  I will apply it to make sure whether it gives same results
                  thanks

                  Comment


                  • #10
                    Originally posted by Arthur Morris View Post
                    Another approach is to use the xtile function provided by egenmore:
                    Code:
                    ssc install egenmore
                    sysuse auto
                    egen tercile = xtile(price), nquantiles(3)


                    After you install the function you can consult the help file for more information.
                    kindly how can i assign the top trecile ?

                    Comment


                    • #11
                      Originally posted by ALKEBSEE RADWAN View Post

                      kindly how can i assign the top trecile ?
                      As you can see there are a lot of ways to assign quantiles. It's worth carefully reviewing your data (which you could share with us: see #12 of the faq) to ensure that the approach you choose is working as you expect. If you share your attempts to assign this variable, and where you hit a snag you'll get a better answer.

                      The following will create an indicator for prices that are in the third (top) tercile:
                      Code:
                      sysuse auto
                      xtile tercile = price, nquantiles(3)
                      generate top3ile = (tercile==3)
                      You'll need to be the judge of whether this is the correct approach in your data.

                      Comment


                      • #12
                        Originally posted by Arthur Morris View Post

                        As you can see there are a lot of ways to assign quantiles. It's worth carefully reviewing your data (which you could share with us: see #12 of the faq) to ensure that the approach you choose is working as you expect. If you share your attempts to assign this variable, and where you hit a snag you'll get a better answer.

                        The following will create an indicator for prices that are in the third (top) tercile:
                        Code:
                        sysuse auto
                        xtile tercile = price, nquantiles(3)
                        generate top3ile = (tercile==3)
                        You'll need to be the judge of whether this is the correct approach in your data.
                        thanks a lot

                        Comment

                        Working...
                        X