Hi,
I have panel data in a wide format for 5 rounds. I am trying to generate status mobility based on different statuses reported in each round.
I want to add those mobilities to create a final variable that adds the following to a persons mobility status: +1 if an upward mobility has happened, - 1 if a downward has happened and 0 if no switch has happened.
For example for a person:
I tried the following:
The above code won't give me this.
Sample of the data using dataex:
I have panel data in a wide format for 5 rounds. I am trying to generate status mobility based on different statuses reported in each round.
I want to add those mobilities to create a final variable that adds the following to a persons mobility status: +1 if an upward mobility has happened, - 1 if a downward has happened and 0 if no switch has happened.
For example for a person:
- From round 1 to round 2, there is no mobility- a value the assigned value should remain the same
- From round 2 to round 3, there is upward mobility- value +1, should be added to the existing status
- From round 3 to round 4, there is downward mobility- value -1, should be subtracted from the existing status
- From round 4 to round 5, there is upward mobility- value +1, should be added to the existing status
I tried the following:
Code:
gen mob1 = 1 if mobility2 > mobility1 gen mob2 = 1 if mobility3 > mobility2 gen mob3 = 1 if mobility4 > mobility3 gen mob4 = 1 if mobility5 > mobility4 replace mob1 = -1 if mobility2 < mobility1 replace mob2 = -1 if mobility3 < mobility2 replace mob3 = -1 if mobility4 < mobility3 replace mob4 = -1 if mobility5 < mobility4 egen row = rowtotal(mob1-mob4)
Sample of the data using dataex:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(mobility1 mobility2 mobility3 mobility4 mobility5) . 1 1 1 1 . . . . . . 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 5 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 3 3 3 . . . . . . . . . . . . . 3 3 1 . 1 1 1 . . . . . . . . . . . . . . . 2 . 2 . 2 . . 1 . 1 1 . 1 . 1 . . . . . . . . . . 1 1 1 1 1 . . . . 4 . . . . 3 1 1 1 1 1 1 1 2 1 3 2 2 1 . 2 1 1 1 1 . . . 1 1 1 . . . . . 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 1 1 1 1 1 1 1 4 4 4 . . . . . . . . . . 2 . . . 2 1 1 1 1 1 . 1 1 . 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 1 1 1 1 1 . 4 4 4 4 1 1 1 1 . . . . . . 1 1 1 1 1 1 . . . . . . . . . . . . . . 3 . 3 3 2 1 . 1 1 1 4 . 4 3 4 . . . . . . . . . . 5 5 5 5 5 1 1 1 1 1 . . 5 5 . . 1 1 1 1 6 4 4 4 4 1 1 1 1 1 1 1 1 1 1 . . . . . 1 . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . 3 6 . 3 . . . . . . . . . . . . . . . 1 1 . 1 1 1 1 . 1 1 1 1 . 1 1 . . . 1 . . . . . . . . . . . . . . . . 1 1 . 1 1 . . . 1 1 . . . . . 5 5 5 5 5 1 1 1 1 1 . . . . . 5 5 . 4 . . . . . . 5 5 5 5 5 end

Comment