Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: return code for replace


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: return code for replace
Date   Mon, 5 Oct 2009 10:21:18 +0000 (GMT)

--- On Mon, 5/10/09, raoul reulen wrote:
> I would like Stata to give me an error message if after
> using the replace command no changes have been made. 
> Does the replace command give a return code indicating
> whether or not a replacent has been made? 

No, but you could get there from first principle: I can
see two reasons why no values where replaced 1) you
specified a condition and all observations did not meet
that condition, 2) All observations that meet your
condition already have the value that you want to
replace it with. So I would code something like this
(I want to replace the variable `x' with the value one
if `touse' == 1 and the variable `foo' == 1):

*------------- begin example ----------------
local cond `"if `touse' & `foo' == 1"'

capture assert `x' == 1 `cond'
if _rc == 0 {
    di as err "some informative error message"
    exit 198
}
else {
    replace `x' = 1 `cond'
}
*-------------- end example -----------------

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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