Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Accessing the number of changes made by a "replace" command


From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: Accessing the number of changes made by a "replace" command
Date   Fri, 18 Mar 2005 14:11:24 -0500

Another way at this:

  capture assert myvar == whatever
  while _rc {
        replace myvar = whatever
       capture assert myvar == whatever
  }

This avoids creating a copy of myvar . . .

--Nick Winter



At 12:21 PM 3/18/2005 -0500, you wrote:

At 10:03 AM 3/18/2005 +0000, David Fischer wrote:
Hi all,
I am attempting to create a "while" loop that executes, amongst other things, a "replace" command on a particular variable. I would like this loop to continue until the "replace" command cannot make any more changes to the data. In order to do this I would like to be able to access the number of (real) changes made by the "replace" command, so that I can say something like "loop while (number of real changes)!=0". Is there a way to do this in Stata? I thought there might be an underscore variable that would do this, but I can't find one.
Thanks!
David Fisher.
Coincidentally, just yesterday, I wrote to Stata Tech Support, asking about this and suggesting that they provide a returned value. It's potentially under consideration, but there are some issues involved.

Until then, the only way to correctly do it is ...
gen savedcopy = myvar // possibly with a type inserted after -gen-
replace myvar = whatever...
count if savedcopy != myvar
and test r(N)
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601

*
* 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