Statalist The Stata Listserver


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

st: RE: eliminate oppositie positive and negative values


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: eliminate oppositie positive and negative values
Date   Wed, 28 Mar 2007 22:13:00 -0500

I am not sure I fully understand the problem, but does the following code
work:

clear
input num   personid  str8 date       charge    proc    xm
406       124   2001-06   -5274      121     -1050
409       124   2001-06   -5274      121     -1050
409       124   2001-06   -5274      121     -1050
408       124   2001-06   5274      121     1050
451       124   2001-06   5274      121     1050
453       124   2001-06   5274      121     1768
end

replace charge = abs(charge)
replace xm = abs(xm)
duplicates tag pers date proc charge xm, gen(tag)
drop if tag !=0
drop tag
l

Scott

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of sara borelli
> Sent: Wednesday, March 28, 2007 8:41 PM
> To: [email protected]
> Subject: st: eliminate oppositie positive and negative values
> 
> Dear Statalist,
> I have a question that is related to one I have posted
> myself a couple of weeks ago:
> I have
> 
> num   personid  date       charge    proc    xm
> 406       124   2001-06   -5274      121     -1050
> 409       124   2001-06   -5274      121     -1050
> 409       124   2001-06   -5274      121     -1050
> 408       124   2001-06   +5274      121     +1050
> 451       124   2001-06   +5274      121     +1050
> 453       124   2001-06   +5274      121     +1768
> 
> I need to drop the negatives and the positives with
> the same date abs(charge) abs(xm) proc personid. As
> suggested by Michael Blasnik in a previous e-mail I
> runned the following:
> 
> gen abscharge=abs(charge)
> gen abs(xm)=abs(xm)
> bysort personid proc date abscharge abs(xm)(charge) :
> gen byte todrop=charge!=charge[_n-1] & _n>1
> bysort personid proc date abscharge absxm (charge) :
> replace todrop=1 if charge!=charge[_n+1] & _n<_N
> drop if todrop==1
> drop todrop
> 
> this worked well, but now I would need also something
> else.
> After the second round it stops dropping negatives
> since the remaining negative does not match anymore
> the postive in  terms of xm. To run the algorithm
> until it stops I have manually copied and pasted until
> it stops dropping additional negatives. But in some
> cases the number I have to do this gets large. Thus I
> would like to know if there is a way to say stata to
> run the algorithm up to the point where no additional
> negative values are dropped
> 
> thank you very much for any suggestion you might have
> 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