These are examples of my two data sets.
Economy data set:
zip | year | data |
1 | 2018 | |
1 | 2019 | |
1 | 2020 | |
2 | 2018 | |
2 | 2019 | |
2 | 2020 | |
3 | 2018 | |
3 | 2019 | |
3 | 2020 |
Car plant data set:
zip | built_date | year |
1 | 1998 | 2020 |
2 | 2016 | 2020 |
What I have after the merge is something like this:
zip | year | data | built_date |
1 | 2018 | . | |
1 | 2019 | . | |
1 | 2020 | 1998 | |
2 | 2018 | . | |
2 | 2019 | . | |
2 | 2020 | 2016 | |
3 | 2018 | . | |
3 | 2019 | . | |
3 | 2020 | . |
I was hoping to create a new variable, if_Exist, that captures whether if the plant exist at year, andl perhaps also fill in the built_date for the empty cells. And I want to assign value 1 for plants with year >= built_date, and 0 if year < built_date.
However I tried various methods but the codes just won't run due to multiple syntax errors.
Can anyone please enlighten me how to get the codes that converts table 3 into the way I wanted? Filling the built_date part is now a must, but I really need the if_Exist varible to exist
Thank you!!
0 Response to Need help with creating a new variable based on several conditions please
Post a Comment