Announcement

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

  • Creating a variable from a percentile

    Dear Statalist Experts

    I hope you are well.
    I want to create a new variable "highVarA" that should contain values of more than 80% of VarA. The remaining value should be "." or missing value.
    I can do that with another way but it will not be exactly what I want.
    I can use
    Code:
    sum VarA, detail
    and copy the value from 75% and use
    Code:
    gen highVarA = .
    replace highVarA = VarA if VarA>= "value"
    But I need 80% values. Can you please help me here. Thank you so much!
    QURESHI, Qazi


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str123 Name float VarA
    "1&1 AG"                           .
    "1&1 AG"                   .03484315
    "1&1 AG"                  -.00774461
    "1&1 AG"                  -.03751598
    "1&1 AG"                 -.005386004
    "1000mercis SA"                    .
    "1000mercis SA"            .02554214
    "1000mercis SA"           .034156952
    "1000mercis SA"           -.12012728
    "1000mercis SA"                    .
    "11 88 0 Solutions AG"             .
    "11 88 0 Solutions AG"      -.089361
    "11 88 0 Solutions AG"    -.24824408
    "11 88 0 Solutions AG"    -.09656604
    "11 88 0 Solutions AG"    -.09121855
    "11 Bit Studios SA"                .
    "11 Bit Studios SA"       -.23336776
    "11 Bit Studios SA"        -.2646595
    "11 Bit Studios SA"      -.030182594
    "11 Bit Studios SA"       -.10646837
    "1Spatial Plc"                     .
    "1Spatial Plc"           -.026000073
    "1Spatial Plc"            -.11950393
    "1Spatial Plc"            -.04920227
    "2020 Bulkers Ltd."                .
    "2020 Bulkers Ltd."                .
    "2020 Bulkers Ltd."        .02202895
    "2020 Bulkers Ltd."       -.05954045
    "24SevenOffice Group AB"   .11744305
    "24SevenOffice Group AB"  -.13923171
    "24SevenOffice Group AB"    .1178121
    "24SevenOffice Group AB"  -.02646791
    "2CRSI SA"                         .
    "2CRSI SA"                  .3476382
    "2CRSI SA"                 .03524129
    "2CRSI SA"                         .
    "2G Energy AG"                     .
    "2G Energy AG"            .024821743
    "2G Energy AG"             .05525199
    "2G Energy AG"           -.007384679
    "2G Energy AG"            -.00717442
    "2cureX AB"                        .
    "2cureX AB"                        .
    "2cureX AB"                        .
    "2cureX AB"                        .
    "2cureX AB"                        .
    "3R Games SA"                      .
    "3R Games SA"                      .
    "3R Games SA"                      .
    "3R Games SA"                      .
    "3R Games SA"                      .
    "3U HOLDING AG"                    .
    "3U HOLDING AG"             .0441386
    "3U HOLDING AG"           .027893513
    "3U HOLDING AG"           .031154595
    "3U HOLDING AG"            .15145305
    "4Energy Invest NV"                .
    "4SC AG"                           .
    "4SC AG"                   .03919098
    "4SC AG"                  .034494758
    "4SC AG"                   .03976049
    "4SC AG"                   .06451345
    "4basebio PLC"                     .
    "4basebio PLC"              .3476382
    "4basebio PLC"                     .
    "4d Pharma PLC"                    .
    "4d Pharma PLC"                    .
    "4d Pharma PLC"                    .
    "4d Pharma PLC"                    .
    "4d Pharma PLC"                    .
    "4iG Nyrt."                        .
    "4iG Nyrt."                .09223145
    "4iG Nyrt."                -.3484537
    "4iG Nyrt."                        .
    "4iG Nyrt."                        .
    "4imprint Group plc"               .
    "4imprint Group plc"      -.08385532
    "4imprint Group plc"      -.09781995
    "4imprint Group plc"      .034352694
    "4imprint Group plc"       .06925553
    "5th Planet Games A/S"             .
    "5th Planet Games A/S"    -.26788998
    "5th Planet Games A/S"      .1985989
    "5th Planet Games A/S"     -.3484537
    "5th Planet Games A/S"             .
    "600 Group PLC"                    .
    "600 Group PLC"            .01464869
    "600 Group PLC"           -.02225583
    "7C Solarparken AG"                .
    "7C Solarparken AG"      -.005819883
    "7C Solarparken AG"       .015129724
    "7C Solarparken AG"       .019077014
    "7C Solarparken AG"       -.02723386
    "7Digital Group PLC"               .
    "7Digital Group PLC"      -.10716356
    "7Digital Group PLC"        .0778405
    "7Digital Group PLC"        .3476382
    "888 Holdings Plc"                 .
    "888 Holdings Plc"        .007568634
    "888 Holdings Plc"        -.11038458
    end

  • #2
    Code:
    h xtile

    Comment


    • #3
      Code:
      help xtile
      points to a good answer -- use _pctile -- note that the answer isn't optimally xtile itself.

      See also centile.

      There is certainly no need to compromise on using the 75% percentile.

      Comment


      • #4
        Try
        Code:
        . sysuse auto
        (1978 automobile data)
        
        . _pctile price, p(80)
        
        . gen highvalue = 1 if price > r(r1)
        (60 missing values generated)

        Comment


        • #5
          Thank you so much! Jared, Nick, Joro
          It worked...
          Warmest regards
          QURESHI, Qazi

          Comment

          Working...
          X