Dear reader,
I have a panel dataset containing executive id's, years and firm id's (cusips)
For every firm, over the time period 2002 to 2009, I want to know how many executives were once in power.
Example of the dataset:
fyear cusip execid
2002 001055 00013
2003 001055 00013
2004 001055 00013
2005 001055 00013
2006 001055 00013
2007 001055 00013
2008 001055 00013
2009 001055 00013
2004 004239 28561
2005 004239 28561
2006 004239 28561
2007 004239 28561
2008 004239 28561
2009 004239 28561
2002 00817Y 20970
2003 00817Y 20970
2004 00817Y 20970
2005 00817Y 20970
2006 00817Y 14660
2007 00817Y 14660
2008 00817Y 14660
2009 00817Y 14660
I want to create a variable that counts the number of execid per cusip over the years 2002 to 2009.
This would mean that for cusip 001055 this number will be 1
for cusip 004239 this number will also be 1
for cusip 00817y however this number will be 2 because there are two different execid id's.
I have tried the following:
But this is incorrect because Stata 12 counts from random years in the 2002 to 2009 range.
An example of a mistake is that is counts 2 execid's for companies that only have existed from 2007 onwards that only had 1 execid.
Does anyone know the answer to this problem?
Regards,
Nicole
I have a panel dataset containing executive id's, years and firm id's (cusips)
For every firm, over the time period 2002 to 2009, I want to know how many executives were once in power.
Example of the dataset:
fyear cusip execid
2002 001055 00013
2003 001055 00013
2004 001055 00013
2005 001055 00013
2006 001055 00013
2007 001055 00013
2008 001055 00013
2009 001055 00013
2004 004239 28561
2005 004239 28561
2006 004239 28561
2007 004239 28561
2008 004239 28561
2009 004239 28561
2002 00817Y 20970
2003 00817Y 20970
2004 00817Y 20970
2005 00817Y 20970
2006 00817Y 14660
2007 00817Y 14660
2008 00817Y 14660
2009 00817Y 14660
I want to create a variable that counts the number of execid per cusip over the years 2002 to 2009.
This would mean that for cusip 001055 this number will be 1
for cusip 004239 this number will also be 1
for cusip 00817y however this number will be 2 because there are two different execid id's.
I have tried the following:
Code:
by execid cusip, sort: gen nvals = _n == 1 if inrange(fyear,2002,2009) count if nvals sort Cusip by Cusip: replace nvals = sum(nvals) by Cusip: replace nvals = nvals[_N]
An example of a mistake is that is counts 2 execid's for companies that only have existed from 2007 onwards that only had 1 execid.
Does anyone know the answer to this problem?
Regards,
Nicole
Comment