Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Replace function


From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: Replace function
Date   Wed, 20 Jun 2012 18:11:22 +0200

Chris,

please read the help files for -if- and -in- qualifiers, where
expressions and ranges are explained, followed by examples.
Additionally, read the help file on -operators-. What you want is

replace sex=1 if id == 1 | id == 3 | id == 4 | id == 7 | id == 9

or, more convenient

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

Unlike -replace-, which is a command, -inlist()- is a function.

Best
Daniel

-- 
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
[...]
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index