Hi Statlist,
I have the following problem. I have a panel dataset of the form:
Hence, the data consists of products observed in time (unbalanced panel). I also have a dummy variable taking 1 if the product has been recalled in a Year and 0 if not. What I would like to do is basically rescaling the time variable Year for each product with respect to the Year in which it received the recall. SO for instance if the product 3, observed in 2005 2006 2007 and 2008 received a recall in 2007, 2007 should be year 0, 2005 = -2, 2006 = -1, 2007 = 0, 2008 = 1 and so on. I have managed to this. The problem is when more than a recall occurs in a time span. Specifically, say idproduct 18 in the data above. Idprod 18 receives 2 recalls one in 2011 and one in 2012. For such kinds of products (and also the ones receiving more than 2 recalls) I would like to rescale time by splitting it into two rescaled time putting the year in common as "pre" of the "younger" recall and "post" of the "elder". So in the case of product 18 I would like to obtain something like:
And for product 15 (which has years in common due to the fact that the recalls are separated):
I don't know if the output is correct: indeed the variable rescaled_year should be eventually, plot on the x-axis of a graphic (so two values for a same rescaled_year are not convenient I guess) The point is that I am looking for a way to split into two the spans of the recalls: the first in 2006 should look: -2, -1, 0,1, 2 , 3; the second in 2011: -1, 0,1,2.
Please notice that this should extend to the case in which I have 3,4 and 5 recalls.
So, for instance had idpr 15 had 3 recalls, this should have been:
Sorry for the length of the post and thank you in advance!
Federico
I have the following problem. I have a panel dataset of the form:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(dummy_1 idproduct Year) 0 1 2010 0 1 2011 0 1 2012 0 2 2004 0 2 2005 0 2 2006 0 2 2007 0 3 2004 0 4 2012 0 4 2013 0 5 2010 0 5 2011 0 6 2010 0 6 2011 0 6 2012 0 7 2007 0 7 2008 0 8 2004 0 8 2015 0 9 2004 0 9 2005 0 9 2006 0 9 2007 0 9 2008 0 9 2009 0 9 2010 0 9 2011 0 9 2012 0 9 2013 0 9 2014 0 9 2015 0 10 2010 0 10 2011 0 10 2012 0 11 2004 0 11 2005 0 11 2006 0 11 2007 0 11 2008 0 11 2009 0 11 2010 0 11 2011 0 11 2012 0 11 2013 0 11 2014 0 11 2015 0 12 2008 0 12 2009 0 12 2010 0 12 2011 0 12 2012 0 12 2013 0 12 2014 0 12 2015 0 13 2010 0 13 2011 0 13 2012 1 14 2004 0 14 2005 0 14 2006 0 14 2007 0 14 2008 0 14 2009 0 14 2010 0 14 2011 0 14 2012 0 14 2013 0 14 2015 0 15 2004 0 15 2005 1 15 2006 0 15 2007 0 15 2008 0 15 2010 1 15 2011 0 15 2012 0 15 2013 0 16 2004 0 16 2005 0 16 2006 0 16 2007 0 16 2008 0 16 2009 0 16 2010 0 16 2011 0 16 2012 0 16 2013 0 16 2014 0 16 2015 0 17 2008 0 17 2009 0 17 2010 0 18 2004 0 18 2005 0 18 2009 0 18 2010 1 18 2011 1 18 2012 0 18 2013 0 18 2014 end
Code:
input float(dummy_1 idproduct Year rescaled_year) 0 18 2004 -4 0 18 2005 -3 0 18 2009 -2 0 18 2010 -1 1 18 2011. 0 1 18 2012. 0 0 18 2013 1 0 18 2014 2
Code:
input float(dummy_1 idproduct Year rescaled_year) 0 15 2004 -2 0 15 2005 -1 1 15 2006 0 0 15 2007 1; -3 0 15 2008 2; -2 0 15 2010 3; -1 1 15 2011 0 0 15 2012 1 0 15 2013 2
Please notice that this should extend to the case in which I have 3,4 and 5 recalls.
So, for instance had idpr 15 had 3 recalls, this should have been:
Code:
input float(dummy_1 idproduct Year rescaled_year) 0 15 2004 -1 1 15 2005 0 1 15 2006 0 0 15 2007 1; -3 0 15 2008 2; -2 0 15 2010 3; -1 1 15 2011 0 0 15 2012 1 0 15 2013 2
Sorry for the length of the post and thank you in advance!
Federico
Comment