Hello,
I have the following dataset:
I would like to classify my variable "animals" in percentiles. I mean, I want to do 10 intervals, being the first one the lower (the first 10% of observations according to the value of variable animals) and the last one the biggest (the 10% biggest values of variable animals). After that, I would like to compute the mean of Age within each percentile. For example, I want to know the mean of Age of the first 10% of observations (it should be percentile one).
I am trying to do the first step (classify the variable animals in perceltiles) with the following code:
However, it does not work, it just give me the value of the first 10 observations. Anyone can help me with my problem? Thank you!
I have the following dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long gid float animals double Age 62356 0 0 62357 0 0 79599 0 .1778533116282972 79600 0 .17785357331615614 79601 0 .1778536186029953 80317 0 .15909446787289028 80318 1 .17610458395941464 80319 0 .1778535061320099 80320 0 .1778534511499288 80321 0 .17785336784015726 80322 0 .17785364358528 80323 0 .17785352006697508 80324 0 .17785340046719966 80325 0 .1778538689661957 80326 0 .17785426020441264 80327 0 .17785365978238588 80328 0 .17785336676075758 80329 0 .17785305873016455 80330 0 .17785384947953276 80331 0 0 80332 0 0 81037 3 .14923540560909032 81038 2 .1654487674794609 81039 0 .17785390171007975 81040 0 .17785403231246733 81041 0 .17785384652552239 81042 0 .17785314257483265 81043 0 .17785357228453336 81044 0 .17785338302178388 81045 0 .17785369357522995 81046 0 .17785348120435174 81047 0 .17785344378697232 81048 0 .1778532409188358 81049 0 .17785387566598843 81050 0 .18247074342281167 81051 0 .011753128763974531 81052 1 0 81053 0 0 81054 0 0 81055 0 0 81756 0 .1778543271591957 81757 0 .17785356209429892 81758 0 .17785367363626392 81759 0 .17785313465776653 81760 0 .1778536476339525 81761 0 .17785362234644708 81762 0 .1778533081250373 81763 0 .17785398037716504 81764 0 .17785360667215855 81765 0 .17785288419261747 81766 0 .17785301989732716 81767 0 .1778528778077373 81768 0 .1778540126846906 81769 0 .17785418244653783 81770 0 .2192007436492247 81771 0 .020631879957504234 81772 0 0 81773 0 0 81774 0 0 81775 0 5.9604641222676946e-08 81776 0 5.9604641222676946e-08 82476 0 .17785365924672192 82477 0 .1778531219408137 82478 0 .17785362497488677 82479 0 .17785388698396787 82480 0 .1778532557042638 82481 0 .17785362581781783 82482 0 .17785249066568554 82483 0 .17785345179188994 82484 0 .17785268525491915 82485 0 .1778538015765605 82486 0 .1778537318877227 82487 0 .17785374539445797 82488 0 .17785365189578783 82489 0 .17785358452277933 82490 0 .1778539981315248 82491 0 .24774813358560266 82492 0 0 82493 0 0 82494 0 0 82495 0 0 82496 0 0 82497 0 0 82498 0 0 83197 0 .17785403006737965 83198 0 .1778535550090794 83199 0 .17785366138360814 83200 0 .17785345138392472 83201 0 .1778537523648822 83202 0 .17785178819127623 83203 0 .17785300154017136 83204 0 .17785340918089787 83205 0 .17785373389469328 83206 0 .17785342168173202 83207 0 .17785335422018989 83208 0 .1778531530811449 83209 0 .17785333043048013 83210 0 .17936670467301497 83211 0 .06361043014024137 83212 0 0 end
I would like to classify my variable "animals" in percentiles. I mean, I want to do 10 intervals, being the first one the lower (the first 10% of observations according to the value of variable animals) and the last one the biggest (the 10% biggest values of variable animals). After that, I would like to compute the mean of Age within each percentile. For example, I want to know the mean of Age of the first 10% of observations (it should be percentile one).
I am trying to do the first step (classify the variable animals in perceltiles) with the following code:
Code:
pctile animals_pct = animals, nq(10) genp(percent)
Comment