Hi all,

I'm working on the following sample.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 company double year float w0
"001166" 2006   .1516999
"001166" 2007  -.3825382
"001166" 2008    .757847
"001166" 2009   5.233164
"001166" 2010   .2216363
"001166" 2011  -.1965048
"001166" 2012  1.1767141
"001166" 2013  -7.348667
"001166" 2014   .3683232
"001166" 2015   .1177742
"001166" 2016  .10647435
"001166" 2017  2.9807024
"001166" 2018  2.8784115
"001491" 2005  -.2270699
"001491" 2006  1.5631847
"001491" 2007  .56534487
"001491" 2008   .3267759
"001491" 2009  1.2710383
"001491" 2010   .3420811
"001491" 2011  1.0560561
"001491" 2012  -2.627582
"001491" 2013  -3.070902
"001491" 2014 -1.4180528
"001491" 2015  -4.685867
"001491" 2016   .4289067
"001491" 2017   .3946427
"001491" 2018 -.10432901
"001855" 2014  -.3256366
"001855" 2015   .5677433
"001855" 2016  -1.996107
"001855" 2017  -118.5722
"001855" 2018  1.7242726
"001932" 2005   2.619214
"001932" 2006  10.914798
"001932" 2007 -.54683685
"001932" 2008 -.49628335
"001932" 2009  1.0554386
"001932" 2010   .5421757
"001932" 2011  .08755323
"001932" 2012 -.52197087
"001932" 2013  -.1656467
"001932" 2014  .07944288
"001932" 2015   .2046654
"001932" 2016   .9336959
"001932" 2017  -.4836137
"001932" 2018  1.0617268
"001945" 1999   1.550001
"001945" 2000  2.1697288
"001945" 2001    1.96726
"001945" 2002   .6981787
"001945" 2003 -.07846977
"001945" 2004 -.34980935
"001945" 2005  1.2656814
"002162" 2001   .6960053
"002162" 2002  15.773005
"002162" 2003   47.16787
"002162" 2004  16.212912
"002162" 2005 -.52174443
"002162" 2006  -.5445366
"002162" 2007   6.573451
"002162" 2008   -157.362
"002162" 2009  -1.012664
"002162" 2010 -4.5318084
"002162" 2011  -6.198843
"002162" 2012   3.494617
"002162" 2013  -16.98453
"002162" 2014   .3324368
"002162" 2015  .54236424
"002162" 2016  -5.075739
"002162" 2017  1.9891856
"002162" 2018  .24224047
"002338" 1999 -.17275256
"002338" 2000   .8153301
"002338" 2001  .10111365
"002338" 2002  -.4338974
"002338" 2003 -2.3787796
"002338" 2004   .3397895
"002338" 2005   .4249638
"002338" 2006  .35274535
"002338" 2007   .9040937
"002338" 2008  1.2003168
"002338" 2009   .4507056
"002338" 2010   .1715474
"002338" 2011   .3581613
"002338" 2012   .6320808
"002338" 2013   .8774309
"002338" 2014 -2.3582609
"002338" 2015  1.6632206
"002410" 1999  -.3774664
"002410" 2000  -.0206092
"002410" 2001 -.22753513
"002410" 2002  -.3786254
"002410" 2003   .7487115
"002410" 2004  2.2103279
"002410" 2005   .3802048
"002410" 2006  -.6452339
"002410" 2007 -.29756767
"002410" 2008 -1.4438903
"002410" 2009  -1.582081
"002410" 2010 -1.4257122
end
I need to create ranked quartiles each year based on variable w0, where companies with the lowest w0 are assigned to quartile 1, while companies with the highest w0 are assigned to quartile 4.
How could I do that? Thanks for the attention.

Daniel