I am trying to run egen to generate an average of topic_prob1 that prior to the focal observation (based on yearpublished) for each designer team, but only getting blanks back. So based on example below for the final row it should average 6 and 7 from rows 2 and 6 for Paul to get 6.5. This seems like a pretty simple thing so likely is user error somehow but I have been trying for days.
I am a first time poster long time reader so my apologies in advance for whatever I messed up in terms of formatting, etc.
Code:
sort yearpublished designer egen topic_prob1_avg = mean(topic_prob1) if yearpublished < yearpublished[_n], by(designer)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int yearpublished double topic_prob1 strL designer 2001 7 "Mark" 2002 7 "Paul" 2002 6 "Mary" 2003 5 "Bill" 2004 6 "Colleen" 2005 6 "Paul" 2006 5 "Mary" 2007 6 "Jim" 2007 8 "Mark" 2008 5 "Mary" 2009 5 "Colleen" 2010 5 "Naomi" 2011 6 "Naomi" 2011 8 "Jim" 2012 8 "Paul" end
I am a first time poster long time reader so my apologies in advance for whatever I messed up in terms of formatting, etc.
Comment