Hi,
My dataset is of the form:
Except that I do not have the variable relevant_country, which I am trying to create. This variable should taked the value of "Spain" if XVAR's value comes from the variable Spain, and the same for the other countries.
I have tried to do the following:
However, instead of the variable containing the country names, it contains the country values (so is identical to XVAR). How can I tell Stata to take the variable name instead of the variable value?
Thank you very much!
My dataset is of the form:
XVAR | Spain | France | UK | Germany | relevant_country |
1 | 1 | . | . | . | Spain |
3 | . | 3 | . | . | France |
5 | . | . | 5 | . | UK |
7 | . | . | . | 7 | Germany |
Except that I do not have the variable relevant_country, which I am trying to create. This variable should taked the value of "Spain" if XVAR's value comes from the variable Spain, and the same for the other countries.
I have tried to do the following:
Code:
global countries Spain France UK Germany gen relevant_country=. foreach cntry in $countries{ global outcome "cntry'" replace relevant_country=$outcome if country!=. }
Thank you very much!
Comment