Hi again, STATA friends!
Great first experience using the forum, thank you to the respondents for the help. I now have a question regarding categorical variables based off of the content of other variables.
I'm trying to create a field which will tell me if, and how many times, an individual in the data changed living location based on city. I could be more specific and try to obtain changes by the field containing street address, but there is input [spelling] error on the dataset's side which would taint the results. City changes will be fine for now.
I used the following code to successfully create a variable:
by ind_id (city), sort: gen changed = (city[1] != city[_N])
...but it doesn't account for an individual who may have moved more than once. I would like to have a result which displays a category for how many changes in 'city' are noted per ind_id, but then stop at the final change.
For example, I'd like to create the variable changed below:
Thanks in advance and I'm sorry I couldn't paste any code or screenshots in,data is housed on a secured remote desktop for privacy reasons.
-Peter
Great first experience using the forum, thank you to the respondents for the help. I now have a question regarding categorical variables based off of the content of other variables.
I'm trying to create a field which will tell me if, and how many times, an individual in the data changed living location based on city. I could be more specific and try to obtain changes by the field containing street address, but there is input [spelling] error on the dataset's side which would taint the results. City changes will be fine for now.
I used the following code to successfully create a variable:
by ind_id (city), sort: gen changed = (city[1] != city[_N])
...but it doesn't account for an individual who may have moved more than once. I would like to have a result which displays a category for how many changes in 'city' are noted per ind_id, but then stop at the final change.
For example, I'd like to create the variable changed below:
ind_id | visit_id | city | changed |
1 | 1 | Hope | 0 |
1 | 2 | Hope | 0 |
1 | 3 | Aurora | 1 |
1 | 4 | Aurora | . |
1 | 5 | Aurora | . |
2 | 1 | Jackson | 0 |
2 | 2 | Jackson | 0 |
3 | 1 | Hope | 0 |
3 | 2 | Aurora | 1 |
3 | 3 | Aurora | . |
3 | 4 | Jackson | 2 |
3 | 5 | Jackson | 2 |
3 | 6 | Hope | 3 |
-Peter
Comment