Statalist


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

AW: st: return code for replace


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: return code for replace
Date   Mon, 5 Oct 2009 12:22:56 +0200

<> 


I could also see raoul -clonevar-ing the variable in question as a reference and -compare-ing it after the -replace- action. Strangely, -compare- does not return a -return list-, though...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Maarten buis
Gesendet: Montag, 5. Oktober 2009 12:21
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: return code for replace

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


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