Announcement

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

  • Using xtile to create quartiles for a subsection of data

    Hi all,

    I've been creating quartiles using:
    Code:
    egen quartiles = xtile(mean_RollingGrowthRate), nq(4) by(FiscalYear)
    However, I'm now trying to create quartiles for a subsection of data—I only want to calculate the quartiles when ActiveInSP500=1.

    I tried

    Code:
    egen quartiles = xtile(mean_RollingGrowthRate), nq(4) by(FiscalYear) if ActiveInSP500==1
    But this didn't worked, it came back with "option if not allowed." I was reading through: https://www.stata.com/manuals/dpctile.pdf and it seemed like an if statement should be allowed...but I'm obviously wrong. Does anyone have any advice on how to do this?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 gvkey int FiscalYear double mean_RollingGrowthRate float ActiveInSP500
    "010553" 1982                     . 0
    "010553" 1983     2.507899761199951 0
    "010553" 1984    2.1448938846588135 0
    "010553" 1985    1.5570627748966217 0
    "010553" 1986    1.3490111455321312 0
    "010553" 1987    1.3357315719127656 0
    "010553" 1988    1.2016920795043309 0
    "010553" 1989    1.0423242673277855 0
    "010553" 1990     .9059087978675961 0
    "010553" 1991     .8079946993125809 0
    "010553" 1992     .7783181808888913 0
    "010553" 1993     .5615265659987927 0
    "010553" 1994    .43996640369296075 0
    "010553" 1995    .48148212060332296 0
    "010553" 1996    .44423368498682975 1
    "010553" 1997      .388205736130476 1
    "010553" 1998     .3415462777018547 1
    "010553" 1999    .30801822021603587 1
    "010553" 2000     .2780062802135944 1
    "010553" 2001     .2279306583106518 0
    "010553" 2002      .139927389472723 0
    "010553" 2003    .08084697052836418 0
    "010553" 2004    .01740175038576126 0
    "010553" 2005   -.04020959585905075 0
    "010553" 2006   -.01597650200128555 0
    "010553" 2007   -.08604827057570219 0
    "010553" 2008   -.09083162788301706 0
    "007435" 1980                     . 1
    "007435" 1981    .07047660648822784 1
    "007435" 1982    .04238335555419326 1
    "007435" 1983    .05037343098471562 1
    "007435" 1984    .06143400142900646 1
    "007435" 1985   .052807162143290044 1
    "007435" 1986    .06006510633354386 1
    "007435" 1987    .06521872391125985 1
    "007435" 1988    .07233841682318598 1
    "007435" 1989    .07909672759059402 1
    "007435" 1990    .07978588687255979 1
    "007435" 1991    .07518811477348208 1
    "007435" 1992    .07782956920564174 1
    "007435" 1993     .0721810294315219 1
    "007435" 1994    .07027295287698507 1
    "007435" 1995    .05770618580281735 1
    "007435" 1996   .053835933282971385 1
    "007435" 1997   .050080277398228644 1
    "007435" 1998    .03753750137984753 1
    "007435" 1999    .02846856713294983 1
    "007435" 2000    .02667093575000763 1
    "007435" 2001    .02036431450396776 1
    "007435" 2002   .017867330461740494 1
    "007435" 2003   .028514114581048487 1
    "007435" 2004    .03071818929165602 1
    "007435" 2005    .04723179843276739 1
    "007435" 2006   .049762500636279586 1
    "007435" 2007   .050617894344031814 1
    "007435" 2008   .054242038168013096 1
    "007435" 2009     .0415020314976573 1
    "007435" 2010    .05000593867152929 1
    "007435" 2011    .06492335703223943 1
    "007435" 2012    .06433937335386872 1
    "007435" 2013    .05593945207074284 1
    "007435" 2014    .04925920432433486 1
    "007435" 2015   .038620812352746725 1
    "007435" 2016   .029779857816174628 1
    "007435" 2017   .028207396762445568 1
    "007435" 2018    .02840841789729893 1
    "007435" 2019      .034981305943802 1
    "007435" 2020   .019825563312042504 1
    "009872" 1980                     . 0
    "009872" 1981    .17162653803825378 0
    "009872" 1982      .178788922727108 0
    "009872" 1983    .21497688194115958 0
    "009872" 1984     .2557826153934002 1
    "009872" 1985     .2168377824127674 1
    "009872" 1986    .12421045762797196 1
    "009872" 1987    .09688693231769971 1
    "009872" 1988    .08421359525527805 0
    "009872" 1989    .07995405989802545 0
    "009872" 1990    .07250831234268844 0
    "009872" 1991   .050309775350615385 0
    "009872" 1992   .016749371169134976 0
    "009872" 1993  -.021829484077170492 0
    "009872" 1994   -.06109262001700699 0
    "009872" 1995   -.06618987056426703 0
    "009872" 1996  -.029408413311466576 0
    "009872" 1997  -.021098576625809072 0
    "009872" 1998  -.017086560698226096 0
    "009872" 1999  -.007695059897378087 0
    "009872" 2000   .005639155488461256 0
    "009872" 2001   .014923571702092886 0
    "009872" 2002     .0319661826826632 0
    "009872" 2003     .0667299130000174 0
    "009872" 2004    .08061197856441141 0
    "009625" 1980                     . 0
    "009625" 1981   .007740318309515715 0
    "009625" 1982    .02986318594776094 0
    "009625" 1983   .017598643743743498 0
    "009625" 1984   .012352889985777438 0
    "009625" 1985 -.0021788607351481914 0
    "009625" 1986  -.010833595180884004 0
    end

  • #2
    Code:
     
     egen quartiles = xtile(mean_RollingGrowthRate) if ActiveInSP500==1, nq(4) by(FiscalYear)
    An if qualifier is not an option.

    Comment

    Working...
    X