Dear stata people,
I am currently trying to merge two datasets. We'll call dataset one: X and dataset two: Y. The problem is occurring in X. The way I am trying to match each row and merge the two datasets is by using my date variable from each to correctly place the right rows together. The only problem is in X the date variable is a string when it should be a float/date. This is what one observation looks like for date variable in X: 22/08/14. The format is right, but stata reads as string. I've scoured the internet trying to find a way to destring this and format as a float but can't seem to find the right solution. When I tried to just destring the observation, I get the error: "date: contains nonnumeric characters; no generate". I also tried this: generate date2 = date(date, "DMY") but get zero observations from that code. I then changed my approach and so far this is the best I've come up with to try and reformat the observation as a float/date:
encode date, gen(date2)
recast float date2
format %tdDD/NN/YY date2
The only problem with this is that now stata, for some reason, reads 22/08/14 as 12feb1960 when I need it to read it correctly as 22aug2014.
I guess my underlying question is, is there a way to format 22/08/14 as a float/date?
Thank you in advance for the help.
I am currently trying to merge two datasets. We'll call dataset one: X and dataset two: Y. The problem is occurring in X. The way I am trying to match each row and merge the two datasets is by using my date variable from each to correctly place the right rows together. The only problem is in X the date variable is a string when it should be a float/date. This is what one observation looks like for date variable in X: 22/08/14. The format is right, but stata reads as string. I've scoured the internet trying to find a way to destring this and format as a float but can't seem to find the right solution. When I tried to just destring the observation, I get the error: "date: contains nonnumeric characters; no generate". I also tried this: generate date2 = date(date, "DMY") but get zero observations from that code. I then changed my approach and so far this is the best I've come up with to try and reformat the observation as a float/date:
encode date, gen(date2)
recast float date2
format %tdDD/NN/YY date2
The only problem with this is that now stata, for some reason, reads 22/08/14 as 12feb1960 when I need it to read it correctly as 22aug2014.
I guess my underlying question is, is there a way to format 22/08/14 as a float/date?
Thank you in advance for the help.