Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Count observations per year


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Count observations per year
Date   Tue, 12 Feb 2008 17:27:59 -0000

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 
n.j.cox@durham.ac.uk  

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index