Hello everyone,
I was wondering if it is possible to create a new variable 'day' that counts the number of days. I have a panel dataset with dates and I would like to create a new variable where the first date in the dataset has the number 1, the second date in the dataset number 2, etc.
What I have come up with so far is:
gen day = .
replace day=1 if date=="2020-10-14", where 2020-10-14 is the first date in the dataset.
This works, but I have to change all the dates manually
However I was wondering if there is a simpler way, so that I am not spending a lot of time converting these days to the number of days.
Thanks in advance!
I was wondering if it is possible to create a new variable 'day' that counts the number of days. I have a panel dataset with dates and I would like to create a new variable where the first date in the dataset has the number 1, the second date in the dataset number 2, etc.
What I have come up with so far is:
gen day = .
replace day=1 if date=="2020-10-14", where 2020-10-14 is the first date in the dataset.
This works, but I have to change all the dates manually
However I was wondering if there is a simpler way, so that I am not spending a lot of time converting these days to the number of days.
Thanks in advance!
Comment