Announcement

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

  • getting top 10% as a dummy variable

    My apologies for very basic question.

    I want to sort by year and create a dummy variable that will take a value of 1 if the value of the variable is in top 10% in that year and zero otherwise.

    Many thanks for your help.







  • #2
    You can use egen to get the 90th percentile by year.

    Comment


    • #3
      Umair, here's an example detailing Nick advice.

      Code:
      sysuse auto.dta,clear
      
      bysort foreign : egen pc90_price=pctile(price) ,p(90)
      gen top10=(price>pc90_price)
      
      bysort foreign : tab top10
      drop pc90_pric
      To adapt this example to your issue, simply replace foreign by year and price by the variable you want to sort. top10 is your dummy variable.

      Comment


      • #4
        Thanks Nick and Charlie for the quick Response.
        Many thanks Charlie for the code.

        Comment


        • #5
          In practice you need to watch out for missings too.


          Code:
          gen top10=(price > pc90_price) if price <  .

          Comment


          • #6
            Thanks Nick.

            Comment

            Working...
            X