Statalist The Stata Listserver


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

Re: st: counting replacements?


From   "Richard Atkins" <Richard.Atkins@lshtm.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: counting replacements?
Date   Fri, 30 Mar 2007 17:52:52 +0100

Replace is a built in command so no chance of checking the source and as
you have found it doesn't appear to return any values.
It's a bit of a nasty hack but how about:

recode price min/.=-3 if foreign==1

This takes advantage of the fact that . is always > any and all
non-missing values.

Richard Atkins
London School of Hygiene and Tropical Medicine


>>> M Hollis <m73hollis_stata@yahoo.com> 30/03/2007 17:22 >>>
Thanks for the suggestion.  I actually just realized
that I have the id numbers for the corrections so I
should really just be merging in the corrected data. 
But, I'm always looking to learn new tricks and I
realized that I didn't give the best example.  The
recode command works well for the example I gave, but
isn't as useful if you don't necessarily know the
value you're changing from.  Here's another example:

. sysuse auto
. replace price=-3 if foreign==1
(22 real changes made)

Is there a way to access this 22 value?  It seems
uncharacteristic of Stata to provide data in the
output that is not available as a return value.

MH
--- Richard Atkins <Richard.Atkins@lshtm.ac.uk> wrote:

> recode price 4999=5000
> assert `r(N)'==1
> 
> Richard Atkins
> London School of Hygiene and Tropical Medicine
> 
> 
> >>> M Hollis <m73hollis_stata@yahoo.com> 30/03/2007
> 16:36 >>>
> I'm setting up a do-file to correct a number of
> errors
> in my dataset.  I'd like to check that each error
> correction replaces the value in one and only one
> observation. The replace command gives output on how
> many values are replaced, but I can't seem to find
> where that value is stored, if anywhere.  For
> example:
> 
> sysuse auto
> replace price=5000 if price==4099
> (1 real change made)
> 
> If I could access the 1 in the output, then I could
> just use something like:
> assert r(changes)==1
> 
> but there doesn't seem to be a return list.  I could
> do:
> 
> count if price==4099
> assert r(N)==1
> replace price=5000 if price==4099
> 
> I'm just wondering if there's a way to get it down
> to
> two lines. 
> 
> Thanks,
> 
> MH
> 
> 
>  
>
____________________________________________________________________________________
> Looking for earth-friendly autos? 
> Browse Top Cars by "Green Rating" at Yahoo! Autos'
> Green Center.
> http://autos.yahoo.com/green_center/ 
> *
> *   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/ 
> *
> *   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/ 
> 



 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front 
*
*   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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index