Eleanor Friedman et al.--
I don't think any of the approaches below are robust
to unexpected twists in the data, something we
should all be careful of as a rule. Just to be
sure the data is as expected, I would:
clear
input var1 var2
. 2
. 8
. 0
7 .
3 .
. .
3 4
end
gen newvar1=max(var1,var2)
gen newvar2=min(var1,var2)
assert newvar1==newvar2
l var? newvar? if newvar1!=newvar2
Paswel Phiri Marenya <[email protected]> wrote:
What to me is easier is something like:
gen var3 = var2
then replace var3=var1 in 4/5 and so on...although with a long data set it
may be tedious perhaps.
Andrew H. Sidman <[email protected]> wrote:
While there is probably a faster way, I gen
temporary variables and recode the missing:
gen var1a = var1
gen var2a = var2
recode var1a var2a (. = 0)
gen newvar = var1a + var2a
drop var1a var2a
Philipp Rehm <[email protected]> wrote:
gen newvar=var1
replace newvar=var2 if newvar==.
ricardo sierra <[email protected]> wrote:
egen newvar=rowtotal(var1 var2)
replace newvar=. if var1==. & var2==.
[email protected] wrote:
Now I have a question about combining the data from two
variables (in the same data set) into one variable. I want to
combine the variables in such a way that the data from one
variable can replace the missing values from the other. I have
created an example of what I am looking for below:
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/