Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Brill, Robert" <robertbrill@austin.utexas.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Drop under several conditions and time (year) |
Date | Sun, 23 Mar 2014 20:49:04 +0000 |
Sorry, that second to last line should be drop if LongTermDebt2007>TotalAssets2007 | LongTermDebt2008>TotalAssets2008 On 3/23/14, 4:44 PM, "Brill, Robert" <robertbrill@austin.utexas.edu> wrote: >Your -if- subsetting seems to be incorrect. Right now, your code says >³drop if the year is equal to 2007, or, if the year is 2008 and long-term >debt is greater than total assets.² > >What you intended to type was probably something more like: > >drop if (Year==2007 & LongTermDebt>TotalAssets) | (Year==2008 & >LongTermDebt>TotalAssets) > >But that will only remove the rows for which those statements are true, >not the entire firm. > >Stata does not know the format of your data, so it will not drop the >entire firm, only the rows for which the -if- statement is true. > >For this reason, previous answers to your question have used the -egen- >command to create a drop indicator, which will be one for all rows of a >firm if the firm fulfills a certain condition. > >An easier way for you to understand your problem might be to reshape your >data into ³wide² format, such that each row represents one firm, and has a >variable for each variable for each year. Thus 13 rows of LongTermDebt are >converted to thirteen columns of LongTermDebt named LongTermDebt2000, >LongTermDebt2001, etc. You can do this by doing: > >reshape wide LongTermDebt TotalAssets, i(Firm) j(Year) > >drop if LongTermDebt2007>TotalAssets2007 | >LongTermDebt2008>LongTermDebt2008 > >reshape long > >Of course, if your data contain variables other than those you have >described, you¹ll need to include them in the argument of reshape (before >the comma). The advantage of reshaping your data to wide is that you will >be able to drop observations on single row conditions, rather than trying >to understand -egen-, which can be complicated for a novice to data >management. > >Regarding your other question, if you simply have a list of keys you want >to drop, rather than encoding your string variable, you could simply use >the correct syntax for strings: > >drop if Key==³C0056" > >Notice the quotation marks‹values of string variables must be enclosed in >quotation marks for Stata to understand what to evaluate. > > > > > > > > >On 3/23/14, 4:10 PM, "Julian Kochan" <julian.kochan@gmx.de> wrote: > >>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/