Announcement

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

  • Calculate the max of a variable over the last two years with multiple values in one year

    I would like to calculate the maximum value of winshares based on the last two years by player (i.e., full name). For example, if I have a player named Aaron Brooks (in the table), for 2010 I would want the value 3.6 because it is the max of winshares of the 2008 and 2009 seasons. It gets tricky because sometimes the player plays for two teams in one year. I created a column called "Variable I am trying to create" to illustrate what variable I want to create. Thank you for your help.
    fullname team stint winshares seasonyr Variable I am trying to create
    Aaron Brooks Hou 1 1.4 2008 .
    Aaron Brooks Hou 1 3.6 2009 1.4
    Aaron Brooks Hou 1 5.5 2010 3.6
    Aaron Brooks Pho 2 1.1 2011 5.5
    Aaron Brooks Hou 1 1.1 2011 5.5
    Aaron Brooks Hou 2 .9 2013 1.1 (didn't play in 2012)
    Aaron Brooks Sac 1 .9 2013 1.1 (didn't play in 2012)
    Aaron Brooks Hou 2 2.1 2014 .9 (didn't play in 2012)
    Aaron Brooks Den 1 2.1 2014 .9 (didn't play in 2012)
    Aaron Brooks Chi 1 3.3 2015 2.1
    Aaron Brooks Chi 1 .9 2016 3.3
    Aaron Brooks Chi 1 1.2 2017 3.3 (max of 2015 and 2016)
    Last edited by Tiffany Keepman; 26 Apr 2017, 06:53.

  • #2
    As explained at length in the FAQ Advice we ask for data examples presented as CODE using dataex (SSC). Please read and follow http://www.statalist.org/forums/help#stata in future posts.

    Yours is clear enough to follow and I suggest using rangestat (SSC) for which search the forum.

    Code:
    rangestat (max) winshares, interval(seasonyr -2 -1) by(fullname)

    Comment


    • #3
      Thank you Nick for this code and for the information on how to post data examples for future posts. I really appreciate your help.

      Comment

      Working...
      X