Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Re: eliminate negative values and their positive counterpart


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Re: eliminate negative values and their positive counterpart
Date   Tue, 06 Mar 2007 14:33:49 -0500

Woops, typo on my 3rd line, should be egen, not gen:

bysort personid proc date abscharge : egen sumcharge=total(charge)

Michael Blasnik

----- Original Message ----- From: "Michael Blasnik" <[email protected]>
To: <[email protected]>
Sent: Tuesday, March 06, 2007 2:15 PM
Subject: st: Re: eliminate negative values and their positive counterpart



I'm not sure if you require that the charges exactly offset each other or not, but if they do, then this should work:

gen abscharge=abs(charge)
bysort personid proc date abscharge (charge) : gen hasnegative=charge[1]<0
bysort personid proc date abscharge : gen sumcharge=total(charge)
drop if hasnegative & sumcharge==0
drop hasnegative sumcharge

You may want to browse at the dataset prior to issuing the drop command to see if it does what you want.

Michael Blasnik

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index