Hello,

I'm trying to get rid of companies that have negative revenues or negative total assets. These variables are opre and toas in my dataex.

So I did the following: bysort idnr (closdate_year): generate algo = opre & toas < 0
idnr, is the name of the company. closdate_year the year, opre is returns and toas total assets.

Then i proceed to drop algo. However, it only drops that current year and not all the companies observations from the dataset.

How can I tell stata to drop all the observations of that company if opre & toas < 0 ?

Thank you

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str16 idnr double(closdate_year opre toas cash)
"SK36835943" 2010    25892    15469   11231
"SK47534273" 2014     6550     7112    5112
"SK44333170" 2009    19181    17544   10429
"SK35845210" 2009   564649   275630   24406
"SK37602985" 2014   499999        .       .
"SK36269212" 2010   419997   175691   45041
"SK36745618" 2009      755    54649    8762
"SK44719434" 2013   133573   153448  -65891
"SK35693720" 2010  1623590  1075746  138173
"SK46775005" 2013    11879     5144    2043
"SK36701530" 2010   451309   133741   15432
"SK36042960" 2011    55870    47392   21509
"SK44605935" 2015   227059   125269   34432
"SK46932607" 2014    44195    28679   22074
"SK36275158" 2012  1494167   915643     327
"SK41294751" 2011    98499        .       .
"SK45950831" 2012        0        0   22160
"SK35735767" 2013    24031    42243   38012
"SK36498301" 2013     5837    13944    1849
"SK36732516" 2015   102264   122303   90853
"SK31438636" 2015  1285306   465540   92009
"SK36045900" 2015   807355   457862  140830
"SK44251076" 2012    74976    51965   31410
"SK31666183" 2011  3483016  9264215  625959
"SK44830971" 2009    39284    61356   48079
"SK44224184" 2011   329301   146797   17322
"SK45679711" 2014        0     5191    5191
"SK46491996" 2012    86464    33378   14159
"SK35803223" 2015   276729   692891  579356
"SK31563376" 2011    42054   187073   97080
"SK35727012" 2014        0    10580   10070
"SK31691633" 2015  2711072  1039208   46060
"SK44279761" 2014     1167     3003    3003
"SK00168122" 2013  1316935  1380184   25681
"SK36004766" 2015   979470  2021199  675586
"SK31624189" 2012  3200514   880008    8283
"SK36451941" 2008  3157106  1832006  118436
"SK45680817" 2012        0     4796    4796
"SK44469551" 2014   499999        .       .
"SK31719520" 2013        0    96802      31
"SK44614365" 2013    27106    12559   12559
"SK36377236" 2012   252322   770057   53434
"SK35924756" 2012   180255   160690  132363
"SK46220224" 2015   426031   537048    1633
"SK36300675" 2011   711841   186804   37428
"SK31663869" 2014  2345650  1117372   14084
"SK36256277" 2010        0     4381    4381
"SK46677593" 2013   180682    29301   29301
"SK44530439" 2013  2739209   527786   63985
"SK35726288" 2013    14306    20185     399
"SK46325646" 2012     7679     9860    9860
"SK45725446" 2013   105113    54816   30166
"SK36711853" 2008   222465   109274   76346
"SK48055034" 2015    21730    13396    9078
"SK44147333" 2010   139224    69253    9152
"SK44757085" 2012    45499   213712    3979
"SK00308145" 2014        .        .       .
"SK36728578" 2008    73823    25593   18821
"SK34152024" 2015 17673625  9025665  115566
"SK44526725" 2013    10766    11862    9045
"SK36650269" 2012        0     1703    1628
"SK44914351" 2013   241916   615657  367091
"SK35816937" 2013    13245    19794     894
"SK47194791" 2015  3047033  1476512  153844
"SK36227951" 2010   108234   106490   61585
"SK47509520" 2015   657350   499743   74440
"SK36291285" 2015   226625   332715   44354
"SK47232897" 2012    55980    23588    1807
"SK36781487" 2009   495513  3644611  753406
"SK47156007" 2015    18000    35880   25814
"SK37857207" 2010   497999        .       .
"SK35816686" 2014        0    39733   14214
"SK44561865" 2013    52873    13875   12968
"SK36465844" 2010   830727   529219  110604
"SK46598677" 2013    19000   162501  151142
"SK46232958" 2015    16030    46381   46381
"SK46527648" 2015    82183   222694   28356
"SK45350124" 2011    10510     6724    4167
"SK44967080" 2011    63950    57054   12507
"SK44705956" 2015   453317   813527   28535
"SK46208275" 2014     7055    72437   42705
"SK44189362" 2015   900955  1324778   29810
"SK36417769" 2008     8564    83084   83085
"SK46058176" 2015   196589   392681   27784
"SK44559275" 2009    78702    42471   15237
"SK36266353" 2013    89141  6929623 1046634
"SK35759348" 2015    33800      899     899
"SK36058114" 2009   117759    75156   17409
"SK35818425" 2011 76369020 23295569 1849281
"SK46062807" 2014   252607    75746   13597
"SK35748133" 2012  4771947  1353456  100764
"SK37890191" 2014        .        .       .
"SK36362174" 2007    40331    27285    5443
"SK44018797" 2012   922040   518417   65050
"SK34119558" 2013    67238    49224   22858
"SK35944196" 2013    23340    13213   10728
"SK44692081" 2013    87021    23444    1186
"SK45454761" 2011    47033     6931    1210
"SK36484491" 2010    10679    15233    4561
"SK45409587" 2010   103667     7070    3968
end