Hi All,

Although the -replace- command is fairly intuitive, it is sometimes a bit tricky.

Specifically, say I have a dataset as the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(y x1 x2)
 5   .  .
12 123 32
32 113  1
end
In the above, we have data on y, and two covariates: x1 and x2. The first row data for the two x variables is missing. Suppose that when both of these are missing, I know that x1 and x2 should be 5. Intuitively, I would do:

Code:
replace x1=5 & x2=5 if missing(x1)
This is an illegal command ( it shouldn't be, in my view). This can be achieved by brute force:

Code:
replace x1=5 if missing(x1)
replace x2=5 if x1==5
The problem, of course with the second method is that it would modify the data incorrectly if x1==5 elsewhere, where it was not missing. That being said, there are two issues:
  1. Why can replace not be used for multiple replacements at once as above?
  2. What can be done about the fact that if two replacements are to be made using the same condition (missing(x1) in the case above), and if they cannot be done simultaneously, how can one account for the fact that the second replacement can only be identified using a condition that is not unique for the replacement (if x1==5)?
Many thanks,
CS