Hello all,
I have a simple question about generating a new variable in the sample data below.
How to create a new variable that contains the first non-missing value of var1 when var2==1. For firm A above, the value of the new variable should be 5 for all years. The new variable takes a missing value if all var1 is missing when var2==1. I appreciate your help, I spent too long figuring this out.
Best regards,
Abdan
I have a simple question about generating a new variable in the sample data below.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 firm int year byte(var1 var2) "A" 2000 . 1 "A" 2001 5 1 "A" 2002 5 1 "A" 2003 5 0 "A" 2004 5 0 "A" 2005 5 0 "A" 2006 5 0 "A" 2007 5 0 "A" 2008 5 0 "A" 2009 5 0 "A" 2010 5 0 "A" 2011 5 0 "A" 2012 5 0 "A" 2013 5 0 "A" 2014 5 0 "B" 2000 . 1 "B" 2001 . 1 "B" 2002 . 1 "B" 2003 3 0 "B" 2004 4 0 "B" 2005 4 0 "B" 2006 4 0 "B" 2007 4 0 "B" 2008 4 0 "B" 2009 4 0 "B" 2010 4 0 "B" 2011 4 0 "B" 2012 4 0 "B" 2013 4 0 "B" 2014 4 0 "C" 2000 . 1 "C" 2001 . 1 "C" 2002 5 1 "C" 2003 5 0 "C" 2004 6 0 "C" 2005 6 0 "C" 2006 6 0 "C" 2007 6 0 "C" 2008 6 0 "C" 2009 6 0 "C" 2010 6 0 "C" 2011 6 0 "C" 2012 6 0 "C" 2013 6 0 "C" 2014 6 0 end
How to create a new variable that contains the first non-missing value of var1 when var2==1. For firm A above, the value of the new variable should be 5 for all years. The new variable takes a missing value if all var1 is missing when var2==1. I appreciate your help, I spent too long figuring this out.
Best regards,
Abdan

Comment