Krishanu's code can be slimmed down a bit:
sort year firm
gen inv = 1
egen inventory_count = total(inv), by(year firm)
could be
bysort year firm : gen inventory_count = _N
As in a separate posting, note that -contract- gets you there more
directly (with some small cost in interpreted code).
Nick
[email protected]
krishanu karmakar
I take the liberty of assuming that a, b, c, d etc in the variable
"inventory" does not mean anything in particular (That is they are not
codes for number of inventories)
In that case I think the following set of commands will do
sort year firm
generate inv=1
egen inventory_count=total(inv), by( year firm)
duplicates drop firm year, force
drop inventory
reshape wide inventory_count, i(firm) j(year)
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/