Hi
I'm trying to "link" a second date variable to my main date variable.
I think it might be easiest to first post an example. I picked the values below myself to easier show what i want to do.
My main date variable is date which is in ascending order and exists for several (480) companies.
The variable div_sum is a sum of the dividends of each company's stock that have been paid to date (i generated this earlier on).
The variable i need help with is div. To generate this i need to match exdate with the largest value of date that is still below or equal to exdate.
I.e. as seen in observations 1 and 2 they have an exdate below 05mar2008 but above or equal to 03mar2008. So here the value of div should be 0.
Observation 3 has an exdate below 22mar2008, but above 05mar2008, so here the value for div would be the div_sum value for 05mar2008 which is 1.5.
And so on - hope it makes sense.
The main problem is that exdate isn't sorted and sometimes doesn't even match a date included in the date variable (date only contains trading dates and sometimes exdate is on a Saturday for some reason).
I've tried a lot of things, but can't seem to figure this out, so hope you can help.
I'm using Stata SE 12.1 for Mac if that matters.
Rasmus
I'm trying to "link" a second date variable to my main date variable.
I think it might be easiest to first post an example. I picked the values below myself to easier show what i want to do.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long date int exdate float(div_sum div) 17594 17595 0 0 17594 17594 0 0 17596 17609 1.5 1.5 17596 17984 1.5 4.2 17613 17615 1.5 2.5 17613 17617 1.5 2.5 17615 17617 2.5 2.5 17616 17619 2.5 4.2 17618 17985 4.2 4.2 17621 17626 4.2 ? end format %td date format %td exdate
My main date variable is date which is in ascending order and exists for several (480) companies.
The variable div_sum is a sum of the dividends of each company's stock that have been paid to date (i generated this earlier on).
The variable i need help with is div. To generate this i need to match exdate with the largest value of date that is still below or equal to exdate.
I.e. as seen in observations 1 and 2 they have an exdate below 05mar2008 but above or equal to 03mar2008. So here the value of div should be 0.
Observation 3 has an exdate below 22mar2008, but above 05mar2008, so here the value for div would be the div_sum value for 05mar2008 which is 1.5.
And so on - hope it makes sense.
The main problem is that exdate isn't sorted and sometimes doesn't even match a date included in the date variable (date only contains trading dates and sometimes exdate is on a Saturday for some reason).
I've tried a lot of things, but can't seem to figure this out, so hope you can help.
I'm using Stata SE 12.1 for Mac if that matters.
Rasmus
Comment