Dear all,

I am working with an administrative dataset that contains a string variable that might assume exactly two different values for the same ID within the same period (year).

In particular, the dataset is like

year id state wanted_var
2011 1 BA PE
2011 1 PE PE
2011 2 CE CE
2012 2 CE CE
2012 2 BA CE


I would like to "correct" the variable 'state' so that whenever a given ID contains two entries in a given year and the value "BA" in one of them, the corrected version of the variable ("wanted_var") assumes the other value (than "BA") for both entries related to a given year for the same ID.

Can you help me with that?

Any help is greatly appreciated.

Thank you very much!


Obs: Here is to code to import the data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year id) str2(state wanted_var)
2011 1 "BA" "PE"
2011 1 "PE" "PE"
2011 2 "CE" "CE"
2012 2 "CE" "CE"
2012 2 "BA" "CE"
end