Hi! This is my first time using these forums, so I'm sorry if this is an old topic.
I have time-series data, with two variables: time, and X.
I want to create two new variables, Y and Z. Y records the time when X changes next, and Z records the value that X changes to when it does change.
For example, suppose my data is:
t X
1 5
2 5
3 7
4 2
Then I want to create Y and Z such that:
t X Y Z
1 5 3 7
2 5 3 7
3 7 4 2
4 2
...and so on.
In a normal programming language, I would use a loop to assign the Y and Z values, but I don't know how to do this in Stata.
Can anyone tell me how to do this?
I have time-series data, with two variables: time, and X.
I want to create two new variables, Y and Z. Y records the time when X changes next, and Z records the value that X changes to when it does change.
For example, suppose my data is:
t X
1 5
2 5
3 7
4 2
Then I want to create Y and Z such that:
t X Y Z
1 5 3 7
2 5 3 7
3 7 4 2
4 2
...and so on.
In a normal programming language, I would use a loop to assign the Y and Z values, but I don't know how to do this in Stata.
Can anyone tell me how to do this?
Comment