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: RE: Drop under several conditions and time (year)


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: Drop under several conditions and time (year)
Date   Sun, 23 Mar 2014 21:25:42 +0000

That method can be used for any condition that you would normally use in an -if- qualifier:

. bysort Key: egen bad=total((Year == 2007 | Year == 2008) & LongTermDebt > TotalAssets)
. drop if bad

The -egen total()- function counts the number of cases for each firm that fulfill the criteria and puts that total in the variable -bad- for all observations for that firm.  The drop statement then gets rid of all cases that have a non-zero value for -bad-, which will include all observations for any firm that fulfills the criteria.

P.S. Robert Brill's method will also work, but I disagree that -egen- is beyond the scope of the beginning programmer.  Yes, it is a little confusing at first, but it is an essential tool for anyone who is going to do anything the least bit complicated in Stata.  So, you might as well buckle down and learn to use it.
________________________________________
From: [email protected] [[email protected]] on behalf of Julian Kochan [[email protected]]
Sent: Sunday, March 23, 2014 5:08 PM
To: [email protected]
Subject: Re: st: RE: Drop under several conditions and time (year)

I tried with nick's suggestion but it didn't work. Doesn't nick's suggestion refer to the case with missing (as it was in my first question) ? Now i want to refer to LTDebt>Assets ... Do you have a suggestion ?
Thanks.

> Am 23.03.2014 um 21:40 schrieb Joe Canner <[email protected]>:
>
> Did you try Nick's suggestion in response to your last post?
> ________________________________________
> From: [email protected] [[email protected]] on behalf of Julian Kochan [[email protected]]
> Sent: Sunday, March 23, 2014 4:10 PM
> To: [email protected]
> Subject: st: Drop under several conditions and time (year)
>
> 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, the third displays the LongTerm Debt and the fourth the TotalAssets.
> 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 LongTermDebt is greater than TotalAssets 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 years.
>
>                I tried: drop if Year == 2007 | Year == 2008 & LongTermDebt > TotalAssets. This made Stata to delete about 5000 observation altough I just had 150 observations with LongTermDebt > Total Assets.
>                There is something I do not get as a Stata beginner. Is the drop function the wrong function when trying to delete observations under several conditions such as comparing Debt to Assets ?
>
> I would be really really happy to receive an answer.
>
> 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/

*
*   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