[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Using 2 vars to make 1 in presence of missing
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 .)
else if (b ne .)
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
I've tried recoding missing to a negative valid value and using gen as
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.
* For searches and help try: