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: STATA Question: drop command with several conditions


From   Roberto Liebscher <[email protected]>
To   [email protected]
Subject   Re: st: STATA Question: drop command with several conditions
Date   Sat, 22 Mar 2014 14:02:20 +0100

Why not generate a variable that gives the number of non-missing (and non-zero) observations for the years 2007 and 2008 for each firm? Then you can use this variable for the drop command.

*Markcap of 0 to missing
replace markcap = . if markcap == 0

*Count observations that are non-missing in years 2007 and 2008
bysort firm: egen countvar = count(markcap) if year == 2007 | year == 2008

*Copy constant to other years
bysort firm: egen countvar2 = min(countvar)

*Delete observations
drop if countvar2 < 2 //If I got you right, you want to keep all observations with at least one non-missing (or non-zero) observation in 2007/2008

HTH,
Roberto

--
Roberto Liebscher
Catholic University of Eichstaett-Ingolstadt
Department of Business Administration
Chair of Banking and Finance
Auf der Schanz 49
D-85049 Ingolstadt
Germany
Phone:  (+49)-841-937-1929
FAX:    (+49)-841-937-2883
E-mail:   [email protected]
Internet: http://www.ku.de/wwf/lfb/



Am 22.03.2014 13:33, schrieb Julian Kochan:
Hi,

i have a set of data with financial firm characteristics of about 10.000 firms for Year 2000 - Year 2012.

Let's assume: The first column of the data table displays the Name of the firm, the second the Year and the third displays the Market Capitalization.
Thus, 13 rows in a row (2000-2012) display information about just one firm - just the year varies.

Problem: I want to drop those firms, for which the Market Cap is zero or Missing in the Year 2007 or Year 2008.
		 If this is the case, the firm should be dropped out of my data completely such that the firm observation is not only dropped for 2007 and 2008, but also for all the other year.
		 I tried a lot but it didn't succeed. As you can see the condition is based on 3 Variables ( firm, market Cap and Year).

I would be really really happy to receive an answer.

best regards

Julian



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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