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

RE: st: Count observations per year

From   "Nick Cox" <>
To   <>
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).


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:

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