Statalist The Stata Listserver


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

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


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

Here's one way to only drop matched pos/neg pairs:

gen abscharge=abs(charge)
bysort personid proc date abscharge (charge) : gen byte todrop=charge!=charge[_n-1] & _n>1
bysort personid proc date abscharge (charge) : replace todrop=1 if charge!=charge[_n+1] & _n<_N
drop if todrop==1
drop todrop

You would need to run this more than once if there are multiple matched pos/beg pairs with the same values. The hasnegative var is superfluous for this approach since the only way that charge!=charge[_n-1] within the same abscharge is if they differ in sign.

Michael Blasnik


----- Original Message ----- From: "sara borelli" <[email protected]>
To: <[email protected]>
Sent: Wednesday, March 07, 2007 12:37 PM
Subject: Re: st: Re: eliminate negative values and their positive counterpart



Hi Michael,

I am sorry to write again about the question of
yesterday
I am not sure how I would change the code you
suggested in the following case:

claimnum   personid  servdate     charge     proc
4087      1000124    2001-06-06   +25274.25   121
4510      1000124    2001-06-06   -25274.25   121
4511      1000124    2001-06-06   +25274.25   121

If I want to eliminate the negative charge AND both
positive counterparts I just type drop if
hasnegative==1.

The problem is that I might need to drop the negative
and only one of the positive counterparts, but the
only variable that can distinguish between the two
positives is claimnum, which cannot be used to define
a group since it is unique to each observation

thank you in advance
Sara
*
*   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