https://www.statalist.org/forums/for...other-variable
I discovered to my shock that triple conditions such as relimp==relat==1 and relimp==relat==3 do not do what I expect them to do.
In my mind, (relimp==relat==1) should be equivalent to (relimp==relat & relat==1). But it is not so, as the example below demonstrates.
To have some data to work with
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id byte wave float(relimp relat) 110 1 1 1 116 1 1 1 116 2 1 1 116 3 1 1 123 1 3 3 123 2 3 3 123 3 3 2 123 4 3 3 123 5 3 2 126 2 3 3 126 3 3 3 126 4 3 3 138 3 3 2 end
Code:
. gen dummy1 = relimp==relat==1 . gen dummy11 = relimp==relat & relat==1 . gen dummy3 = relimp==relat==3 . gen dummy33 = relimp==relat & relat==3 . compare dummy1 dummy11 ---------- difference ---------- count minimum average maximum ------------------------------------------------------------------------ dummy1=dummy11 7 dummy1>dummy11 6 1 1 1 ---------- jointly defined 13 0 .4615385 1 ---------- total 13 . compare dummy3 dummy33 ---------- difference ---------- count minimum average maximum ------------------------------------------------------------------------ dummy3<dummy33 6 -1 -1 -1 dummy3=dummy33 7 ---------- jointly defined 13 -1 -.4615385 0 ---------- total 13 . list, sep(0) +-------------------------------------------------------------------+ | id wave relimp relat dummy1 dummy11 dummy3 dummy33 | |-------------------------------------------------------------------| 1. | 110 1 1 1 1 1 0 0 | 2. | 116 1 1 1 1 1 0 0 | 3. | 116 2 1 1 1 1 0 0 | 4. | 116 3 1 1 1 1 0 0 | 5. | 123 1 3 3 1 0 0 1 | 6. | 123 2 3 3 1 0 0 1 | 7. | 123 3 3 2 0 0 0 0 | 8. | 123 4 3 3 1 0 0 1 | 9. | 123 5 3 2 0 0 0 0 | 10. | 126 2 3 3 1 0 0 1 | 11. | 126 3 3 3 1 0 0 1 | 12. | 126 4 3 3 1 0 0 1 | 13. | 138 3 3 2 0 0 0 0 | +-------------------------------------------------------------------+
0 Response to Triple conditions such as relimp==relat==1 do not do what I expect them to do. Why? Where is this behaviour explained?
Post a Comment