Maybe my head has been around the problem so long, looking at the manual,
other code, and such, that I just cannot see it. I have two variables, a
and b, and 1.5 datasets, A and B. All cases in B are in A, but some cases
in A are not in B. I want to merge the two datasets, matching on the id.
Variable a is missing for some cases in A, but the same variable has valid
values for some of those cases in B (as b).
I have tried several approaches. What I want is:
do if (a ne .)
compute c=a
else if (b ne .)
compute c=b
else
compute c=.
end if
I know its old spss syntax, but basically I want to use the value in
variable a unless it is missing, in which case use the value in variable
b.
I've tried recoding missing to a negative valid value and using gen as
follows:
gen c=max(a,b)
but that also sometimes ends up using a "b" value when a is missing but b
is not really valid for the case. (long story, details not relevant, I'll
suppress unless asked).
I tried egen but it doesn't seem willing to let me say something like:
calculate c=a, unless case not in A, then calculate c=b .
I've tried various syntactical approaches and none seem to work; I won't
bore you with a long set of tweaked but failed code.
* * *
Maybe I have, as I said, just gotten completely confused--there are about
half a dozen such situations in these datasets. I've spent the weekend
cleaning the data and these are the final issues that remain, and maybe
I'm just missing it--well, it is kind of clear I am missing it.
Any assistance is greatly appreciated.
Thanks.
Sam
*
* 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/