Dear All, According to the following data (this example is taken from http://bbs.pinggu.org/thread-6277610-1-1.html), I'd like to create a categorical variable d, which is equal to 1 if b2a=rmax, 2 if b2b=rmax, 3 if b2c=rmax, and 4 if b2d=rmax.
The following is my code:
Any other suggestion?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(b2a b2b b2c b2d) float rmax 100 0 0 0 100 0 80 20 0 80 0 0 60 40 60 90 0 10 0 90 0 10 20 70 70 end label values b2a B2A label values b2b B2B label values b2c B2C label values b2d B2D
Code:
gen d = (b2a == rmax) replace d = 2 if b2b == rmax replace d = 3 if b2c == rmax replace d = 4 if b2d == rmax
Comment