Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Creating a dummy for each large firm in each fiscal year (foreach command)


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Creating a dummy for each large firm in each fiscal year (foreach command)
Date   Mon, 13 Jun 2011 09:10:55 +0100

One line suffices

egen largefirmdummy = total(fyear == 2008 & at > 100), by(gvkey)

As Kit points out, the extra condition -at < .- would do no harm.

Nick

On Mon, Jun 13, 2011 at 8:26 AM, Nick Cox <[email protected]> wrote:
> If I understand this correctly, Daniel's code is equivalent to this,
> for which the limits he referred to won't bite.
>
> gen tag = fyear == 2008 & at > 100
> bysort gvkey (tag) : gen largefirmdummy = tag[_N]
>
> There's much more on this kind of thing in the Speaking Stata column
> forthcoming in SJ 11(2) 2011.
>
> No loops are needed at all.
>
> Nick
>
> On Sun, Jun 12, 2011 at 9:21 PM, daniel klein
> <[email protected]> wrote:
>> I do not think the first dummy (gvkeylarge) is needed here. One way to
>> create the disired dummy (largefirmdummy) might be
>>
>> levelsof gvkey if (fyear==2008) & (at > 100) ,loc(keys) s(,)
>> g byte largefirmdummy = inlist(gvkey, `keys')
>>
>> The -inlist()- function will not work if there are more than about 240
>> large firms, though. If this is the case, you may have to create a
>> loop over the elements of the local. Alternatively, you may also think
>> about using -reshape- your data wide.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index