I have panel data for the year 2000-2014. I want to create a new variable county2000 which takes the value of year 2000 from county x. If the observation in 2000 is missing, I want to use the next available observation (e.g. 2001). Can you help me with how to do it? The following is the data sample. Thank you for your help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id int year byte(state county) 1758 2000 11 3 1758 2001 . . 1758 2002 . . 1758 2003 . . 1758 2004 . . 1758 2005 . . 1758 2006 . . 1758 2007 . . 1758 2008 . . 1758 2009 . . 1758 2010 . . 1758 2011 . . 1758 2012 . . 1758 2013 . . 1758 2014 . . 1761 2000 11 5 1761 2001 11 7 1761 2002 11 7 1761 2003 11 7 1761 2004 11 7 1761 2005 11 15 1761 2006 11 15 1761 2007 11 15 1761 2008 11 15 1761 2009 11 15 1761 2010 11 15 1761 2011 11 15 1761 2012 11 15 1761 2013 11 15 1761 2014 11 15 49002 2000 . . 49002 2001 12 7 49002 2002 12 7 49002 2003 . . 49002 2004 12 7 49002 2005 12 7 49002 2006 12 7 49002 2007 12 7 49002 2008 12 7 49002 2009 12 7 49002 2010 . . 49002 2011 . . 49002 2012 . . 49002 2013 . . 49002 2014 . . end
Best regards,
Abdan
0 Response to Creating a new variable with the first observation
Post a Comment