Statalist


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

Re: st: Count observations per year


From   "krishanu karmakar" <[email protected]>
To   [email protected]
Subject   Re: st: Count observations per year
Date   Wed, 13 Feb 2008 03:25:33 +0530

Thank you sir for hinting to a more compact way of doing it.

regards

Krishanu

On Feb 12, 2008 10:57 PM, Nick Cox <[email protected]> wrote:
> 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/
>



-- 
Read it: http://www.stata.com/support/faqs/res/statalist.html
Specially Question 3.
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index