Hi there,
I am struggling to create a date variable. I have found some information on using -mdy- and -date-, but this won't seem to work with the type of data I have.
I have two variables available (storage type double): year and month. I need to create a new variable that combines these two together basically (I don't have data on the day)
For some observations I don't have any data (so year and month are missing), and for some observations only 'month' has a missing value.
When only the year is available, the new date variable should contain the year value (i.e. in this case the new variable should not get a missing value).
Could someone help me? Thank you in advance (:
Here is some example data.

I am struggling to create a date variable. I have found some information on using -mdy- and -date-, but this won't seem to work with the type of data I have.
I have two variables available (storage type double): year and month. I need to create a new variable that combines these two together basically (I don't have data on the day)
For some observations I don't have any data (so year and month are missing), and for some observations only 'month' has a missing value.
When only the year is available, the new date variable should contain the year value (i.e. in this case the new variable should not get a missing value).
Could someone help me? Thank you in advance (:
Here is some example data.
Code:
clear all input double(id year month) 1 1992 4 2 1995 11 3 . . 4 2007 3 5 2004 . end
Comment