Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: recode foreach with sysmis versus dot


From   annoporci <annoporci@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: recode foreach with sysmis versus dot
Date   Mon, 24 Dec 2012 20:53:09 +0800

Dear Statalist,

My question here is pure curiosity as I have found a workaround. No urgency.

In a dataset I have, I need to replace zeros with "missing" for all variables in the dataset.

A recent statalist exchange suggested the use of recode with a foreach loop. That suggestion was to turn a missing value into zeros --- the reverse of what I'm after --- so I tried to adapt the suggestion:

recode myvar (mis = 0)

The reverse:

recode myvar (0 = mis)

But that and other similar attempts failed. The "dot" sysmiss approach worked, so that's what I'm using now:

recode myvar (0 = .)

<CODE>
 use auto,clear
 local variables rep78
 foreach var of varlist `variables'{
*   recode `var'(3=mis) /// fails
*   recode `var'(3=sysmiss) /// fails
*   recode `var'(3=missing) /// fails
*   recode `var'(3=`missing') /// fails
*   recode `var'(3=-9999) /// works
   recode `var'(3=.) /// works
 }
<\CODE>

Reference:
http://www.stata.com/statalist/archive/2010-08/msg00410.html
http://www.stata.com/help.cgi?missing

--
Patrick Toche.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index