Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

"else if" statement including conditional lookup in time series dataset?

I have a dataset in long format:

location_1 I location_2 I year I direction
1              1          2000     1
1              2          2001     0
...

Using an if statement, I can declare whether the locations of the entity is the same in year X.

1 = same location
0 = different location

This is only part of the story. I want the 0 to be more specific. Meaning that if location_1 changes over time but location_2 stays the same I want this to be indicated (the same applies for vice versa). However, I know I have to add a lookup in the line / year above to see whether the entity has actually changed the location again, say:

location_1 I location_2 I year I direction
1              1          2000     1
1              2          2001     2
1              2          2002     3
1              2          2003     3
1              1          2004     2
1              1          2005     1

IDs for direction

1 = same location
2 = movement in location_1
3 = different location_1 and location 2

In Stata, how do I implement the CONDITION year[-1]==year[] to my if clause.

My current code/ idea is it to do this in two steps. First by binary coding and then in a second step compare the 0 with the line above.

generate int loc1_not_loc2 =
 cond(location_1 == location_2, 1,
 cond(location_1 =! location_2, 0,
)
)``
question from:https://stackoverflow.com/questions/66048447/else-if-statement-including-conditional-lookup-in-time-series-dataset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...