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: Replace function


From   Christian Westby <christian.m.westby@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Replace function
Date   Wed, 20 Jun 2012 10:59:05 -0500

Dear Statalisters,

I have a quick question that I cannot seem to find an answer to.

I want to replace the values of a variable only in a specified subset
of observations

For example:

set obs 10
gen id=_n
expand 3
gen sex=0
replace sex=1 if id== 1 3 4 7 9 (I only want to replace the value for
these specific id’s)

The above replace statement does not work. Beside inputting the data
by hand,  how could I get this to work? I have tried adding the “in”
function such as

replace sex=1 if id in(1 3 4 7 9)

but it too did not work.


Regards

-Chris

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