For example, someone is good until they are bad. And then once they are bad, they remain bad until they switch to good.
Here is my example:
Code:
clear input year int good int bad 2000 1 0 2001 0 0 2002 0 1 2003 0 0 2004 0 0 2005 0 0 2006 1 0 2007 0 0 2008 0 1 end
Code:
clear input year int good int bad goodpath badpath 2000 1 0 1 0 2001 0 0 1 0 2002 0 1 0 1 2003 0 0 0 1 2004 0 0 0 1 2005 0 0 0 1 2006 1 0 1 0 2007 0 0 1 0 2008 0 1 0 1 end
I can do this if there is only 1 switch (from good to bad or vice versa). If only one switch, you find first occurrence of good and first occurrence of bad.
Code:
egen first_yr_good = min(cond(good == 1, year, .)) egen first_yr_bad = min(cond(bad == 1, year, .)) gen goodpath=1 if year>=first_yr_good replace goodpath=0 if year>=first_yr_bad & first_yr_good < first_yr_bad
I could code one line for every possible scenario, but that seems inefficient.
Thanks for your help in advance
0 Response to filling in values between dates
Post a Comment