Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

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


From   Martijn S <martstouthart@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Creating a dummy for each large firm in each fiscal year (foreach command)
Date   Sun, 12 Jun 2011 18:33:51 +0200

Hello,

This is my problem. I have a sample which uniquely identifies firms by
the variable gvkey. Now I want to run a regression over firms that are
defined as large and therefore I want to create a dummy.  I define
firms as large on basis of their 2008 total assets. As a result I
created a dummy variable called largefirmdummywith the command:
generate largefirmdummy=1 if fyear==2008 & at > 100. Next I entered
the following command: generate gvkeylarge = gvkey if
largefirmdummy==1. So I now have the variable gvkeylarge which
contains the gvkey of each large firm.

Suppose now, gvkeylarge contains a firm with the 'gvkey' 1166. I have
this firm in my sample from 1999-2010, as is can be seen from variable
gvkey which contains 12 times the gvkey 1166.

So from 1999-2010 I want to create a dummy which has a value of 1 in
for this firm. This can be done by
the following command:

replace largefirmdummy=1 if gvkey==1166
replace largefirmdummy=1 if gvkey==8071
replace largefirmdummy=1 if gvkey==8546

etc....

Thus I want to create a loop which looks at every unique number if
gvkeylarge, than looks at looks at the variable gvkey
if it containts this unique number, and when this is the case the loop
must add a 1 to the variable largefirmdummy.


I tried the foreach command but I cannot get this working. I hope that
someone can help me out.


Thanks,

Martijn







 .
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index