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

st: Re: accessing number of changes made by replace


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: Re: accessing number of changes made by replace
Date   Sat, 19 Mar 2005 06:30:50 -0500

I just answered this q (offlist) for one of our grad students the other day. Here is a utility that will handle this feature. The flag variable's sum is the number of changes made.

program drop _all
program alt1
version 8.2
syntax varlist(min=1 max=1)
qui g double __`varlist' = `varlist'
end

program alt2
version 8.2
syntax varlist(min=1 max=1)
confirm numeric v __`varlist'
qui g byte flag_`varlist' = !(`varlist' == __`varlist')
drop __`varlist'
su flag_`varlist'
end


use auto
* set the 'watched' state for price
alt1 price
* do some replacements
replace price=. if price<5000
replace price=99999 if price>10000
* generate the flag variable indicating which obs have been altered
alt2 price

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

On Mar 19, 2005, at 2:33 AM, Nick wrote:


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

I think you need to implement this yourself.
If you have a variable holding
the previous values, then after each change
you compare latest version with the previous values;
exit if no differences; otherwise replace
previous with latest, and loop again.
*
*   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