Good Morning everybody,
I would like to merge two variables in a certain way.
The situation is, that I have two variables, one has "text" and -97 for missin values, the other one is a dummy (0/1) for text or no text and -97 for missing valies.
Now I would like to generate a third variable which takes only the missing values from my dummy variables and fills the rest with the "text" from the string variable.
Example:
Var1 Var2 Var3
"Text" 1 "Text"
-97 -97 -97
"Text" -97 -97
"Text" 1 Text
I tried
which gives me both values from both variables in the new variable. And I tried also
for which stata gave me a "type missmatch". Both Variables are coded as type string and I use Stata 15.1
I would be happy about every advice
Best Regards
I would like to merge two variables in a certain way.
The situation is, that I have two variables, one has "text" and -97 for missin values, the other one is a dummy (0/1) for text or no text and -97 for missing valies.
Now I would like to generate a third variable which takes only the missing values from my dummy variables and fills the rest with the "text" from the string variable.
Example:
Var1 Var2 Var3
"Text" 1 "Text"
-97 -97 -97
"Text" -97 -97
"Text" 1 Text
I tried
Code:
egen newvar = concat( var1 var2), decode p(" ")
Code:
gen VAR3 = VAR1 replace VAR3 = -97 if VAR2 == -97
I would be happy about every advice

Best Regards
Comment