lundi 21 mars 2016

Replacing string value using if option in Stata

I cannot figure out how to tell STATA to replace the value of a string variable only if the value of another (also) string variable is equal to "xxx"? To illustrate the problem: I need to merge two datasets according to the match in the name of the municipality (unfortunately, I do not have anything else that is common for the both datasets). In the first dataset, there are several hospitals with the municipality name "Frankfurt". In the second dataset, there are two occurrences of Frankfurt: "Frankfurt am Main" and "Frankfurt (Oden)". Both of them have a hospital. Consequently, I have to employ additional criteria to distinguish between them. In other words, I cannot tell STATA simply to replace all municipality values "Frankfurt" by e.g. "Frankfurt am Main" (in this case I could use command (replace ort = subinstr(ort, "Frankfurt", "Frankfurt am Main", .) ) but I have to firstly find where the hospital is situated with the help of its designation and afterwards to tell STATA to e.g. replace Frankfurt by FaM if designation=="xxx". I suppose it shouldn't be that difficult command but I cannot find it. Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire