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: Creating a new variable conditional on the values for 2 other variables


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Creating a new variable conditional on the values for 2 other variables
Date   Tue, 10 May 2011 08:36:28 +0100

Note that this can be written as one line

generate C = cond(missing(B), A, B)

Nick

> On Tue, May 10, 2011 at 2:08 AM, Hitesh Chandwani

>> Thank you, Christian! This works!

Christian Holz

>>> generate C=A
>>> replace C=B if !missing(B)

Hitesh Chandwani

>>>> I have 2 variables, A and B. I have values of A for all observations and
>>>> values of B for some. A and B are both cost variables such that
>>>> (B=A+extra
>>>> cost). I need to generate a new variable C, such that C=B (for
>>>> observations
>>>> having a value for B), otherwise C=A
*
*   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