I have a dataframe with variables, 2 of which are the start and end year of the data collection timeframe.
i.e.
Var1 Var2 start end
1 A 2000 2022
2 B 1990 1995
3 C 2005 2006
... ... ... ...
I would like to modify this dataframe so that a column for every year is displayed and the presence/absence of data for each year is coded as a binary variable (1/0).
Because the dataset has thousands of rows and many varied year ranges I would like this process to be automated and not manual.
i.e.
Var1 Var2 1990 1991 1992 1993 1994 1995 1996 ... 2021 2022
1 A 0 0 0 0 0 0 0 1 1
2 B 1 1 1 1 1 1 0 0 0
3 C 0 0 0 0 0 0 0 0 0
Then I would like to transform this dataframe so that the years are displayed into 1 row
i.e.
Year Var1 Var2 Data_Availability
1990 1 A 0
1990 2 B 1
1990 3 C 0
...
2022 1 A 1
2022 2 B 0
2022 3 C 0
Any help on how to achieve this is greatly appreciated.