Dear Statalist members,
I am trying to code a new variable into stata which calculates the loss probability per firm. I estimate the loss probability as the proportion of years for which a firm reports a negative income before extraordinary items (variable ib) over the past 4 fiscal years. I.e. when in 4 fiscal years a firm reports a negative income once, the loss probability (loss_prob variable) should be 1/4=0.25. Though this might seem intuitively easy, I am struggling with the fact that not every firm (ID=gvkey) has four prior years (fyear) available. Could anyone help me out on how to code this? Below is some examplary data!
P.S. the firms are allowed to have a value for loss_prob if only 2 or 3 quarters are available, I will later remove these myself if deemed necessary through the use of . drop if count<=3 for instance.
gvkey fyear ib loss_prob
001004 2001 -58.939
001004 2002 -12.41
001004 2003 3.504
001004 2004 18.572
001004 2005 35.163
001004 2006 59.447
001004 2007 75.74500000000001
001004 2008 80.59999999999999
001004 2009 44.628
001004 2010 73.139
001004 2011 67.723
001004 2012 55
001004 2013 72.90000000000001
001004 2014 -54.5
001004 2015 40.5
001013 2001 -1287.7
001013 2002 -1145
001013 2003 -76.7
001013 2004 31.3
001013 2005 85.5
001013 2006 94.2
001013 2007 113.3
001013 2008 -44.4
001013 2009 -465.7
001013 2010 77.2
001034 2001 -35.674
001034 2002 -93.56699999999999
001034 2003 19.444
001034 2004 -314.737
001034 2005 62.176
001034 2006 59.992
Many thanks!
I am trying to code a new variable into stata which calculates the loss probability per firm. I estimate the loss probability as the proportion of years for which a firm reports a negative income before extraordinary items (variable ib) over the past 4 fiscal years. I.e. when in 4 fiscal years a firm reports a negative income once, the loss probability (loss_prob variable) should be 1/4=0.25. Though this might seem intuitively easy, I am struggling with the fact that not every firm (ID=gvkey) has four prior years (fyear) available. Could anyone help me out on how to code this? Below is some examplary data!
P.S. the firms are allowed to have a value for loss_prob if only 2 or 3 quarters are available, I will later remove these myself if deemed necessary through the use of . drop if count<=3 for instance.
gvkey fyear ib loss_prob
001004 2001 -58.939
001004 2002 -12.41
001004 2003 3.504
001004 2004 18.572
001004 2005 35.163
001004 2006 59.447
001004 2007 75.74500000000001
001004 2008 80.59999999999999
001004 2009 44.628
001004 2010 73.139
001004 2011 67.723
001004 2012 55
001004 2013 72.90000000000001
001004 2014 -54.5
001004 2015 40.5
001013 2001 -1287.7
001013 2002 -1145
001013 2003 -76.7
001013 2004 31.3
001013 2005 85.5
001013 2006 94.2
001013 2007 113.3
001013 2008 -44.4
001013 2009 -465.7
001013 2010 77.2
001034 2001 -35.674
001034 2002 -93.56699999999999
001034 2003 19.444
001034 2004 -314.737
001034 2005 62.176
001034 2006 59.992
Many thanks!
Comment