Dear Statalist users,

I have panel data for firms involved in international trade. t1 is my variable which is a dummy (1 if firm participates in global markets and 0 otherwise). Now I want to generate the following

a) starter firms - These are firms that do not trade in t-1 and t-2 periods but begin trading at t and continue to do so till the sample period
b) stop firms - These are firms who were trading but then stopped during the sample period and continued to not trade after deciding to stop
c) switchers - these are firms that either started trading for the first time and then stopped, or vice-versa. (in the data example you can see firm 365 starts trading in 2002 and then stops in 2004)

I am not able to construct these variables. It would be really helpful someone could help me with it

input double id int year float t1
365 2001 0
365 2002 1
365 2003 1
365 2004 0
365 2005 1
365 2006 1
365 2007 0
365 2008 0
365 2009 0
365 2010 0
365 2011 0
365 2012 0
365 2013 0
381 2001 1
381 2002 1
381 2003 1
381 2004 1
381 2005 1
381 2006 1
381 2007 1
381 2008 1
381 2009 1
381 2010 1
381 2011 .
381 2012 .
381 2013 .
569 2001 0
569 2002 0
569 2003 0
569 2004 0
569 2005 0
569 2006 0
569 2007 0
569 2008 0
569 2009 0
569 2010 0
569 2011 .
569 2012 .
569 2013 .
595 2001 .
595 2002 .
595 2003 .
595 2004 .
595 2005 .
595 2006 0
595 2007 0
595 2008 0
595 2009 0
595 2010 0
595 2011 0
595 2012 0
595 2013 0
600 2001 .
600 2002 .
600 2003 .
600 2004 .
600 2005 .
600 2006 .
600 2007 .
600 2008 .
600 2009 0
600 2010 0
600 2011 0
600 2012 0
600 2013 .
783 2001 0
783 2002 0
783 2003 0
783 2004 0
783 2005 0
783 2006 0
783 2007 0
783 2008 0
783 2009 0
783 2010 0
783 2011 0
783 2012 0
783 2013 0
870 2010 0
934 2001 .
934 2002 .
934 2003 .
934 2004 0
934 2005 0
934 2006 0
934 2007 0
934 2008 0
934 2009 0
934 2010 .
934 2011 .
934 2012 .
934 2013 .
1120 2001 1
1120 2002 1
1120 2003 1
1120 2004 1
1120 2005 1
1120 2006 1
1120 2007 1
1120 2008 1
end